Batch File Rename Utility
This PowerShell script is designed to facilitate the batch renaming of files in a specified directory. Administrators often need to organize files systematically, and this script provides a simple solution for modifying file names based on user-defined patterns. Utilizing this utility alongside ServerEngine can help maintain orderly file systems, increase productivity, and ensure that files are easily accessible and identifiable.
param ( [string]$directoryPath = "C:\FilesToRename", [string]$newFileNamePattern = "Document_{0:0000}.txt" ) # Get all files in the specified directory $files = Get-ChildItem -Path $directoryPath # Initialize a counter for new names $counter = 1 foreach ($file in $files) { # Generate a new file name using the specified pattern $newFileName = $newFileNamePattern -f $counter $newFilePath = Join-Path -Path $directoryPath -ChildPath $newFileName # Rename the file Rename-Item -Path $file.FullName -NewName $newFilePath Write-Output "Renamed '$($file.Name)' to '$newFileName'" # Increment the counter $counter++ } Write-Output "Batch file renaming completed."