79564075

Date: 2025-04-09 10:22:21
Score: 4
Natty:
Report link

I have tried the below script and able to get missing files but not missing folders. Could you please help us getting the right script which can list even missing folders also.

# Prompt for the paths of the two folders to compare
$folder1 = "C:\Users\User\Desktop\Events"
$folder2 = "C:\Users\User\Desktop\Events1"

Write-Host "From VNX:"(Get-ChildItem -Recurse -Path $folder1).Count
Write-Host "From UNITY:"(Get-ChildItem -Recurse -Path $folder2).Count

# Get the files in each folder and store their relative and full paths
# in arrays, optionally without extensions.
$dir1Dirs, $dir2Dirs = $folder1, $folder2 | 
  ForEach-Object {
    $fullRootPath = Convert-Path -LiteralPath $_
    # Construct the array of custom objects for the folder tree at hand
    # and *output it as a single object*, using the unary form of the 
    # array construction operator, ","  
    , @(
      Get-ChildItem -File -Recurse -LiteralPath $fullRootPath |
        ForEach-Object {
          $relativePath = $_.FullName.Substring($fullRootPath.Length + 1)
          if ($ignoreExtensions) { $relativePath = $relativePath -replace '\.[^.]*$' }
          [PSCustomObject] @{
            RelativePath = $relativePath
            FullName = $_.FullName
          }
        }
    )
  }

# Compare the two arrays.
# Note the use of -Property RelativePath and -PassThru
# as well as the Where-Object SideIndicator -eq '=>' filter, which
# - as in your question - only reports differences
# from the -DifferenceObject collection.
# To report differences from *either* collection, simply remove the filter.
$diff = 
  Compare-Object -Property RelativePath -PassThru $dir1Dirs $dir2Dirs | 
  Where-Object SideIndicator -eq '=>'

# Output the results.
if ($diff) {
    Write-Host "Files that are different:"
    $diff | Select-Object -ExpandProperty FullName
} else {
    Write-Host "No differences found."
}
Reasons:
  • RegEx Blacklisted phrase (3): Could you please help us
  • RegEx Blacklisted phrase (1): help us
  • Long answer (-1):
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Jithendra