I’m trying to create a batch file which will loop around a list of JPGs/PNGs in a folder, and create sub-directories using the first 2 characters of these image names. After creating the sub-directories, it will then move the image into the correct sub folder.
For example, ABC.jpg and DEF.png will create AB and DE, and move ABC.jpg into AB and DEF.png into DE.
The problem I’m having is extracting the first 2 characters and creating the sub-directories. Here is the relevant code I have so far:
for %%A in (*.jpg,*.png) do (
set _xx=%%A
md %_xx:~0,2%
)
[Error / duplication handling, and the file move itself has been removed for clarity]
Echoing out the variable _xx shows no value assigned to it, however echoing out %%A gives the correct file name.
Running this script actually creates 2 sub-directories called ‘2’ and ‘~0’
Any suggestions?
You need to use
at the top of the file, and then instead of
use