Home > Software design >  how generate & use list of values within a commend?
how generate & use list of values within a commend?

Time:01-07

I would like to use a windows command that is processing many files. The syntax of the command is as follows & requires a separated list of filenames: command "file_1 file_2 file_3 file_4" output-file

I have to handle 1000s of files. Is there any way generate the list of files automatically in the command line? Something like:

command "(echo file_1.txt to file_1000.txt)" output-file

Thanks a lot!

CodePudding user response:

If your question is "how do I create a list of files numbered 1 to 1000," then you can do this in PowerShell:

1..1000 | % { New-Item file_$_.txt }

Note that % is an alias for ForEach-Object. The $_ token means "current object from the pipeline" (i.e., the number 1-1000).

CodePudding user response:

This question has many open-ended issues. It is unlikely that all files can be processed by a single command since cmd has a line length limit. However, you can process them one at a time. It is unclear what the output-file would contain.

FOR %A IN ("file_*") DO (command "%A")

If this is in a .bat file script, double the PERCENT character on the variable name.

FOR %%A IN ("file_*") DO (command "%%~A")
  •  Tags:  
  • Related