Question : move certain number of files at a time

Hi -

   I already have this code (below) and I was wondering if I could still use it to move only 100,000 files at a time to the 'destination directory' instead of everything in the 'base directory'?

1:
2:
3:
4:
5:
6:
set BaseDir=e:\hold0
set DestDir=e:\hold
for /F "tokens=*" %%A in ('dir /ad /s /b "%BaseDir%"^|sort /r') do (
  move "%%A\*.*" "%DestDir%"
  rd "%%A"
)

Answer : move certain number of files at a time

Ah, that's a bit easier, try this.

~bp
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
@echo off
setlocal EnableDelayedExpansion
set BaseDir=e:\hold0
set DestDir=e:\hold
set MaxFiles=100000
set Count=0
for /F "tokens=*" %%A in ('dir /ad /s /b "%BaseDir%"^|sort /r') do (
  for %%B in ("%%A\*") do (
    set /A Count += 1
    if !Count! GTR %MaxFiles% (
      echo Maximum of [%MaxFiles%] reached, stopping now.
      exit /b
    )
    move "%%B" "%DestDir%">NUL
  )
  rd "%%A"
)
Random Solutions  
 
programming4us programming4us