/build/static/layout/Breadcrumb_cap_w.png

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)

Posted by: flip1001 9 years ago
Black Belt
0
robocopy 1stfolder 2ndfolder /E
robocopy 2ndfolder 3rdfolder /MIR
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ