Skip to content

Instantly share code, notes, and snippets.

@biagnei240698
Last active July 12, 2024 07:22
Show Gist options
  • Save biagnei240698/f031d0d7675ba92df0fc79ab3ca368f3 to your computer and use it in GitHub Desktop.
Save biagnei240698/f031d0d7675ba92df0fc79ab3ca368f3 to your computer and use it in GitHub Desktop.
RenameFileBulkPrefix -> this script rename all files in a directory if te filename contains "-" and rename te prefix.
#Script for rename files
$path = "C:\<directory>\"
get-childitem $path | ForEach-Object {
$fileName = $_.Name
$fileExtension = $_.Extension
$findChar = $_.Name.IndexOf("-")
if($findChar -lt 0){
$findChar = 0;
} else {
$prefixOfName = $fileName.Substring(0, $findChar)
$newName = $prefixOfName + $fileExtension
rename-item -path ($path + $fileName) -NewName $newName
echo "name-old: " + $fileName + " name-new: " + $newName
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment