Tuesday, 29 October 2013

WIndows: HOW TO move files in sequent folders

I was found not long ago in a situation where I had a large number of files in one folder that had to be moved in sequent folders (500 files in each folder). Here is the script I managed to make:

echo off
:: set this number eq to num
set movedFiles=500
:: the number of files in each folder
set num=500
:: location of files 
set location=D:\files
:: destination of files
set destinbation=D:\files\
:: set the starting numbering for the subfolders
set /a sn=5
for %%G in ("!location!"\*) do (
 if !movedFiles! EQU %num% (
  set /a sn=sn+1
  echo Creating !destinbation!!sn!
  mkdir !destinbation!!sn!
  set /a movedFiles=0
 echo "%%G" "!destinbation!!sn!"
 move /Y "%%G" "!destinbation!!sn!"
 set /a movedFiles+=1