2012-11-22 118 views

回答

1
@echo off 
setlocal 

:: Initialization 
set "ext=jpg" 
set "source=folder 1" 
set "target=folder 2" 

:: Get count of images and select random image 
for /f %%N in ('dir /b "%source%\*.%ext%"^|find /c /v ""') do (
    set /a "imageNum=%random% %% %%N" 
) 

:: Copy the image 
if %imageNum% gtr 0 (set "skip=skip=%imageNum%") else set "skip=" 
for /f "%skip% eol=: delims=" %%F in ('dir /b "%source%\*.%ext%"') do (
    echo copy /y "%source%\%%F" "%target%\1.%ext%" 
    exit /b 
) 
+0

它的工作,非常感謝你:) – Sakura

1
@Echo OFF 

REM By Elektro [email protected] 

:: Generate random numbers before filenames 
FOR %%# in ("D:\Folder 1\*") Do (CALL Echo %%RANDOM:~5,1%%%%RANDOM:~4,1%%%%RANDOM:~3,1%%%%RANDOM:~2,1%%%%RANDOM:~1,1%%;%%# >> "%TEMP%\TempFile.txt") 

:: Sorts the generated random numbers and choose a random file. 
For /F "TOKENS=*" %%# in ('Type "%TEMP%\TempFile.txt" ^| SORT ^| MORE +%RANDOM:~1,1%') DO (

:: Copy the file to a folder 
    For /F "TOKENS=2 Delims=;" %%@ in ('Echo %%#') do (
     Echo [+] File choosed: "%%[email protected]" 
     Copy /Y "%%[email protected]" "D:\folder 2\1.jpg" 1>NUL 
     GOTO:EXIT 
    ) 
) 

:EXIT 
:: Delete the temp file 
DEL /Q "%TEMP%\Tempfile.txt" 
Pause&Exit 
+0

它的工作,謝謝:) – Sakura

相關問題