Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Powershell find in compare folder A and B and copy  (Read 3673 times)

0 Members and 1 Guest are viewing this topic.

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    Powershell find in compare folder A and B and copy
    « 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

    Salmon Trout

    • Guest
    Re: Powershell find in compare folder A and B and copy
    « Reply #1 on: May 14, 2019, 02:15:02 PM »
    Do you get any error messages?

    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: Powershell find in compare folder A and B and copy
      « Reply #2 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

      Salmon Trout

      • Guest
      Re: Powershell find in compare folder A and B and copy
      « Reply #3 on: May 15, 2019, 12:15:30 AM »
      Have you Googled what that might mean?

      Blisk

        Topic Starter


        Intermediate

        Thanked: 1
        • Experience: Familiar
        • OS: Windows 7
        Re: Powershell find in compare folder A and B and copy
        « Reply #4 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