Skip to content

Instantly share code, notes, and snippets.

@richjenks
Created April 16, 2016 07:59
Show Gist options
  • Save richjenks/b54c57798b483e90f4d5bfdcbdb6d74d to your computer and use it in GitHub Desktop.
Save richjenks/b54c57798b483e90f4d5bfdcbdb6d74d to your computer and use it in GitHub Desktop.
PowerShell snippets
# 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