【问题标题】:Delete 3 of 20 files from a folder at a time through command prompt通过命令提示符一次从文件夹中删除 20 个文件中的 3 个
【发布时间】:2016-12-24 17:40:50
【问题描述】:

c:\users\sam\desktop\test Del x1.txt x2.txt x3.txt

这工作正常。但是如何在不转到文件夹路径的情况下做到这一点。

【问题讨论】:

    标签: windows shell command command-prompt


    【解决方案1】:

    你在这里有点深奥......编写脚本会更容易。

    这是一个基本脚本,您可以从这里扩展:

    #Get the path
    $path = "$env:USERPROFILE\Desktop"
    
    #Get the files in the path
    $Files = Get-ChildItem $path
    
    #Loop through each file
    foreach($file in $files)
    {
        #Check to see if it's a text file
        if($file -like "*.txt")
        {
            #Delete the file and do not confirm
            Remove-Item $file -Confirm:$false -ErrorAction SilentlyContinue
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-04
      • 1970-01-01
      • 1970-01-01
      • 2020-02-01
      • 2014-02-15
      相关资源
      最近更新 更多