MoveToFolders.bat
@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%x in ('dir /b *.ext') do (
set tmp=%%x
set tmp=!tmp:~0,1!
if not exist .\!tmp! md !tmp!
move "%%x" "!tmp!\%%x" > nul
)
endlocal
echo Done.
Moves files which matches the mask (now - *.ext
) from current folder to subfolders with subfolder name equal to 1st letter of filename. The simplest way - put this batch into the folder with files and execute.
Replace *.ext
with correct mask for your files.
It is possible that some files won't be moved with "File not found" error due to nonstandard unicode symbol in its filename. Move such files by hands.
UPDATE To solve the issue with non-standard symbols you may try to use dir /x *.ext
command (applicable if 8.3 names are not disabled). In such case you must skip 7 lines and use 4th (must be verified) token ("tokens=4 skip=7"
) when it is not empty. "File not found" errors over last 2 lines are safe and must be ignored.
It worked great. Thank you. About 280 files couldnt be moved but out of 8000 thats pretty good. – Daarwin – 2019-12-21T19:11:08.883