How to batch rename multiple files while keeping the sorting order


  1. Posts : 6
    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 Computer


  2. Posts : 2,916
    Windows 10 Pro for the Bro
       #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.

    How to batch rename multiple files while keeping the sorting order-image.png
      My Computer


  3. Posts : 456
    Windows 10
       #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 Computer


  4. Posts : 989
    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 Computer


  5. Posts : 456
    Windows 10
       #5

    KeithM said:
    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 Computer


  6. Posts : 989
    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 Computer


  7. Posts : 217
    windows 8.1 pro
       #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 Computer


  8. Posts : 456
    Windows 10
       #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 Computer


 

  Related Discussions
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 14:04.
Find Us




Windows 10 Forums