0
爲了提高我的PowerShell技能,下面是一個簡單問題的難題解決方案示例。任何建議如何改善oneliner是值得歡迎的。使用PowerShell過濾和複製
任務:修剪一個巨大的圖標庫,使其更易於管理。原來的目錄結構看起來像這樣:
/Apps and Utilities /Compile /32 Bit Alpha png /Compile 16 n p.png /+ 10 or more files /+ 5 more formats with 10 or more files each /+ 20 or so icon names /+ 22 more categories
我想複製32位阿爾法PNG和平坦的目錄結構了一下。這是我的快速和非常骯髒的解決方案:
$dest = mkdir c:\icons; gci -r | ? { $_.Name -eq '32 Bit Alph a png' } | % { mkdir ("$dest\" + $_.Parent.Parent.Name + "\" + $_.Parent.Name); $_ } | gci | % { cp $_. FullName -dest ("$dest\" + $_.Directory.Parent.Parent + "\" + $_.Directory.Parent) }
不好,但它解決了我的問題。產生的結構:
/Apps and Utilities /Compile /Compile 16 n p.png /etc /etc /etc
你會怎麼做?
將考慮排序。在編寫腳本時,我擴展了大部分別名,但是我喜歡我的簡化版 - ls(或dir)比gci更好的選擇:)。 – Bergius 2009-01-27 10:53:04