I have a set of files I wish to copy to a new set of subfolders.
For instance:
0_107_206.tif
1_0_69.tif
1_16_75.tif
1_40_117.tif
2_0_36.tif
2_26_62.tif
35_0_19.tif
These files are stored in folders based on the first substring of the filename such as 0, 1 or 35. I want to create subfolders based on the second substring between the 2 '_' characters. I have tried several things along the lines of
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%B in (*.tif) DO (
SET FileName=%%B
SET FileName1=!FileName:~2!
SET FileName2=!FileName1:~0,-7!
MD %TargetPath%!FileName2!
)
ENDLOCAL
But this is not flexible enough. Is there a way to get the position of the '_' characters and feed that into a SUBSTRING function? Naturally this needs to work in a loop since there are thousands of files I need to proces.
Thanks in advance.