I have a folder "C:\TEST\Clean" with many photos (let's say 436) and I have to move 30 of them to the folder "C:\Dropbox\Apps\AutoPost\For_Post_1".
I have this so far but it's for 1 file and I need it for 30.
@echo off
set folder=C:\TEST\Clean
set destfolder=C:\Dropbox\Apps\AutoPost\For_Post_1
for /f "delims=" %%C in ('dir /b /a-d "%folder%\*.jpg" ^| find /c /v ""') do set /A num=%random% %% %%C
for /f "delims=" %%F in ('dir /b /a-d "%folder%\*.jpg" ^| more +%num%') do set name=%%F & goto next
:next
echo Wallpaper is now %name%
move "%folder%\%name%" "%destfolder%\%name%"
答案1
You can use the following script to execute 30 times the snippet you have already written:
@ECHO off
SET src=C:\TEST\Clean
SET dst=C:\Dropbox\Apps\AutoPost\For_Post_1
SET ext=*.jpg
FOR /L %%G IN (1,1,30) DO (call :subroutine "%%G")
GOTO :eof
:subroutine
FOR /f %%A IN ('dir /b /s %src%\%ext% ^| find /v /c ""') DO SET cnt=%%A
FOR /f "delims=" %%C IN ('dir /b /s "%src%\%ext%" ^| find /c /v ""') DO (
SET /A num=%ranDOm% %% %%C
FOR /f "delims=" %%F IN ('dir /b /s "%src%\%ext%" ^| more +%num%') DO SET name=%%F & GOTO next
)
:next
ECHO Round %1 : File %name%
MOVE %name% %dst%
EXIT /B
:eof
Best explanation for for-loops I've found: http://ss64.com/nt/for.html
EXIT /B
is available in Windows 2000 and later and is similar to a common return