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