我一直在試圖得到一個非常具體的目錄列表,迄今爲止沒有成功。兩個級別的目錄列表與Powershell
可以說我有一個文件夾結構是這樣的:
- C:\的Inetpub \更新\ updatefolder1
- C:\的Inetpub \更新\ updatefolder1 \網絡\
- C:\的Inetpub \更新\ updatefolder1 \網絡\(站點代碼,結構變亮)
- C:\的Inetpub \更新\ updatefolder1 \腳本\(DB腳本)
- C:\的Inetpub \更新\ updatefolder2
- C:\的Inetpub \更新\ updatefolder2 \網絡\(站點代碼,結構變亮)
現在,當我使用的foreach,它看起來就像這樣:
$folders = Get-ChildItem $UpdateDir -Directory -Recurse -Depth 1 | Select-Object FullName
ForEach($folder in $folders) {
$folder = folder.TrimStart("@{FullName=").TrimEnd("}") #To get a clean name
}
結果將如下:
C:\inetpub\updates\updatefolder1
C:\inetpub\updates\updatefolder2
C:\inetpub\updates\updatefolder1\Web\
C:\inetpub\updates\updatefolder1\Web\ (site code, the structure goes on)
C:\inetpub\updates\updatefolder1\Scripts\ (db scripts)
C:\inetpub\updates\updatefolder2\Web\ (site code, the structure goes on)
哪個不好。 它應該看起來像這樣:
C:\inetpub\updates\updatefolder1
C:\inetpub\updates\updatefolder1\Web\
C:\inetpub\updates\updatefolder1\Web\ (site code, the structure goes on)
C:\inetpub\updates\updatefolder1\Scripts\ (db scripts)
C:\inetpub\updates\updatefolder2
C:\inetpub\updates\updatefolder2\Web\ (site code, the structure goes on)
任何新穎的想法?我嘗試了幾件事,除了那個foreach循環之外,仍然沒有運氣。
在此先感謝。
1.你已經張貼在這裏似乎有許多錯別字的代碼的結果進行排序。 2.你想達到什麼目的? 3.您發佈的兩個結果似乎都是相同的,只是序列/順序不同。你可以請檢查一次並確認嗎? – SavindraSingh
問題是你用來獲取全名的可怕黑客攻擊。刪除整個'ForEach'循環並將第一行更改爲'$ folders = Get-ChildItem $ UpdateDir -Directory -Recurse -Depth 1 | Select-Object -Expand FullName' – TheMadTechnician
@SavindraSingh錯別字?哪裏?除了我忘記添加變量實際輸出的事實。 – Ramil