Computer Hope

Microsoft => Microsoft DOS => Topic started by: Blisk on May 14, 2019, 02:23:00 AM

Title: Powershell find in compare folder A and B and copy
Post by: Blisk on May 14, 2019, 02:23:00 AM
I have folder A with files which are compressed and copied to folder B
files in folder A have extension .bak, files in folder B have extension .zip, but both have the same name. (Like first is monday.bak and second is monday.zip)
now I need to copy files from folder A to folder C, but only files which doesn't exist in folder B.
For example folder A have files
monday.bak
tuesday.bak
wednesday.bak

Folder B have files
monday.zip
tuesday.zip

Now I need to copy from folder A to folder C what is missing in folder B
and that is file wednesday.bak


I tried this but not working, what I am doing wrong?

Code: [Select]
$path1 = D:\A
$path2 = D:\B
$path3 = D:\C
$fileList = get-childitem $path1 | ?{$_.name -notin $(get-childitem $path2).name }
$filelist.name | copy-item  $path3
Title: Re: Powershell find in compare folder A and B and copy
Post by: Salmon Trout on May 14, 2019, 02:15:02 PM
Do you get any error messages?
Title: Re: Powershell find in compare folder A and B and copy
Post by: Blisk on May 15, 2019, 12:12:10 AM
You must provide a value expression on the right-hand side of the '-' operator.
Code: [Select]
At D:\copy_files.ps1:4 char:47
+ $fileList = get-childitem $path1 | ?{$_.name - <<<< notin $(get-childitem $path2).name }
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression
Title: Re: Powershell find in compare folder A and B and copy
Post by: Salmon Trout on May 15, 2019, 12:15:30 AM
Have you Googled what that might mean?
Title: Re: Powershell find in compare folder A and B and copy
Post by: Blisk on May 15, 2019, 12:18:07 AM
Have you Googled what that might mean?

I did, but I get many different results so don't know what it is