Last active
August 23, 2016 20:03
-
-
Save abergs/e682cd1f98f5170e86a6 to your computer and use it in GitHub Desktop.
Remove node_modules
This file contains 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
# By Anders and Henkan 2014-08-07 v1 | |
# http://ideasof.andersaberg.com | |
$path = $args[0] | |
$chars = "abcdefghijklmnopqrstuvwxyz" | |
function GetFileName($num) | |
{ | |
$name = "" | |
while($num -gt 25) { | |
$name += "z" | |
$num -= 26 | |
} | |
$name += $chars[$num] | |
return $name | |
} | |
function RenameRec($xpath) { | |
$counter = -1 | |
$items = @(Get-ChildItem $xpath | ForEach-Object -Process {$_.FullName}) | |
foreach($item in $items) { | |
$counter += 1 | |
$filename = split-path $item -Leaf | |
$name = GetFileName($counter) | |
#write-host "OLD $filename NEW $name" | |
if($filename -ne $name){ | |
#Write-Host "Renaming $item to $name" | |
Rename-Item $item $name | |
} | |
} | |
$folders = @(Get-ChildItem $xpath -Directory | ForEach-Object -Process {$_.FullName}) | |
foreach($folder in $folders) { | |
RenameRec($folder) | |
} | |
} | |
Write-Host "Renaming all files... (this can take a while, Ignore any errors)" | |
RenameRec($path) | |
Remove-Item $path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@joezimjs thanks, works great. No need to use powershell.