Powershell - Compare Source and Target directories for .txt files. Copy all files that are not already in target to target AND a third directory.
Need to compare source directory $source to $dest to see what .wav files are in source but not target. I want to copy those files that are not in target to the target AND to a third directory $sharefolder Here is what I have so far. It appears that the copy-item is putting all of the differences into one copy string:
$sharefolder = '\\isilon1\blob\partial_dictation'
$comparefolder = '\\isilon1\blob\partial_dictation_compare'
$source = Get-childitem \\isilon1\blob\dcbld\pv -filter *.wav -recurse
$dest = Get-ChildItem \\isilon1\blob\Partial_Dictation_Compare -filter *.wav -recurse
$diff = Compare-Object $dest $source -passthru | Where-Object {$_.SideIndicator -EQ "=>"} | % {$_.FullName}
ForEach-Object {
Copy-Item "$diff" "$comparefolder" -WhatIf
Copy-Item "$diff" "$sharefolder" -WhatIf
}
This is what I get if I echo $diff ;
\\isilon1\blob\dcbld\pv\-D\CB\LD\-9\94\1.wav
\\isilon1\blob\dcbld\pv\-D\CB\LD\-9\94\2.wav
This is correct as these files are not in the destination. When the copy-item runs, it gives this:
Copy-Item : Cannot find path '\\isilon1\blob\dcbld\pv\-D\CB\LD\-9\94\1.wav \\isilon1\blob\dcbld\pv\-D\CB\LD\-9\94\2.wav' because it does not exist.
I am coming from Unix so this is new to me. Any thougts? Suggestions??
0 Comments
[ + ] Show comments
Answers (1)
Please log in to answer