本文介绍了PowerShell脚本从列表中删除文件并输出已删除文件的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件列表,包括它们在.txt中的位置,如下所示:
I have a list of files including their location in a .txt like the following:
例如,如何从"backupsFolder"文件夹开始递归删除所有其他内容,并输出所有已删除的文件?
How do I delete everything else recursively starting from the 'backupsFolder' folder for example, and also output all the deleted files?
推荐答案
我认为这应该有所帮助.
I think this should help.
脚本:
$TargetFolder = "Pathofyourfolder"
$Files = Get-ChildItem $TargetFolder -Exclude (gc List.txt) -Recurse
foreach ($File in $Files)
{ write-host "Deleting File $File" -foregroundcolor "Red"; Remove-Item $File | out-null }
这篇关于PowerShell脚本从列表中删除文件并输出已删除文件的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!