A
A
Alexander2019-10-04 18:21:07
PowerShell
Alexander, 2019-10-04 18:21:07

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

1 answer(s)
E
Eugene, 2019-10-04
@Losyahka

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 question

Ask a Question

731 491 924 answers to any question