I want to create a batch script to move my files to their respective folder according to their ID.
example:
file name E:\folderPath\Pre001Post.csv, will move to folder E:\folderPath\M001\
001 is the ID, the 'Pre' and 'Post' was random, 2 zero was leading for number less that 10.
file name E:\folderPath\Pre099Post.csv, will move to folder E:\folderPath\M099\
099 is the ID, the 'Pre' and 'Post' was random, 1 zero was leading for number less that 100.
file name E:\folderPath\Pre109Post.csv, will move to folder E:\folderPath\M109\
109 is the ID, the 'Pre' and 'Post' was random.
below was my script,
@setlocal enabledelayedexpansion
for /l %%S in (1, 1, 111) do (
IF %%S LSS 10 ( SET z=00%%S ) ELSE (goto:moveFileProcess)
IF %%S LSS 100 ( SET z=0%%S ) ELSE (goto:moveFileProcess)
:moveFileProcess
echo !z!
echo %z%
MOVE /Y E:\folderPath\???%z%????.csv E:\folderPath\M%z%\
)
The problem was I not able set the variable %%s value to variable z (with the 00 leading).
I was follow Windows Batch files: what is variable expansion, and what does EnableDelayedExpansion mean? to add the @setlocal enabledelayedexpansion, but its still fail. Anyone know which part I was wrong?