我正在撰寫一個腳本,它將遍歷我擁有的檔案夾,并顯示檔案的名稱。我面臨的唯一問題是檔案夾中有很多檔案夾。示例(在 Test Upload 檔案夾內,還有三個檔案和兩個檔案夾。這兩個檔案夾中有 3 個檔案,另一個檔案夾包含一個檔案)我不確定如何繼續回圈,直到所有檔案和每個檔案夾都已讀。
$Files = Get-ChildItem "C:\Users\HelloWorld\Documents\Test Upload"
#write-host $Files
GetFolderContents($Files)
function GetFolderContents($Test){
#$Sub = Get-ChildItem "C:\Users\HelloWorld\Documents\Test Upload\$Test"
foreach($files in $Test){
#check if folder or file
if (! $files.PSIsContainer)
{
write-host "File"
}
else{
write-host "Folder"
#need to now loop through this folder and get its contents
}
}
}
uj5u.com熱心網友回復:
使用-Recurseswitch 引數Get-ChildItem使其遞回列舉整個目錄結構:
$Files = Get-ChildItem "C:\Users\HelloWorld\Documents\Test Upload" -Recurse
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/441140.html
