Created
December 16, 2016 00:12
-
-
Save 9999years/6953982f38a5edb02cfc495c0744bb8d to your computer and use it in GitHub Desktop.
A set of Powershell cmdlets for modifying file names (replacing strings and stripping end/start strings)
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
function StripStartName { | |
[CmdletBinding()] | |
Param( | |
[String]$Name | |
) | |
ls | %{ | |
if($_.Name.StartsWith($Name)) { | |
ren -LiteralPath "$($_.FullName)" "$($_.Parent.FullName)\$($_.Name.Substring($Name.Length))" | |
} | |
} | |
} | |
function StripEndName { | |
[CmdletBinding()] | |
Param( | |
[String]$Name | |
) | |
ls | %{ | |
if($_.Name.EndsWith($Name)) { | |
ren -LiteralPath "$($_.FullName)" "$($_.Parent.FullName)\$($_.Name.Substring(0, $_.Name.LastIndexOf($Name)))" | |
} | |
} | |
} | |
function ReplaceInFileName { | |
[CmdletBinding()] | |
Param( | |
[String]$Replace, | |
[String]$With | |
) | |
ls | %{ | |
if($_.Name.Contains($Replace)) { | |
ren -LiteralPath "$($_.FullName)" "$($_.Parent.FullName)\$($_.Name.Replace($Replace, $With))" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment