Powershell - 如果文本文件中存在名称,则删除文件夹
Powershell - delete folder if name exists in text file
我有一个包含文件夹名称列表的文本文件。
我想从我的目录中删除名称出现在文本文件中的文件夹
这是我的尝试
#I get the contents of the text file
$textfile = Get-Content "C:\Users\s611284\Desktop\Dossiers.txt"
#I get the name of the folders from the directory
$Foldersname = Get-ChildItem -Path $Directory | ForEach-Object {
$_.BaseName
}
#I get the names present in the text file and in the folders of the directory
Compare-Object -IncludeEqual $textfile $Foldersname | Where-Object SideIndicator -eq '=='
93 / 5000
这为我提供了文本文件和目录中的文件夹名称列表。现在我想删除此列表中的文件夹
希望有人能帮忙
谢谢
你可以使用
#I get the contents of the text file
$textfile = Get-Content "C:\Users\s611284\Desktop\Dossiers.txt"
#I get the name of the folders from the directory
$Foldersname = Get-ChildItem -Path $Directory | ForEach-Object {
$_.BaseName
}
#I get the names present in the text file and in the folders of the directory
Compare-Object -IncludeEqual $textfile $Foldersname | Where-Object SideIndicator -eq '=='|ForEach-Object {
$item=$_.inputobject
remove-item $Directory$item -Recurse
}
我有一个包含文件夹名称列表的文本文件。
我想从我的目录中删除名称出现在文本文件中的文件夹
这是我的尝试
#I get the contents of the text file
$textfile = Get-Content "C:\Users\s611284\Desktop\Dossiers.txt"
#I get the name of the folders from the directory
$Foldersname = Get-ChildItem -Path $Directory | ForEach-Object {
$_.BaseName
}
#I get the names present in the text file and in the folders of the directory
Compare-Object -IncludeEqual $textfile $Foldersname | Where-Object SideIndicator -eq '=='
93 / 5000
这为我提供了文本文件和目录中的文件夹名称列表。现在我想删除此列表中的文件夹
希望有人能帮忙
谢谢
你可以使用
#I get the contents of the text file
$textfile = Get-Content "C:\Users\s611284\Desktop\Dossiers.txt"
#I get the name of the folders from the directory
$Foldersname = Get-ChildItem -Path $Directory | ForEach-Object {
$_.BaseName
}
#I get the names present in the text file and in the folders of the directory
Compare-Object -IncludeEqual $textfile $Foldersname | Where-Object SideIndicator -eq '=='|ForEach-Object {
$item=$_.inputobject
remove-item $Directory$item -Recurse
}