【问题标题】:Move Files from one folder to another without using -Recurse不使用 -Recurse 将文件从一个文件夹移动到另一个文件夹
【发布时间】:2019-01-27 15:55:15
【问题描述】:

我有一个 powershell 脚本,我想做的就是将某种类型的文件从指定的文件夹移动到目标文件夹。不幸的是,如果没有包含 -Recurse,这将无法工作,这不是我想要实现的功能。如果我包含 -Recurse 它开始从“D:/Photos/x/”等移动图像。我要做的就是将文件从“D:/Photos”移动到目的地

Get-ChildItem "D:\Photos" -Include *.png, *.jpeg, *.jpg |
Move-Item -Destination "D:\Photos\Powershell Task" -Force

【问题讨论】:

    标签: powershell


    【解决方案1】:

    没有-Recurse-Include 参数不起作用。

    但是,还有另一种方法可以让 -Include 执行您想要的操作(即过滤多个扩展名),即将\* 添加到路径中。

    在你的情况下:

    Get-ChildItem -Path "D:\Photos\*" -Include *.png, *.jpeg, *.jpg |
    Move-Item -Destination "D:\Photos\Powershell Task" -Force
    

    请注意:目标路径 D:\Photos\Powershell Task 必须存在。

    【讨论】:

      【解决方案2】:

      解决方案:

      Get-ChildItem "D:\Photos\*" -Include *.png, *.jpeg, *.jpg | Move-Item -Destination "D:\Photos\Powershell Task" -Force
      

      说明: 选择 Get-ChildItem 以使用包含时,您必须选择 -recursion 或使用 -path 中的通配符定义包含的内容。 这种情况 D:\Photos\* 定义为获取 D:\Photos 中同时具有名称和扩展名的所有子项,然后您使用 -include 过滤这些子项,仅说出具有扩展名的子项。 jpg .png

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-25
        • 1970-01-01
        相关资源
        最近更新 更多