2013-01-14 10 views
5

Mam poniższy kod, który porównuje dwa foldery i wypisuje pliki różne w odniesieniu do każdego folderu, czy istnieje sposób, aby uzyskać to, aby wyświetlić pełną ścieżkę pliku/folderu dla plików w podfolderach?Powershell - Porównaj zawartość folderu

Cheers

# Create varaibles to store folder paths - pass to Strings... 
param([string]$argFolderA,[string]$argFolderB) 

# Set variables for folder 
$FolderA = Get-ChildItem -Recurse -path $argFolderA 
$FolderB = Get-ChildItem -Recurse -path $argFolderB 

# Compare the contents and output the files different within each folder. 
Compare-Object -ReferenceObject $FolderA -DifferenceObject $FolderB >> C:\CmpOut.txt 

Odpowiedz

3

Spróbuj tego:

Compare-Object -ReferenceObject $FolderA -DifferenceObject $FolderB | 
select @{n="InputObject";e={ 
    if ($_.inputobject -is [system.io.directoryinfo]) 
    {([system.io.DirectoryInfo]$_.InputObject).fullname} 
     else 
     { ([system.io.FileInfo]$_.InputObject).fullname}}},SideIndicator 
5

Użyj flagę PASSTHRU z Comapre-Object tak:

Compare-Object -ReferenceObject $FolderA -DifferenceObject $FolderB -Passthru | % {$_.FullName} >> C:\CmpOut.txt 
+0

W ten sposób SideIndicator jest stracone. –

1

Rura to poprzez ForEach {$_.InputObject.FullName}.

Jak to:

Compare-Object -ReferenceObject $FolderA -DifferenceObject $FolderB | ForEach {$_.InputObject.FullName} 
+0

W ten sposób SideIndicator został utracony. –

+1

Nie jest stracone ... jest dostępne przez '$ _. SideIndicator'. – aphoria

Powiązane problemy