Tyrone Hirt
Tyrone Hirt

Reputation: 341

PowerShell - Rename files with number prefix

I have the following code:

$FilesFolder = "$env:USERPROFILE\Desktop\FilesToRename"
foreach($item in $FilesFolder)
{
Get-ChildItem $FilesFolder | Rename-Item -NewName { "Test - " + $_.Name }
}

It's a simple code, basically it adds the prefix Test - to all files in the folder that is in the $FilesFolder variable.

The issue is that I would like each file in that folder to gain a numerical prefix, that is, if the folder has 3 files it would have a file with a 01 prefix, a file with a 02 prefix and another with a 03 prefix.

Which file will receive the prefix makes no difference in my case, I would just like each file to have a numeric prefix.

How can I do this?

Upvotes: 1

Views: 15

Answers (0)

Related Questions