Creating a Batch File that can Process a Drag and Drop of Multiple Files

Midimistro picture Midimistro · Nov 23, 2015 · Viewed 7.8k times · Source

I am trying to process several files by running them through a batch file. I want the batch file to be able to take all the files its given (aka dumped; or dragged and dropped) and process them.

Currently I can process the files individually with the following batch command:

"C:\Program Files\Wireshark\tshark.exe" -r %1 -Y "filter" -o "uat:user_dlts:\"User 8 (DLT=155)\",\"pxt\",\"0\",\"\",\"0\",\"\"" -o "gui.column.format:\"Info\",\"%%i\""> %1".filter.txt"

I am looking to do the same thing as above, but with the ability to simply drag and drop the files onto the batch file to be processed.

For those confused about the above batch file:
-r Reads the input file, whose full file address (including extension) is captured by %1
-Y Filters out certain parts of the dragged & dropped file
-o Sets preferences (defined by stuff in the ""s) for running the executable: tshark.exe
- > redirects the results to stdout
- %1".filter.txt" outputs the results to a new file called "draggedfilename.filter.txt"

Please refrain from using this code anywhere else except helping me with this code (due to the application it is being used for). I changed several flags in this version of the code for privacy sake. Let me know if you have any questions!

Answer

SachaDee picture SachaDee · Nov 23, 2015

Use %* instead of %1.

Example :

@echo off 

for %%a in (%*) do  (
"C:\Program Files\Wireshark\tshark.exe" -r "%%a" -Y "filter" -o "uat:user_dlts:\"User 8 (DLT=155)\",\"pxt\",\"0\",\"\",\"0\",\"\"" -o "gui.column.format:\"Info\",\"%%i\""> "%%a"".filter.txt"
)

Replace %%i with the right variable.