Last active
July 12, 2024 07:22
-
-
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.
This file contains hidden or 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
#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