1.

Solve : Batch file - Filenames when using wildcards?

Answer»

Can it be done, when sending multiple files to a command using a wildcard, such as in...
Code: [Select] FOR %%X IN (*.txt) DO COMMANDthat each filename sent to the command can be somehow got/captured as it is passed along?

I would like to save each filename to a variable as the file is sent to the command, then, when the next file is sent, replace the variable with the next filename.

An example:

File #1 of 10 gets sent to the command, I need to know that filename so i can do something like the following:
Code: [Select]...DO COMMAND [string manipulation of filename for File #1]
Hope that makes sense, let me know.

Thanks for the help. try this

set c=0
for %%X IN (*.TXT do (
call set c=%%c%%+1
call set c.%%c%%=%%X
)



that would set all filenames into variables , c.0 + 1
example:
%c.1%
%c.2%
%c.3%
Thanks for the quick reply diablo416.

I think that might be close to what I need, but instead of each filename getting its own variable, I need just one. One variable that KEEPS getting replaced as each new file is sent to the command.

Thanks again.

for %%X IN (*.TXT do (
SET VARIABLE=%%x
command
)
@ Dias DE verano
Thank you, that was remarkably SIMPLE. I had actually tried it before but believed it not to work, as I had not looked at the output carefully. Perhaps it still may not work fully with what I need to do.

Here is the source of my confusion:
Code: [Select]FOR %%X IN (*.TXT) DO (
SET test=%%x
command [command parameter in which I call variable(test)]
)I call the variable(test) like so, %test% , however this does not work.
Additionally, variables I set outside of this specific FOR command, work fine, however it should be noted these have hard set values, UNLIKE variable(test) with its value of %%X.

So, the question is, how do I call variable(test) in my command's parameters?

Thanks for the help.Google for the topic "delayed expansion".
Thanks Dias de verano, I got it WORKING now.

-edit-

I just read the previous thread I had started, where you explicitly warned me about this, my bad.



Discussion

No Comment Found