@echo off & title 随机移动指定范围内随机数量文件 By 依梦琴瑶
setlocal enabledelayedexpansion
::设置A文件夹路径
set A=A
::设置B文件夹路径
set B=B
::如果需要存放到更多目录,请在上面自行定义变量后,加到下方变量中去
::每个变量必须用双引号括起来,并用英文逗号隔开
set Dirs="%B%"
::设置每个文件夹存放的随机数量范围
set F_Num=9-17
::设置要移动的文件后缀名,如果不限,请直接填写*符号
set Ext=*
for /f "tokens=1,2 delims=-" %%a in ("%F_Num%") do (
set Least=%%a
set Most=%%b
)
set /a M=Most+1
(for /f "delims=" %%a in ('dir /a-d/b "%A%\*.%Ext%"') do (
set /a RandNum=!random!%%1000+1000
echo !RandNum!^|"%A%\%%~a"
))>filelist.$
sort filelist.$ /o filelist.#
for %%i in (%Dirs%) do (
set Count=0
if defined Line (
call set Skip=skip=!Line!
)
call :MoveFile "%%~i" "!Skip!"
)
del filelist.*
pause
exit
:MoveFile
set /a sjs=!random!%%!M!
if !sjs! leq !Most! (
if !sjs! geq !Least! (
goto MoveContinue
)
)
goto MoveFile
:MoveContinue
for /f "%~2 tokens=2 delims=|" %%a in (filelist.#) do (
set /a Count+=1
if !Count! leq !sjs! (
move "%%~a" "%~1\"
set /a Line+=1
)
)
goto :eof