Even better would be to have it automatically create sequentially numbered folders to move the batches of files into [...]
The following code was tested with a max file count of 5 instead of 1000.
@ECHO OFF &SETLOCAL EnableExtensions EnableDelayedExpansion
FOR /R "d:\folder" %%# IN (*) DO (
IF DEFINED bNewFolder (
SET /A "nFolderCount+=1"
ECHO moving... "%%~nx#" to "d:\folder!nFolderCount!\"
MOVE /Y "%%#" "d:\folder!nFolderCount!\" >NUL
SET /A "nFileCount+=1"
IF !nFileCount! EQU 1000 SET "bNewFolder=DEFINED"
IF !nFolderCount! GTR 0 (
ECHO Done, !nFolderCount! new folders were created.
ECHO The last folder contains !nFileCount! files.
ECHO The rest should contain 1000 files each.
) ELSE ECHO Done, no files found.
[...] then gracefully quit when there's less than 1,000 files left in the source directory or when it's empty.
As written above, the script should exit gracefully. It will always empty the source folder. Allowing the script to leave files in the source folder may require violating the "'blindly' grab" rule. I believe two passes would be necesary per thousand files. The first pass would only count the number of files up to one thousand in the source folder. The second pass would move the counted files only if the number counted is equal to one thousand. If more than that number remain, the cycle would repeat (pass 1, pass 2, pass 1, ...) until less than a thousand files remain.EDIT
: Removed ":FolderLoop" label and its associated GOTO statement. It's no longer necessary to jump out of the FOR loop by using the boolean bNewFolder, which replaced bNewLoop as a more descriptive variable name.
Edited by 5eraph, 23 December 2013 - 05:36 PM.