I just can't figure this out.
I have a bunch of files with name format: "PREFIX_PREFIX2_filename.pdf"
I want to sort them into folders like this: "PREFIX/PREFIX2/(files)"
This is what I have so far:
setlocal enableextensions disabledelayedexpansion
for %%f in (*_*_*.pdf, *_*_*.png) do (
for /f "tokens=1, 2 delims=_" %%p in ("%%~nf") do (
for %%d in ("%%~dpf.") do if /i not "%%~p"=="%%~nd" (
if not exist "%%~dpf\%%~p" md "%%~dpf\%%~p"
if not exist "%%~dpf\%%~p" md "%%~dpf\%%~p"
move "%%~ff" "%%~dpf\%%~p"
)
)
)
This sorts them based on the first prefix, but I just can't get any further, and honestly I am not sure even sure what's going on here anyway. This CMD language has got to me the most ugly and inscrutable thing I've ever seen.
I have read over a bunch of similar questions but still couldn't work it out.
I would be very grateful if someone could advise me how to finish up this surely relatively simple task and also explain to me what the hell is going on here.