Organising files to folders alphabetically

0

I have a folder with thousands of files witch open in a synth emulator. The files are so many that the emulator freezes for seconds when i try to browse which file to open. Id like to put all the files in a subfolder by the first letter of the file name.

I have Total Commander. Is it possible to automate? If not is ther any other way?

Daarwin

Posted 2019-12-21T15:45:40.490

Reputation: 127

Answers

3

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.

Akina

Posted 2019-12-21T15:45:40.490

Reputation: 2 991

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