I'm pretty new to to working with batch files. I need to split a folder of about 500k images into smaller folders of about 5000 each. I have been able to do this but they do not split sequentially. Image 1 will end up in one folder while image 2 is in a completely different one for example. Here's what I have so far.
@echo off
setlocal enabledelayedexpansion
set source=C:\Desktop\test
set numfiles=0
set numdirs=1
set filelimit=5000
for /F "tokens=*" %%G in ('dir "%source%" /A:-D /B') do (
set /A numfiles+=1
set target=0000!numdirs!
set target=!target:~-5!
if not exist "%source%\!target!" md "%source%\!target!"
move "%source%\%%G" "%source%\!target!"
if [!numfiles!]==[%filelimit%] (
set /A numdirs+=1
set numfiles=0
)
)
Example of file names:
02C_CN201S7P_00001.tif
02C_CN201S7P_00002.tif
02C_CN201S7P_00003.tif
Any help would be much appreciated.