我有一个文件夹,其中包含许多不同名称的 csv 文件。我正在尝试将一组 129 个复制到不同的文件夹。129 个中的每一个都有不同的名称。有没有办法一次在powershell中做到这一点?也许使用 copy-item 但我需要能够做类似的事情;copy-item oldfolder\somename.csv AND oldfolder\anothername.csv AND etc. -destination differentexistingfolder
假设您有一个包含文件名的文本文件,例如:
file1.csv
file2.csv
someother.csv
...
你可以做:
# read file names from txt file
$filenames = Get-Content path\to\file\with\names.txt
# find the files and copy them
Get-ChildItem -Path path\to\oldfolder\ -Filter *.csv |Where-Object { $filenames -contains $_.Name } |Copy-Item -Destination path\to\destination\
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句