简体   繁体   中英

How to copy array of files (3,500) from directory A to Directory B

I have 3,508 files with different names that need to copy from directory a to directory b.

Have tried:

Copy-Item "C:\users\username\directory-a\file-1.jpeg,file-2.jpeg" -Destination "C:\users\username\directory-b\"

Powershell will give error on file separation.

PowerShell will take an array of filenames as the -Path , -LiteralPath , or -Include parameter; however, if you are providing multiple filenames separated by commas, each one must be quoted separately - your example provides only a single file name that contains commas. Instead, use

Copy-Item "C:\users\username\directory-a\file-1.jpeg","C:\users\username\directory-a\file-2.jpeg" -Destination "C:\users\username\directory-b\"

or

Copy-Item "C:\users\username\directory-a\*" -Include "file-1.jpeg","file-2.jpeg" -Destination "C:\users\username\directory-b\"

You can pass a variable that is an array of file names to any of the parameters I mentioned above, eg,

$files = (Get-Content C:\User\Me\List-of-files.txt)
Copy-Item -Path $Files -Destination D:\New-Folder

The documentation for Copy-Item at Microsoft Docs does not make this clear.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM