substring - Creating sub-directories using first 2 characters of a file name in a batch file -
i'm trying create batch file loop around list of jpgs/pngs in folder, , create sub-directories using first 2 characters of these image names. after creating sub-directories, move image correct sub folder.
for example, abc.jpg , def.png create ab , de, , move abc.jpg ab , def.png de.
the problem i'm having extracting first 2 characters , creating sub-directories. here relevant code have far:
for %%a in (*.jpg,*.png) ( set _xx=%%a md %_xx:~0,2% )
[error / duplication handling, , file move has been removed clarity]
echoing out variable _xx shows no value assigned it, echoing out %%a gives correct file name.
running script creates 2 sub-directories called '2' , '~0'
any suggestions?
you need use
setlocal enabledelayedexpansion
at top of file, , instead of
md %_xx:~0,2%
use
md !_xx:~0,2!
Comments
Post a Comment