Copy-File and Folders with Dots

I just discovered that Copy-File behaves differently if the destination includes one or more folders with dots in their names, and thought I would share.

Copy-File -Path C:\Temp\Test.txt -Destination c:\Users\JDoe\Desktop\Temp creates a Temp folder and copies Test.txt into it.

Copy-File -Path C:\Temp\Test.txt -Destination C:\Users\JDoe\Desktop\Temp.1 copies Test.txt to the desktop and renames it Temp.1.

Copy-File -Path C:\Temp\Test.txt -Destination C:\Users\JDoe\Desktop\Temp.2\Temp.3 generates an error “Could not find a part of the path”

Copy-file -Path C:\Temp\Test.txt -Destination C:\Users\JDoe\Desktop\Temp.2\Temp.3\ create the folders and copies the file where intended.

1 Like

I just encountered this myself, so it doesn’t appear to have been fixed. Not even sure if new versions are still being released?

In my scripts if I want a folder I explicitly create that folder using New-Folder before using the Copy-File cmdlet. I think that’s a better approach than relying on the Copy-File cmdlet to create folders.