例如“D:\图片”中有N多张png图片,我想找出 md5_1=xxx...;md5_2=yyy... 的图片文件并删除。
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
<# :
cls&echo off&mode con lines=3000
rem 查找并删除指定目录下多个指定md5值的图片文件
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]::GetEncoding('GB2312')))) -Args '%~f0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$folder="D:\图片";
$ext=@(".png");
$md5list=@(
"md5值1",
"md5值2",
"md5值3",
"md5值4"
);
$md5=New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
function getmd5($f){
$h='';
$stream=New-Object System.IO.FileStream($f,[System.IO.Filemode]::Open,[System.IO.FileAccess]::Read);
$h=[System.BitConverter]::toString($md5.ComputeHash($stream));
$stream.Close();
$stream.Dispose();
return $h.replace('-','');
}
$files=@(dir -liter $folder -recurse|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
$hash=getmd5 $files[$i].FullName;
if($md5list -contains $hash){$files[$i].FullName;}
}
<# :
cls&echo off&mode con lines=3000
rem 查找并删除指定目录下多个指定md5值的图片文件
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]::GetEncoding('GB2312')))) -Args '%~f0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$folder="D:\图片";
$ext=@(".png");
$md5list=@(
"md5值1",
"md5值2",
"md5值3",
"md5值4"
);
$md5=New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider;
function getmd5($f){
$h='';
$stream=New-Object System.IO.FileStream($f,[System.IO.Filemode]::Open,[System.IO.FileAccess]::Read);
$h=[System.BitConverter]::toString($md5.ComputeHash($stream));
$stream.Close();
$stream.Dispose();
return $h.replace('-','');
}
$files=@(dir -liter $folder -recurse|?{($ext -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
$hash=getmd5 $files[$i].FullName;
if($md5list -contains $hash){$files[$i].FullName;}
}
温馨提示:答案为网友推荐,仅供参考