For my picture collection I want to have all pictures in a folder automatically sorted into folders by date. Luckily the files are already named after the timestamp:
Here's another possibility how you could do this using delayed expansion and substrings:
SETLOCAL ENABLEDELAYEDEXPANSION
for %%a in (*.jpg) do (
set f=%%a
set g=!f:~0,10!
md "!g!" 2>nul
move "%%a" "!g!"
)
The first line enables the syntax using !
instead of %
and has the effect to interpret the value of the variable not as the first line of the block is executed (standard batch behavior), but only when the line itself is executed.
!f:~0,10!
is the syntax to obtain a substring - the dates you're after are always 10 characters long.