|Thanks nbrane. I've tried your suggestion, it doesn't work either, so I will stick with Judago's 2nd method. However I encounter similar problems when trying with filenames contain special characters. These special characters include !^&=;, which are valid in Windows filename system but with special functions in batch scripting.|
I've revised the batch script as follows:
@echo off&&setLocal EnableDelayedExpansion
if [%1]== (echo Please drag and drop files to the icon&pause&goto :eof)
if not [%6]== (echo Too many files&pause&goto :eof)
FOR %%B IN (%arg%) DO (
if /i not [%%~xB]==[.ts] echo %%~xB is an invalid format&pause&goto :eof
echo "%~nx0" is going to process following files:
for %%a in (%arg%) do echo %%~fa
for %%Y in (%arg%) do if not [%%~fY]== echo %%~fY
echo Press any key to start or CTRL-C to quite
pause > nul
I've tried the following filenames:
"test!.ts" "test;.ts" "test,.ts" "test1, test2.ts" "test^.ts" "test&.ts" "test=.ts" "test1 & test2.ts"
All fail to echo the correct filename.
How should I modify the script to deal with filenames with these special characters (!^&=;,)?
One additional question, is it possible to use 1 for-loop to handle 2 set of variables?
1st set of variables is the filenames drag and drop to the batch,
2nd set of variables is the new filenames enter by user.
In the latter part of my batch, I will use a command-line program to convert the input files to new format with new filenames (assigned by the user). The C/L program needs the above two sets of variables as parameters.
For ease of testing, I try to echo 2 sets of variables at the same line to see whether the script works but it fails to do so (unable to echo %Name1% to %Name5%).
FOR %%A IN (%arg%) DO IF NOT [%%~A]== (
set /a cc+=1
set /p Name!cc!=Enter the new name of "%%~nA":
FOR %%B IN (%arg%) DO IF NOT [%%~B]== (
set /a dd+=1
echo %%~fB will be converted to !Name%dd%!
Any help is appreciated.