Answer the question
In order to leave comments, you need to log in
How to copy a directory with all subfolders checking the checksum for each file?
Hello friends!
Can you please tell me how to copy a directory with all subfolders checking the checksum for each copied file? Work on Win.
Answer the question
In order to leave comments, you need to log in
To solve your problem, I recommend using Powershell.
I posted this script, I think it will help you.
$OldFolder = "C:\Temp" # folder with source files
$NewFolder = "C:\test\test" # folder where files will be copied
$files = Get-ChildItem $OldFolder -File -Recurse
foreach ($file in $files )
{
$folder = "$NewFolder$(Split-Path $file.DirectoryName -NoQualifier)"
if (-not (Test-Path $folder)) {New-Item $folder -Force -ItemType Directory}
Copy-Item $file .fullname $folder -Force
$MD5 = Get-FileHash -Path $file.fullname -Algorithm MD5
$MD5New = Get-FileHash -Path "$folder\$file" -Algorithm MD5
if ($MD5.Hash -ne $MD5New.Hash)
{Write-Host "Warning!!! The hash of the new file $folder\$file does not match the original!!!" -ForegroundColor Red
Read-host "Press Enter to continue"
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question