【问题标题】:Powershell - Move files 1 folder deeperPowershell - 将文件移动1个文件夹更深
【发布时间】:2018-05-10 11:01:01
【问题描述】:

我希望将大量 pdf 文件移到更深的文件夹中。

当前文件结构为:
[Reference Code]\[file].pdf
我希望将文件移动到:
[Reference Code]\April 18\[file].pdf

如果我没记错的话,这可以在 linux 中使用mv */*.pdf */April 18/*.pdf 完成,但 Windows 的解决方案似乎有点复杂

【问题讨论】:

    标签: powershell move subdirectory


    【解决方案1】:
    $rootPath = "C:\"
    $moveTo = "C:\April 18"
    
    foreach ($pdfFile in (Get-ChildItem $rootPath | Where-Object {$_.Extension -eq ".pdf"}))
    {
        Move-Item -Path $pdfFile.FullName -Destination "$moveTo\$($pdfFile.Name)"
    }
    

    像这样?

    【讨论】:

    • 感谢您的回答,效果非常好,并为我提供了一个很好的例子
    【解决方案2】:

    一种可能性:

    $rootDir = "Reference Code"
    
    Get-ChildItem -Path "$rootDir\*.pdf" -File |
        ForEach-Object {
            Move-Item $_.FullName -Destination "$rootDir\April 18\$($_.Name)"
        }
    

    请注意,如果文件夹 April 18 不存在,这将失败。

    【讨论】:

    • 感谢您的选择,我应该指定我正在寻找创建文件夹的脚本,但这为我提供了一个很好的构建示例
    猜你喜欢
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 2021-12-02
    • 1970-01-01
    • 2012-11-11
    • 1970-01-01
    • 2020-08-08
    相关资源
    最近更新 更多