for %%a in (%*) do .. fails when a filename contains "(" , ")"

Viewed 46

Have a batch that accepts one or more files being dragged and dropped on it. Issue occurs if a filename contains "(" ")" which just causes the batch to fail.

for %%a in (%*) do (

with filename test(asas).txt the last command run before it fails is

for %a in (C:\test(asas).txt) do (

Assumed the following would resolve it

for %%a in ("%*") do (

Which does resolve if single file being dropped on the batch but then does not work if multiple files are dragged and dropped onto the batch file.

for %a in ("C:\test(asas).txt anotherfile.txt") do (

Rest of the logic does not find the files as it assumes "C:\test(asas).txt anotherfile.txt" is the filename.

Is this just a know limitation or is there a possible work around. Some more information requested in the comments below. Below are the command lines when file(s) are dropped onto the batch.

Having space in the file name does not cause any issues. e.g. Batch file started with:

Command line used is: C:\Windows\system32\cmd.exe /c ""C:\test\test.bat" "C:\t t.txt"" 

However when there is ( or ) no double quotes are added. Batch file started with:

Command line used is: C:\Windows\system32\cmd.exe /c ""C:\test\test.bat" C:\test(asas).txt"

Example sending both files together Batch file started with:

Command line used is: C:\Windows\system32\cmd.exe /c ""C:\test\test.bat" "C:\t t.txt" C:\test(asas).txt"
0 Answers
Related