File Copy

This topic contains 2 replies, has 2 voices, and was last updated by  Raghavendran 1 month, 1 week ago.

  • Author
    Posts
  • #77479

    Raghavendran
    Participant

    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

    Olaf Soyk
    Participant

    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

    Raghavendran
    Participant

    Hi Olaf,

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

    Thanks again!

You must be logged in to reply to this topic.