
我注意到,既不能cmd
也powershell
不能對具有隱藏屬性的文件進行遞歸文件搜尋。
那麼有什麼辦法可以解決這個問題嗎?我的意思是,除了必須從相關文件中刪除隱藏屬性之外,為此我需要事先知道它們的位置,這當然會使整個練習變得毫無意義。
為什麼它不適用於具有隱藏屬性的檔案?這是某種安全功能嗎?
範例(cmd)
C:\>dir /b
Intel
PerfLogs
plant
Program Files
Program Files (x86)
Users
Windows
C:\>cd plant
C:\plant>dir /b
banana.txt
C:\plant>attrib banana.txt
A C:\plant\banana.txt
C:\plant>attrib -a +h banana.txt
C:\plant>dir /b
C:\plant>dir /b banana.txt
File Not Found
C:\plant>cd /
C:\>dir /b /s banana.txt
File Not Found
C:\>
答案1
若要列出隱藏文件,請使用電源外殼你必須使用該-Force
參數。因此,透過使用Get-ChildItem -Force -Recurse
您將獲得所有文件的列表,包括隱藏文件。
Get-Help Get-ChildItem -Examples
:
Force 參數將隱藏檔案新增至顯示。
是的,這並不直觀,參數本身的描述也沒有告訴你。
對於命令列本身來說,它將是dir /A
或dir /AH
僅列出隱藏文件,但我不確定您如何搜尋該輸出。
答案2
在 Windows 命令提示字元中,對所有檔案使用 /a 和 /s 開關並遞歸:
/A Displays files with specified attributes.
/S Displays files in specified directory and all subdirectories.
例子
dir/a/s
在 Powershell 中,我使用相同的方法,只是用 -force 而不是 /a 來顯示所有檔案:
dir -force -s
或者
dir -force -r
Powershell 中還有 ls 可以少輸入 1 個字元!
ls -force -s
或者
ls -force -r
答案3
最後得到的答案是:
命令:
dir /a:H /s
POWERSHELL :(
ls -ah -recurse
選項-force)