Splitting files into multiple subdirectories

I recently had to prepare a delivery of images to a client – around 60,000 images, which I wanted to copy to a 128GB USB stick. Unfortunately this proved impossible. The Windows error message proved inconclusive, but a quick search on the web showed that, in the case of the FAT32 file system, there’s a maximum to the number of files that can be contained in one directory. So I decided to write a short batch script that creates a new directory for each 10,000 files, and moves the files there. Here it is:

@echo off
setlocal enabledelayedexpansion
set /a foldernr=1
set /a counter=0
call :makedir
for %%I in (*.jpg) do (
set /a counter+=1
echo !counter!
if !counter!==10001 (
set /a foldernr=foldernr+1
set /a counter=1
call :makedir
move %%I "Beeldmaterial_!foldernr!\%%I"
goto :eof
mkdir "Beeldmaterial_!foldernr!"
goto :eof

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert