How to split large folder into multiple folders


with a batch script

@echo off
setlocal enabledelayedexpansion

set folder=c:\files

set filecount=0
set foldercount=1
set maxfiles=100

for /F “tokens=*” %%G in (‘dir “%folder%” /A:-D /B’) do (
set /A filecount+=1
set target=0000!foldercount!
set target=!target:~-5!
if not exist “%folder%\!target!” md “%folder%\!target!”
move “%folder%\%%G” “%folder%\!target!”

if [!filecount!]==[%maxfiles%] (
set /A foldercount+=1
set filecount=0
)
)

Paste the script below into a text file and save it with a .cmd extension. Change the value of the line “set folder=c:\files” with your folder location.
Running the script will create sequentially-numbered subfolders and move 100 files into each one

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s