【问题标题】:How do I copy files with different names form one folder to another folder using powershell?如何使用powershell将不同名称的文件从一个文件夹复制到另一个文件夹?
【发布时间】:2020-04-01 15:23:23
【问题描述】:

我有一个文件夹,其中包含许多不同名称的不同 csv 文件。我正在尝试将一组 129 个复制到不同的文件夹中。 129 个中的每一个都有不同的名称。有没有办法一次在powershell中做到这一点?也许使用 copy-item 但我需要能够做类似的事情;复制项目 oldfolder\somename.csv AND oldfolder\anothername.csv AND etc. -destination differentexistingfolder

【问题讨论】:

  • 您要从源目录中复制所有*.csv 文件,还是复制129 个特定 csv 文件?
  • 这129个文件有什么共同点吗?您是否尝试将所有文件从一个文件夹复制到另一个文件夹?
  • 我只想从许多其他 .csv 文件中复制 129 个 .csv 文件。每个文件都有不同的名称。所以有 129 个特定的 csv 文件。

标签: powershell copy-item


【解决方案1】:

假设您有一个带有文件名的文本文件,例如:

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\

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-02
    • 1970-01-01
    • 2018-10-12
    • 1970-01-01
    相关资源
    最近更新 更多