3

I have a folder with 110.000 files and I want a way to break this folder into multiple subfolders containing say 3000 files each (with a batch script perhaps?). (Trying a copy/paste with WinExplorer gets stuck in "Preparing to Copy".)

For example:

BigFolder
  |
NewFolder
|     |    |    |    |
Sub1  Sub2 Sub3 Sub4 Sub5...
greektranslator
  • 499
  • 1
  • 6
  • 19
  • 1
    see http://stackoverflow.com/questions/41489945/fast-methods-to-copymove-files-in-batch-file - just change the `limit` – Magoo Jan 06 '17 at 08:48
  • …and `"%DirN%"` to `"NewFolder\Sub%DirN%"` – Compo Jan 06 '17 at 09:20
  • Looks like the latest 2 scripts simply repeat copying the same first batch of files in different folders... – greektranslator Jan 06 '17 at 11:11
  • They would if they were copying. Mine at least `move`s hence the file will start in one directory and finish with a bunch of others in another. – Magoo Jan 06 '17 at 11:21
  • I just tried once again the last script, by only changing " *.bat *.cmd *.txt" to " *.html " since my files are html, what happens is a simple copy of the same batch of files. I can confirm that files are not moved by seeing the file count remains unchanged in source folder. – greektranslator Jan 06 '17 at 11:28
  • Running the penultimate script (Magoo) and replacing ".bat .cmd .txt" with ".html" only moves the bat file! – greektranslator Jan 06 '17 at 11:38
  • i think OP should read that the echo for security reasons has to be removed to actually move the files. –  Jan 06 '17 at 14:05
  • Echo had been removed when I ran it -:) – greektranslator Jan 06 '17 at 15:54

1 Answers1

5

I am surprised to find the same case of mine. I had 30,000 files that needed to be sorted, so I asked question on this page: Fast methods to copy(move) files in batch file

This is Compo's script:

@Echo Off
If /I Not "%__CD__%"=="%~dp0" PushD "%~dp0" 2>Nul||Exit/B
SetLocal EnableDelayedExpansion
Set "DirN=-1"

:Check_DirN
Set/A "DirN+=1"
If Exist "%DirN%" GoTo Check_DirN
Set "limit=700"
For %%A In (*.bat *.cmd *.txt) Do (
    If Not Exist "%DirN%" MD "%DirN%"
    If /I Not "%%~nxA"=="%~nx0" RoboCopy . "%DirN%" "%%A" /MOV 1>NUL
    Set/A "limit-=1"
    If !limit! Lss 0 GoTo Check_DirN
)
Echo(Task Done!
Timeout -1 1>Nul

And this is what I use and I edited for a bit for the purpose:

@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"

:Check_DirN
Set/A "DirN+=1"
If Exist "%DirN%" GoTo Check_DirN
cls
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

You can remove taskkill, start and sc part if desired. I added this part because explorer and Windows Search Indexer will cause waste of memory when moving files. I recommend you to run the script with Administrator privilege.

Try to test the script in small scale to see if it does work.

Community
  • 1
  • 1