directory - How can I compare the content of 3 directories in powershell -


after looking while, i've found lot of people trying same thing haven't yet been able find complete answer i'm hoping can us!

what give 2 directories, , b, , compare inside inside b , if there files or folders in b not in generate output file detailing path item in b , not a. here, id use list of items , if of items in these paths contain different files in 2 directories (the names same documents\folder\b.txt contains different desktop\folder\b.txt) generate list showing different or showing file path items different if cant show text different.

i've looked doing .hash i'm not sure if that's best way go it? like:

$sourcedocs = get-childitem –path c:\documents1 | foreach  {get-filehash –path $_.fullname} $destdocs = get-childitem –path c:\documents2 | foreach  {get-filehash –path $_.fullname} 

in terms of have physical comparison, trying 3-way comparison code below isn't accurate i've got yet.

$foldera = 'c:\users\username\desktop\folder a' $folderb = 'c:\users\username\desktop\folder b' $folderc = 'c:\users\username\desktop\folder c' $achild = get-childitem $foldera -recurse $bchild = get-childitem $folderb -recurse $cchild = get-childitem $folderc -recurse compare-object -referenceobject $achild -differenceobject $bchild, $cchildcode 

after looking further, ive found out might better use 3.0 rather 2.0 can use -dir more efficiently.

any questions, let me know.

any appreciated.

this answer want: what give 2 directories, , b, , compare inside inside b , if there files or folders in b not in generate output file detailing path item in b , not a.

 $folder1 = "c:\users\username\desktop\folder a"         $folder2 = "c:\users\username\desktop\folder b"           # files under $folder1, filter out directories         $firstfolder = get-childitem -recurse $folder1 | where-object { -not $_.psiscontainer }          $failedcount = 0         $i = 0         $totalcount = $firstfolder.count         $firstfolder | foreach-object {             $i = $i + 1             write-progress -activity "searching files" -status "searching file  $i of     $totalcount" -percentcomplete ($i / $firstfolder.count * 100)             # check if file, $folder1, exists same path under $folder2             if ( test-path ( $_.fullname.replace($folder1, $folder2) ) ) {                 # compare contents of 2 files...                 if ( compare-object (get-content $_.fullname) (get-content $_.fullname.replace($folder1, $folder2) ) ) {                     # list paths of files containing diffs                     $filesuffix = $_.fullname.trimstart($folder1)                     $failedcount = $failedcount + 1                     write-host "$filesuffix on each server, not match"                 }             }             else             {                 $filesuffix = $_.fullname.trimstart($folder1)                 $failedcount = $failedcount + 1                 write-host "$filesuffix in folder 1" $filesuffix | out-file "$env:userprofile\desktop\folder1.txt" -append             }         }          $secondfolder = get-childitem -recurse $folder2 | where-object { -not $_.psiscontainer }          $i = 0         $totalcount = $secondfolder.count         $secondfolder | foreach-object {             $i = $i + 1             write-progress -activity "searching files on second folder" -status "searching file  $i of $totalcount" -percentcomplete ($i / $secondfolder.count * 100)             # check if file, $folder2, exists same path under $folder1             if (!(test-path($_.fullname.replace($folder2, $folder1))))             {                 $filesuffix = $_.fullname.trimstart($folder2)                 $failedcount = $failedcount + 1                 write-host "$filesuffix in folder 2" $filesuffix | out-file "$env:userprofile\desktop\folder2.txt" -append             }         } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -