以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的多个文件夹放一起运行
<# :
cls
@echo off
rem 从多个子文件夹里分别随机抽取一个jpg或gif图片文件剪切/移动到一个新的文件夹里
mode con lines=3000
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~f0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$newfolder=".\#result";
$newfolder=$newfolder.trimend('\') -replace '^\.',$path;
$folders=@(dir -liter $path|?{($_.FullName -ne $newfolder) -and ($_ -is [System.IO.DirectoryInfo])});
for($i=0;$i -lt $folders.length;$i++){
$files=@(dir -liter $folders[$i].FullName|?{(@('.jpg','.gif') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
if($files.length -ge 1){
$arr=@(get-random -input $files -count $files.length);
for($i=0;$i -lt $arr.length;$i++){
$newpath=$newfolder+'\'+($i+1).toString();
if(-not (test-path -liter $newpath)){[void](md $newpath -force);};
write-host ($arr[$i].FullName+' --> '+$newpath);
};
};
}
追问为啥一直在循环运行哦?是图片不能中文名还是有什么其他设置的要求吗?
追答按运行代码后窗口标题栏中的提示联系我