Copy a single file to a non-existing folder

Question:

It’s easy to copy multiple files to a folder that doesn’t exists and let it be created:

The command above will create the folder DoesNotExist. That’s what I’m after.

But what is the PowerShell syntax to the same when the source is only a single file?

I tried C:\Temp2\DoesNotExist\ (with the trailing slash), but Powershell says “The filename, directory name, or volume label syntax is incorrect.” and refuses to copy the single file.

Answer:

If you’re looking for a one liner solution, you can do this.

Source:

Copy a single file to a non-existing folder by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply