PoshCode Logo PowerShell Code Repository

Compare 2 foldertrees by Bernd Kriszio 21 months ago (modification of post by Bernd Kriszio view diff)
diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/1827"></script>download | new post

a small script to find changed files between 2 to foldertrees. Added call to diffmerge (from VS 2008)

  1. function Compare-Foldertrees
  2. {
  3.     param(
  4.         $path1,
  5.         $path2
  6.         )
  7.  
  8.  
  9.     $len1 = $path1.length
  10.     $len2 = $path2.length
  11.  
  12.     . Require-function Get-MD5
  13.  
  14.     Write-Host "====== First path only =======`n"
  15.     gci $path1 -rec | ? {! $_.PSISContainer} | % {
  16.         $fileName1 = $_.fullName
  17.         $fileName = $fileName1.substring($len1)
  18.         $filename2 = $path2 + $fileName
  19.         #$filename1
  20.         #$filename2
  21.         if (! (Test-Path $filename2))
  22.         {
  23.             "$filename"
  24.         }
  25.     }
  26.  
  27.     Write-Host "`n====== Second path only =======`n"
  28.  
  29.     gci $path2 -rec | ? {! $_.PSISContainer} | % {
  30.         $fileName2 = $_.fullName
  31.         $fileName = $fileName2.substring($len2)
  32.         $filename1 = $path2 + $fileName
  33.         #$filename1
  34.         #$filename2
  35.         if (! (Test-Path $filename1))
  36.         {
  37.             "$filename"
  38.         }
  39.     }
  40.  
  41.  
  42.     Write-Host "`n====== Different =======`n"
  43.  
  44.     gci $path1 -rec | ? {! $_.PSISContainer} | % {
  45.         $fileName1 = $_.fullName
  46.         $fileName = $fileName1.substring($len1)
  47.         $filename2 = $path2 + $fileName
  48.         #$filename1
  49.         #$filename2
  50.         if ( (Test-Path $filename2))
  51.         {
  52.             $md1 = Get-MD5($filename1)
  53.             $md2 = Get-MD5($filename2)
  54.             if ($md1 -ne $md2)
  55.             {
  56.                 "$filename"
  57.                 & 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\diffmerge.exe' $fileName1 $filename2
  58.             }
  59.         }
  60.     }
  61. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me