Category Archives: Powershell

Make windows files/folders permissions right

There are times on windows when you migrate your files to a new system and you will face the corrupted permission-sets on your files or folders. These 4 cmd commands will help you gain your control over your files again 🙂

CD \
TAKEOWN /F * /A /R 1 > NUL
ICACLS * /reset /T /Q

Just remember to create a batch file containing those lines above. 🙂

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!