3

I used the Copy-Item command to copy a set reports to a server location. It was working fine before but recently more reports have been added to the folder and now most of the times it works fine but in some cases it shows the error:

The target file "$destination" is a directory, not a file

The code I used is:

Copy-Item -Path "$Source" -Destination "$destination" -Recurse -Force

I am not sure why I am not getting this error for every case.

1
  • 2
    Show us what is in $Source and $destination Commented Apr 5, 2022 at 19:01

1 Answer 1

1

What you have should work but this may work around the issue if there is some limitation with certain shared folder destinations:

Note: Remove the -WhatIf once you confirm the changes it will make are correct. Currently it will only output what files would have been copied.

Get-ChildItem $Source | Foreach-Object {
  Copy-Item $_.FullName $destination -Recurse -Force -WhatIf
}

Basically, this enumerates all of the files and folders under the $Source directory, then copies the files or folders individually to the destination.


If you are able to offer the values of $Source and $Destination I or another might be able to offer a solution to your problem, rather than a workaround.

Sign up to request clarification or add additional context in comments.

1 Comment

$Source is a folder that consists of 108 .XML reports and 108 .HTML reports. And $destination is a folder in a server location ,//inrd-tstest01/Reports. And if there is some limitations then it should happen every time when I use this command but it is happening for 50 percent cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.