通过命令提示符一次从文件夹中删除20个文件中的3个



c:userssamdesktoptest Del x1.txt x2.txt x3.txt

这个工作很好。但是如何做到不去文件夹路径

你有点深奥…编写脚本会更容易。

是一个基本的脚本,你可以从这里展开:

#Get the path
$path = "$env:USERPROFILEDesktop"
#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
    }
}

最新更新