Powershell’s tricks

Suppose you have a deep and complex folder tree and you need a list of folders containing specific files –like CSS files; say you wanna minify them; what would you do?

a clean dir *.css /s /b returns the files’ bare name and path, but there’s no grouping there… Oh wait! we have powershell! Let’s use it!

ls -Filter *.css -Recurse -Name | group -Property directoryname

^^ this returns a Dictionary> where the key is the unified folder names where .css files reside. easy huh? OK now go and minify those files… DONE? Oh wait! what if you’ve missed some files? I won’t check back manually! I can’t actually act like a ASP:Repeater! here comes the Powershell again!

$list=ls -Filter *.css -Recurse -Exclude *.min.css -Name
$minlist=ls -Filter *.min.css -Recurse -Name
$list | where {$minlist -cnotcontains $_.Replace(".css", ".min.css")}

and yes! there was a file I missed!

Minified the file and now I’m good to go!

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="">