simonetaddei Posted June 25, 2016 Posted June 25, 2016 hi, i need to do a massive rename using batch language, for example if i have a few file named: nomefile0001 nomefile0002 nomefile0004 nomefile0005 nomefile0008 nomefile0010 i need to rename the file like this: nomefile0001 nomefile0002 nomefile0003 nomefile0004 nomefile0005 nomefile0006 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? Simone
jaclaz Posted June 25, 2016 Posted June 25, 2016 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: http://www.bulkrenameutility.co.uk/Main_Intro.php 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.). jaclaz 2
gunsmokingman Posted June 28, 2016 Posted June 28, 2016 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 Code '-> 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 Fso.DeleteFile(i.Path),True Next '-> Build And Show The Report Set Ts = Fso.CreateTextFile("TestList.txt") Ts.WriteLine Now() Ts.WriteLine "Files Process : " & Az(C1) Ts.WriteLine t Ts.Close() Act.Run("TestList.txt"),1,True '-> 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 Fso.DeleteFile("TestList.txt"),True 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 Az=n End Function Rename TestListFiles.vbs.txt to TestListFiles.vbs to make active TestListFiles.vbs.txt Resuts TestList.txt
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now