-1

Want to make a batch file from a folder of 30,000 files from let's say C:\Users\NAME\Desktop, that will create a folder named "1", put 500 files in, no matter the name of the file, and then loop naming the next "2", until all 30,000 are in folders of 500 files each.

Thanks in advance for the help :)

Izuuk
  • 3
  • 2

2 Answers2

0

Found this from Compo, sorry didn't reference it!

@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=2"
For %%A In (*.png *.doc) 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
Compo
  • 36,585
  • 5
  • 27
  • 39
Izuuk
  • 3
  • 2
  • 3
    Izuuk, please do not copy my existing code already on this site, (especially without referencing it), and changing just the limit value and file globs. What you should have done was to mark this question as a duplicate of an already existing question. – Compo Oct 11 '22 at 16:44
  • Sorry @Compo, still learning the ropes of StackOverflow! Worked great on personal but on work PC it was saying "check_dirn was not recognised" which was odd and couldn't find anything on that – Izuuk Oct 12 '22 at 06:08
0
@ECHO OFF
SETLOCAL
rem The following settings for the source directory and destination directory are names
rem that I use for testing and deliberately include names which include spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.

SET "sourcedir=u:\your files\t w o"
SET "destdir=u:\your results"

PUSHD "%sourcedir%"
ECHO sd=!sourcedir!
FOR /f "tokens=1*delims=:" %%b IN (
 'dir /b /a-d * png *.doc^|findstr /n "."'
 ) DO (
  SET /a subdir=1+(%%b / 7^)
  FOR /f "tokens=2delims==" %%e IN ('set subdir') DO (
   ECHO MD "%destdir%\%%e" 2>NUL
   ECHO MOVE "%%c" "%destdir%\%%e\"
  )
)
popd
GOTO :EOF

Always verify against a test directory before applying to real data.

I used a limit of 7 for testing. Modify as you will

Required md and move commands are merely echoed for verification. remove the echoes to activate after testing.

Magoo
  • 77,302
  • 8
  • 62
  • 84