Author Posts

August 17, 2017 at 3:20 pm

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 }

August 17, 2017 at 4:39 pm

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"

August 17, 2017 at 5:30 pm

Hi Olaf,

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

Thanks again!