Jump to content

massive and ordered rename using batch

Recommended Posts

hi, i need to do a massive rename using batch language, for example if i have a few file named:


i need to rename the file like this:


i try to copy filename in a text document, then elaborate text document and rename the file using the name in text document.

dir /B > fileList.txt

I don't know how to elaborate the names in the fileList.txt

someone can help me?


Link to comment
Share on other sites

If you have a few files, it is not "massive".

If it is "massive" then probably batch is going to be too slow for the activity.

There are several dedicated tools.

Usually they would be better and easier:


There is also a command line version that you can use from batch.

In "pure" batch it will depend on the specific naming scheme (current) and specific naming scheme (after processing), that would be, in the case you provided (which I doubt is actually the way you have files named) a simple for loop to separate the "main" name from the suffix, then recreate an incremental suffix and possibly add the extension that you omitted in your sample.

There are (there will be) any kind of complication, as soon as someone will post a small batch doing exactly what you asked, you will try using on your actual data and it won't work (because you didn't describe accurately enough the data, because of file/directory permissions, because of non ASCII filenames, etc.).




Link to comment
Share on other sites

Here is a VBS script that meant to be run from your Desktop to a Folder and list it Contents. It then rename the file to a 4 digit number, it also produces a text file with the changes made. 

1:\ Change This For Each i In Fso.GetFolder("D:\UsbMp3").Files, to the path of the folder

2:\ This script only is meant to be used with file that have only 3 characters and a period any less or more will cause an error


'-> Object For Runtime
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Run Time Varibles
Dim C1, i, j, t, Ts 
'->Loop Threw The File In The Folder Listed Below 
  For Each i In Fso.GetFolder("D:\UsbMp3").Files
'-> Count The Files
   C1 = C1 + 1
'-> Get The Period And File Charaters EG .com, .txt, .vbs
   j = Right(i.Name,4)
'-> For The Text Report List The New File Name With The Old File Name
    t = t & Az(C1) & j & " = " & i.Name & vbCrLf
'-> Copy Old Name To the New Name = Az(C1) & j
    Fso.CopyFile i.Path,Replace(i.path,i.name,Az(C1) & j),True
'-> Delete The Old File
'-> Build And Show The Report
   Set Ts = Fso.CreateTextFile("TestList.txt")
   Ts.WriteLine Now()
   Ts.WriteLine "Files Process : " & Az(C1)
   Ts.WriteLine t
'-> Ask To Keep It Or Delete It   
  If MsgBox("Yes To Keep TestList.txt Or No To Delete TestList.txt", _
  4132,"Keep Or Delete") = 7 Then
  End If  
'-> Funtion To Add Zero To The Number
   Function Az(n) 
   Dim z 
    If Len(n)= 1 Then n = "000" & n
    If Len(n)= 2 Then n = "00" & n
    If Len(n)= 3 Then n = "0" & n
   End Function



Rename TestListFiles.vbs.txt to TestListFiles.vbs to make active TestListFiles.vbs.txt

Resuts TestList.txt

Link to comment
Share on other sites

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...