
顯示或不顯示特定資料夾上的隱藏項目的設定在哪裡?例如,如果全域設定是顯示所有隱藏文件,我該如何更改桌面資料夾,以便不顯示隱藏的desktop.ini文件?
我希望能夠以程式方式更改它,希望在 Powershell 中。
答案1
attrib -s -h
或者
attrib +s +h
(抱歉,不是 Powershell。老套了。)
有一篇關於 Powershell 的好文章這裡。相關位:
$file=file.txt
$file.attributes="Hidden"
$file.attributes="Normal"
答案2
在 Powershell 中,隱藏屬性儲存在 Directoryinfo 類型的 Attributes 屬性中。
要查看目錄中的所有項目及其屬性,您可以這樣做:
Get-ChildItem "C:\MyPath" -Force | Select Name, Attributes
這些屬性是逗號分隔的條目,用於解釋某些屬性,例如隱藏資料夾的「隱藏,目錄」。您可以透過對多個項目的 Attributes 屬性進行正規表示式替換來刪除隱藏屬性,如下所示:
Get-ChildItem "C:\MyPath" -Force |? {$_.Attributes -like "*hidden*"} |% {$_.Attributes = $_.Attributes -replace ", Hidden|Hidden,? ?", ""}