Skip to content

Instantly share code, notes, and snippets.

@ytechie
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytechie/a41593592b63d98cdae1 to your computer and use it in GitHub Desktop.
Save ytechie/a41593592b63d98cdae1 to your computer and use it in GitHub Desktop.
Powershell Script to remove partial file name before the tilde
# I had some files that had some garbage text attached and separated with a tilde. This script was used to remove that extra text.
# Example: blah ~ IMG123.jpg -> IMG123.jpg
Get-ChildItem "e:\photography" -Recurse -filter *~* | `
Foreach-Object {
$oldName = $_.Name
$pos = $oldName.IndexOf("~")
$newName = $oldName.Substring($pos + 2)
#write-host $_.fullname
write-host $_.FullName + " -> " + $newName
rename-item $_.FullName -NewName $newName
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment