Jump to content
EduGeek EdSec 2026 is Go! 27th Oct in Derby! Join us for a day of EdTech security focused talks, networking, and an evening social ×

How to put 00 in front of all files in folder (Batch rename)


Recommended Posts

Posted

Im sure someone will know the answer to this so does anyone know how I do this...

 

I have a folder full of photographs eg. 3829.jpg

I need to add 00 in front of each file. eg. 003829.jpg

 

I have a full folder. Is there a quick way to do this?

 

many thanks in advance Edugeekers.

Posted (edited)

If anyone else is trying to achieve similar but doesn't want to install software, it's only a few lines in Powershell.

 

To make files a set length by adding required number of leading zeros:

$Files = Get-ChildItem -Path E:\Temp\Test -File


$MaxLength = 6


$Files | ForEach-Object {

$Name = $_.BaseName

Do {
$Name = $('0'+$Name).ToString()
}    

While($Name.length -lt $Maxlength)

Rename-Item -Path $_.FullName -NewName "$Name$($_.Extension)"
}

 

Or to add a set number of leading zeros regardless of file name length:

 

$Files = Get-ChildItem -Path E:\Temp\Test -File

$ZerosToAdd = 4

$Files | ForEach-Object {

$Name = $('0' * $ZerosToAdd)+$_.BaseName
Rename-Item -Path $_.FullName -NewName "$Name$($_.Extension)"
}

Edited by sbrade47
  • Thanks 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...