- function Get-MD5($filePath){
- $objMD5 = [System.Security.Cryptography.MD5]::Create('MD5');
- $stream = [IO.File]::Open($filePath, [IO.FileMode]::Open, [IO.FileAccess]::Read);
- [BitConverter]::ToString( $objMD5.ComputeHash($stream) );
- $stream.Close();
- }
-
- $fd1 = 'E:\Test\1'; #源文件夹1
- $fd2 = 'E:\Test\2'; #源文件夹2
- $ext = '*.nds'; #文件类型
- $Hash = @{};
-
- dir -Literal $fd1 -filter $ext | forEach {
- $md5 = Get-MD5 $_.FullName;
- $Hash[$md5] = $_.Name;
- }
-
- dir -Literal $fd2 -filter $ext | forEach {
- $md5 = Get-MD5 $_.FullName;
- if( $Hash.ContainsKey($md5) ){
- mv -Literal $_.FullName -Dest ($fd2 + '\' + $Hash[$md5]) -Force;
- }
- }
复制代码
|