Reputation: 2705
In bash, you can
cp filea fileb filec Folder
which will copy filea
fileb
and filec
into Folder
For some reason, i couldn't find a way to do the same thing in Powershell.
Everywhere i looked, all i could find is just the possibility to use wildcards in order to move
a bunch of files from the same type like:
cp *.txt Folder
But that's not what i'm looking for. I'm looking for a way to copy several files
by their names in one command.
Does anybody knows a way to do that?
Upvotes: 1
Views: 85
Reputation: 15470
A one liner to do:
@("file1","file2","filen") | % {Copy -Path $_ -Destination "destination"}
Upvotes: 0
Reputation: 9581
"I'm looking for a way to copy several files by their names in one command."
Here are three examples that can do what you want. The first one is closest to what you're looking for.
param(
$files = @('filea', 'fileb', 'filec'),
$dest = 'Folder'
)
Copy-Item -LiteralPath $files -Destination $dest -Verbose
$files | ForEach-Object { Copy-Item -Path $_ -Destination $dest -Verbose }
foreach ($file in $files) { Copy-Item -Path $file -Destination $dest -Verbose }
Upvotes: 2