paultran00
asked on
Use Powershell to check that all files and subfolders in Folder1 got copied to Folder2
HI,
I have 2 folders: Folder1 and Folder2. I want to check that all files and subfolders in Folder1 got copied to Folder2, by looking at a count of files and file sizes.
In WIndows 10, How do I write a powershell to do this?
I have 2 folders: Folder1 and Folder2. I want to check that all files and subfolders in Folder1 got copied to Folder2, by looking at a count of files and file sizes.
In WIndows 10, How do I write a powershell to do this?
Use the robocopy command for copying, it knows logging. I have never seen it fail in that respect, that's why I wouldn't care for comparing folders afterwards.
ASKER
The files have already been copied to folder2. I need to compare / validate and show proof that everything has been copied over.
Can robocopy compare and show proof?
Can robocopy compare and show proof?
Robocopy does not verify bit-by bit. But as I told you, I never saw a case where robocopy indicated "0 copying errors" while there were some.
Anyway, for powershell, MS holds a tutorial here, that allows comparison: https://devblogs.microsoft.com/scripting/easily-compare-two-folders-by-using-powershell/
Anyway, for powershell, MS holds a tutorial here, that allows comparison: https://devblogs.microsoft.com/scripting/easily-compare-two-folders-by-using-powershell/
Compare the file hashes
$folder1 = Get-ChildItem –Path C:\folder1 | foreach {Get-FileHash –Path $_.FullName}
$folder2 = Get-ChildItem –Path C:\folder2 | foreach {Get-FileHash –Path $_.FullName}
Compare-Object -ReferenceObject $folder1.Hash -DifferenceObject $folder2.Hash
If they match the folders are 100% identical, theres no 'but what ifs' they are mathematically identical.
</p>
$folder1 = Get-ChildItem –Path C:\folder1 | foreach {Get-FileHash –Path $_.FullName}
$folder2 = Get-ChildItem –Path C:\folder2 | foreach {Get-FileHash –Path $_.FullName}
Compare-Object -ReferenceObject $folder1.Hash -DifferenceObject $folder2.Hash
If they match the folders are 100% identical, theres no 'but what ifs' they are mathematically identical.
</p>
Seems to be the same syntax that "scripting guy" in my link proposes :-)
Hello McKnife,
It's not exactlly the same. Pete Long command compare the Hash of the files. That is best way to make sure that files are exactelly the same, even if files names are different
It's not exactlly the same. Pete Long command compare the Hash of the files. That is best way to make sure that files are exactelly the same, even if files names are different
You are right.
I was mistaken, I trusted MS (the scripting guy) to always come with the ideal solution :-)
Sorry Pete.
I was mistaken, I trusted MS (the scripting guy) to always come with the ideal solution :-)
Sorry Pete.
Minor update on PL post (It's optional and it does not change his post), It'll be more easy read a path instead of reading a HASH :-)
Compare-Object -ReferenceObject $folder1.Path -DifferenceObject $folder2.Path
$folder1 = Get-ChildItem –Path C:\folder1 | foreach {Get-FileHash –Path $_.FullName}
$folder2 = Get-ChildItem –Path C:\folder2 | foreach {Get-FileHash –Path $_.FullName}
Compare-Object -ReferenceObject $folder1.Path -DifferenceObject $folder2.Path
Compare-Object -ReferenceObject $folder1.Path -DifferenceObject $folder2.Path
$folder1 = Get-ChildItem –Path C:\folder1 | foreach {Get-FileHash –Path $_.FullName}
$folder2 = Get-ChildItem –Path C:\folder2 | foreach {Get-FileHash –Path $_.FullName}
Compare-Object -ReferenceObject $folder1.Path -DifferenceObject $folder2.Path
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.