Created
April 16, 2016 07:59
-
-
Save richjenks/b54c57798b483e90f4d5bfdcbdb6d74d to your computer and use it in GitHub Desktop.
PowerShell snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Batch rename files (underscores to hyphens) | |
Dir | Rename-Item –NewName { $_.name –replace "_","-" } | |
# Get full path of all files | |
gci -r | where {$_.extension -match ".html|.htm|.php|.asp"} | select FullName | |
# Delete all files except... | |
gci -r | ? {$_.extension -notmatch ".html|.htm|.php|.asp"} | ? {-not $_.PsIsContainer } | remove-item | |
# Delete SVN folders | |
(get-childitem -recurse -force | where-object { $_.PsIsContainer -eq $true -and $_.Name -eq ".svn" } ) | remove-item –recurse -force | |
# Delete empty directories | |
Get-ChildItem -recurse | Where {$_.PSIsContainer -and @(Get-ChildItem -Lit $_.Fullname -r | Where {!$_.PSIsContainer}).Length -eq 0} | Remove-Item -recurse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment