File Copy

Welcome Forums General PowerShell Q&A File Copy

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 7 months ago.

  • Author
  • #77479

    Points: 0
    Rank: Member

    I have two folders Folder1 and Folder2 in C drive. Folder1 has few files which needs to be copied to Folder2. Also, after copy of each file from folder1 to folder2, the files can be moved to another folder called 'Backup'. The point is – this needs to be done by looping each file in the folder. Can you please guide me on this? I am currently using the below script for this, but this gives an error

    $CopyFrom = "C:\Folder1"
    $CopyTo = "C:\Folder2"

    Get-ChildItem -Path $CopyFrom -Exclude *_ControlFile_* | ForEach-Object -Process {Copy-Item $File -Destination $CopyTo }

  • #77481

    Points: 1,086
    Helping Hand
    Rank: Community Hero

    If you want to deliver a professional copy job you can use robocopy .... it's specially made for. 😉

    robocopy "C:\Folder1" "C:\Folder2"  /XF "*_ControlFile_*"

    But if you need to use Powershell you can make your life easier like this:

    Get-ChildItem -Path "C:\Folder1" -Exclude "*_ControlFile_*" | Copy-Item -Destination "C:\Folder2"
  • #77490

    Points: 0
    Rank: Member

    Hi Olaf,

    Thanks for your response. I understand that simple child-item / copy-item combination would work.

    Thanks again!

The topic ‘File Copy’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort