cls&echo off&cd /d "%~dp0"&mode con lines=5000
rem 将一个文件夹跟另一个文件薯茄夹进行对比,并查找出不相同的文件
set #=Any question&set _=WX&set $=Q&数凳察set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
echo%#% +%$%%$%/%_% %z%
pause
exit
#>
$folder1="D:\xxx\A文件夹"
$folder2="D:\xxx\B文件夹"
$folder3="D:\xxx\C文件夹"
if(-not (test-path -literal $folder1)){write-host ('"'+$folder1+'" 未找到')exit}
if(-not (test-path -literal $folder2)){write-host ('"'+$folder2+'" 未找到')exit}
if(-not (test-path -literal $folder3)){[void][IO.Directory]::CreateDirectory($folder3)}
function getfilehash($file){
$hash=''
$md5=New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$stream=New-Object System.IO.FileStream($file, [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read)
$hash=[System.BitConverter]::ToString($md5.ComputeHash($stream)).replace('-','')
$md5.Clear()
$stream.Close()
$stream.Dispose()
return $hash
}
$files=@(dir -literal $folder1 -recurse|?{$_ -is [System.IO.FileInfo]})
for($i=0$i -lt $files.length$i++){
$tmpfile=$folder2.trimend('\')+$files[$i].FullName.SubString($folder1.trimend('\').length)
if(test-path -literal $tmpfile){
$h1=getfilehash $files[$i].FullName
$h2=getfilehash $tmpfile
粗信 if($h1 -ne $h2){$files[$i].FullName}
}else{$files[$i].FullName}
}
robocopy比直接复制要快很多。RoboCopy,它是一个命令行的目录复制虚弯命差氏闷令,自从Windows NT 4.0 开始就成为windows 资源工具包的一部分,然后在Windows Vista、Windows 7和 Windows Server 2008采用作为标准的功能。核野Windows 7的此项功能也得到升级——已经可以支持多线程了,这就意味着可以大大提升复制速度。而且该功能可以创建两个文件结构完全的镜像副本而不复制任何不需要的重复文件,同时还允许您保留所有相关文件信息,包括日期和时间戳、安全访问控制列表(ACL))等等。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)