Prefix filename with sequential number. Be prompted (powershell)

  • 8 months ago
Comment

ChatGPT
1 / 1

You can use PowerShell to rename files in a directory by adding a sequential number prefix and prompting the user for confirmation. Here's how you can achieve this:

powershell
$directoryPath = "C:\Path\To\Your\Directory"
$files = Get-ChildItem -Path $directoryPath -File

foreach ($file in $files) {
$newFileName = Read-Host "Enter a new name for $($file.Name)"
$newFileName = "$newFileName $($file.Name)"
Rename-Item -Path $file.FullName -NewName $newFileName
}

Replace "C:\Path\To\Your\Directory" with the actual path to the directory containing the files you want to rename.

When you run this script, it will prompt you for a new name for each file and then rename the file with the provided name and its original extension. It will also add a sequential number as a prefix to each file to ensure unique names.

Keep in mind that this script does not handle validation of the new names, so you should provide valid names to avoid issues.

Note: Please be cautious when renaming files in bulk, as incorrect renaming can lead to data loss or confusion. Make sure to test the script on a small set of files before using it on a larger scale.