How to batch rename multiple files while keeping the sorting order


  1. Posts : 1
    10.0.17134 Build 17134
       #1

    How to batch rename multiple files while keeping the sorting order


    Pretty hard to explain what I wish to do in a clear title...

    Hello !

    I'll explain with an example, files names will sound silly but I'm sumplifying the issue.

    I have a folder called "test", in this folder I have 3 images (.jpg).
    One image is the picture of the number "1" and is called "5.jpg"
    A second image is the picture of the number "2" and is called "6.jpg"
    A third image is the picture of the number "3" and is called "8.jpg"

    In my folder I sort the files by name which means that I have, in order, the pictures of the "1" > the "2" > and the "3", named "5.jpg" > "6.jpg" > "8.jpg"

    I wish to rename those files as follow :

    - Picture of the "1" = "abc_00010"
    - Picture of the "2" = "abc_00020"
    - Picture of the "3" = "abc_00030"

    Is there a way to do that with a simple command pront ?
    Bascily I would need to have the command to keep the order the file is currently sorted in and apply names of each files in form "abc_X0"

    X being 0001, 0002, 0003, ... 0013, 0014, 0015, ... 0125, 0126, 0127 ... 1454, 1455, 1456

    Thanks by advance for your help !
      My ComputerSystem Spec

  2. pepanee's Avatar
    Posts : 1,186
    Windows 10 Professional
       #2

    Better File Rename: http://www.publicspace.net/windows/B...ame/index.html

    The only restriction in the Trial version is that you can name a maximum of 10 files at a time. No time limit. If you really find this program useful for other projects, then consider purchasing it. I use this program many times on the computer.

    Click image for larger version. 

Name:	image.png 
Views:	3 
Size:	242.4 KB 
ID:	228103
      My ComputerSystem Spec

  3.    #3

    I created a batch script to do this


    I created a batch script to do this. here is the code and a small video I made.

    Code:
    @SetLocal EnableDelayedExpansion
    @echo off
    Echo.
    set /p yourfolder="Input the path to the folder where you want to change filenames to ABC_*: "
    Echo.
    Echo User specified: %yourfolder%
    
    
    For /f %%c in ('echo %yourfolder%') do set upath=%%c
    
    
    If NOT EXIST !upath! goto nofolder
    
    
    cd /d %upath%
    
    
    for %%a in (*) do (
    
    
    set name=%%~na
    
    
    If "!name:~1,1!"=="" (
    set name=000%%a
    echo Renaming "%%a" to "ABC_!name!"
    ren "%%a" "ABC_!name!"
    )
    
    
    IF "!name:~2,1!"=="" (
    set name=00%%a
    Echo Renaming "%%a" to "ABC_!name!"
    ren "%%a" "ABC_!name!"
    )
    
    
    
    
    If "!name:~3,1!"=="" (
    set name=0%%a
    Echo Renaming "%%a" to "ABC_!name!"
    ren "%%a" "ABC_!name!"
    )
    )
    for /f "delims=" %%b in ('dir /b ^| find /i /v "ABC_"') do (
    Echo Renaming "%%b" to "ABC_%%b"
    ren "%%b" "ABC_%%b"
    )
    goto TheEnd
    
    
    :nofolder
    Echo.
    Echo The folder doesn't exist
    
    
    :TheEnd
    pause
    How to batch rename multiple files while keeping the sorting order Attached Files
      My ComputerSystem Spec


  4. Posts : 149
    Microsoft Windows 10 Home
       #4

    In PowerShell (assuming you're in the directory containing the files:

    Code:
    $i = 1
    gci *.jpg | %{rename-item $_.Fullname ('abc_{0:d4}0.jpg' -f $i++) }
    Keith
      My ComputerSystem Spec

  5.    #5

    KeithM said: View Post
    In PowerShell (assuming you're in the directory containing the files:

    Code:
    $i = 1
    gci *.jpg | %{rename-item $_.Fullname ('abc_{0:d4}0.jpg' -f $i++) }
    Keith
    I got an error here. It's creating a 0 (zero) on the wrong side. For example 127.jpg turned into abc_01270.jpg...

    Not sure if that is intended.
      My ComputerSystem Spec


  6. Posts : 149
    Microsoft Windows 10 Home
       #6

    That's intentional --- it's what the OP asked for:

    - Picture of the "1" = "abc_00010"
    - Picture of the "2" = "abc_00020"
    - Picture of the "3" = "abc_00030"

    and
    in form "abc_X0"

    X being 0001, 0002, 0003, ... 0013, 0014, 0015, ... 0125, 0126, 0127 ... 1454, 1455, 1456

    He's want's to number by 10's. That's accomplished by the format string:
    'abc_{0:d4}0.jpg' where the literal elements 'abc_' and '0.jpg' are joined by the value of $i (0) formatted as a four-place integer with leading 0's.

    https://social.technet.microsoft.com...-operator.aspx

    If you want to increment the names by one, just edit the code to omit the '0' after the closing brace: 'abc_{0:d4}.jpg'

    Keith
      My ComputerSystem Spec

  7.    #7

    Hi Maxjprg..just read your thread..I use Rename 4u from Kelly Utilities and this program is no longer supported and i have managed to do a Google search and found this link... Rename4u 1.1 Download (Free) - Rename4u.exe
    I downloaded it and ran a security check and program is safe to run and kept the program myself as a backup.
    Rename 4u is a simple free program to use and i use this is ideal for my image batch rename files.

    Give the program a go..if it meets your requirements... if it does keep a backup of the program in case of re-installation.

    I have used it for over a year now with no problems at all.

    Bye.Have a nice weekend.
      My ComputerSystem Spec

  8.    #8

    @KeithM you are right. I wasn't paing close attention that's actually exactly what the Topic Creater wanted.

    I remembered antoher tool I have used in the past "Advanced Renamer" I think it is free but not sure.
      My ComputerSystem Spec


 

Related Threads
I have a problem with the batch rename feature in Windows 10. This is when you select multiple files, right click and select "rename" and then type in the new name into the first file's name field. This will make all selected files the name you...
Hi, I love whern Windows is very simple and fast, sometime I really don't need "plus" that slow me down working. One of them is when for example I would open a photo folder and open immediatly the most recent pictures. In very old windows this...
The Windows Photo Viewer will not display photos in the order they are sorted by Windows Explorer. This is not referring to the slide show feature, just the forward and back arrows. The only order pictures can be viewed is by name despite Windows...
Batch Rename Deletes Files in Performance & Maintenance
Hey all, I just upgraded to Windows 10 last night, and I've been playing around with the new File Explorer. One thing I tried was the batch rename function (by which I mean just selecting multiple files and clicking "rename"). I quickly realized...
Hi, I'm not new to Batch Files but i have a requirement that i can't seem to get my head around, I'm sure it must be simple'ish.. I have 2 .txt files (Locations.txt | Files.txt) Locations is a list of directories Files is a list of...
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd
All times are GMT -5. The time now is 07:38.
Find Us