如何在 PowerShell 中列出目錄內容?
若要顯示目錄內容,請使用 Get-ChildItem cmdlet。你需要提供目錄路徑,或者如果你在同一目錄中,則只需直接使用 Get-ChildItem 即可。在下面的示例中,我們需要顯示 D:\temp 目錄的內容。
當 Get-ChildItem 命令在這個目錄之外執行時,則應提供目錄路徑。這被稱為絕對路徑。
PS C:\> Get-ChildItem D:\Temp\
命令
當此命令直接在目錄內執行時,則只需執行此命令。這被稱為相對路徑。
PS D:\Temp> Get-ChildItem
輸出
Directory: D:\Temp Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 13-12-2019 09:52 GPO_backup d----- 24-11-2018 11:31 LGPO -a---- 07-05-2018 23:00 301 cars.xml -a---- 29-12-2017 15:16 4526 healthcheck.html -a---- 29-12-2017 15:16 4526 healthcheck1.html -a---- 08-12-2017 10:24 48362 servicereport.html -a---- 08-12-2017 10:24 48362 servicereport1.html -a---- 08-12-2017 10:16 393 style.css -a---- 08-12-2017 11:29 7974 Test.xlsx -a---- 25-10-2017 08:13 104 testcsv.csv -a---- 12-12-2017 23:04 1034 testhtmoutput.html
請注意:Get-ChildItem 命令僅顯示資料夾和檔案,但不會顯示子資料夾的內容。若要顯示子資料夾及其檔案,你需要使用 –Recursive 引數。
廣告