user1062718
user1062718

Reputation: 11

Copy files without recreating subdirectories using Powershell

The solution here works for me if the command is executed at a command prompt:

Copy files without recreating subdirectories

However, I get an error if the command is in a batch file:

"The following usage of the path operator in batch-parameter substitution is invalid %~nf"

How do you code this in Powershell?

Upvotes: 1

Views: 305

Answers (1)

manojlds
manojlds

Reputation: 301357

Replace any % with %% in a bat file.

So %~nf becomes %%~nf

Powershell equivalent:

gci -r .\test | ?{-not $_.PsIsContainer} | copy-item -Destination .\test2

Upvotes: 4

Related Questions