我有一個包含檔案夾名稱串列的文本檔案。
我想從我的目錄中洗掉名稱出現在文本檔案中的檔案夾
這是我的嘗試
#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 / 5 000
這給了我文本檔案和目錄中存在的檔案夾名稱串列。現在我想洗掉此串列中的檔案夾
希望有人可以幫助
謝謝
uj5u.com熱心網友回復:
你可以使用
#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
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/474175.html
