Author Topic: Break folder with many files into multiple subfolders (Windows, bat script)  (Read 65 times)


  • Administrator
  • Hero Member
  • *****
  • Posts: 296449
  • Gender: Male
  • point d’amour
    • spiros.doikas
    • greektranslator
    • doikas
    • 102094522373850556729
    • lavagraph
    • Greek translator CV
Break folder with many files into multiple subfolders

Put this code in a txt file, put the file in the big folder, rename it to bat. Adjust:

limit=2999 [The number of files each subfolder will have]
*.html [The type of files you are moving]

Code: [Select]
@Echo Off
If /I Not "%__CD__%"=="%~dp0" PushD "%~dp0" 2>Nul||Exit/B
taskkill /f /im explorer.exe >nul
taskkill /f /im SearchIndexer.exe >nul
sc stop WSearch >nul
sc config WSearch start= disabled >nul

SetLocal EnableDelayedExpansion
Set "DirN=-1"

Set/A "DirN+=1"
If Exist "%DirN%" GoTo Check_DirN
echo Moving files to Directory %DirN%...
Set "limit=2999"
MD "%DirN%"
For %%A In (*.html) Do (
    RoboCopy . "%DirN%" "%%A" /MOV 1>NUL
    Set/A "limit-=1"
    If !limit! Lss 0 GoTo Check_DirN
Echo(Task Done!

start explorer.exe
start SearchIndexer.exe
sc config WSearch start= delayed-auto >nul
sc start WSearch >nul
Timeout -1 1>Nul
« Last Edit: 10 Aug, 2017, 08:20:31 by spiros »