How to use a wildcard in a script package with CLI tools that require a specific file name?

I have a cli application that doesn't like the use of wildcards. This example uses *.dat . I just get an error that the *.dat file is not valid.

I have a folder with thousands of files that need to be processed with this tool. So doing it manually is not an option. I met quite a few applications where I had this problem, but this time it is pretty important. A general decision on how to deal with this application would be very enjoyable.

Can I create a list of files from all *.dat files and transfer it to the application? I don't need to use a script package, but it seemed like the easiest solution.

+4
source share
1 answer

You can use the for loop:

 for %%x in (*.dat) do mycommand "%%x" 

This will run the command once for each file. If you want to fill them out, you need to do some more work:

 setlocal enabledelayedexpansion set Count=0 set List= for %%x in (*.dat) do ( set List=!List! "%%x" set /a Count+=1 if !Count! GEQ 50 ( mycommand !List! set List= set Count=0 ) ) 

This will transfer 50 files at a time to the command. You can customize this number if you want. The problem is that you have thousands of files in the folder, then you cannot just list them all on one command line (because there is a limit on the maximum length of the command line), so you need to process them in pieces.

+5
source

All Articles