Ask a question Report

Renaming multiple files in a folder [Solved]

Hurricane_G 5Posts Wednesday January 30, 2013Registration date February 5, 2013 Last seen - Latest answer on Feb 5, 2013 12:55AM
Hi all,
I require a help herewith. Actually i require to develop a Batch Script for renaming following 4 files kept in a folder "C:\files"
Actual File:
1) ABC_XCV_2013-01-30-07-15-29.xls
2) ZXC_VBN_2013-01-30-06-18-28.xls
3) OLK_JHU_2013-01-30-02-22-33.pdf
4) NKI_SJS_2013-01-30-01-12-29.pdf
Required file after execution of Script:
1) ABC_XCV_2013-01-29.xls
2) ZXC_VBN_2013-01-29.xls
3) OLK_JHU_2013-01-29.pdf
4) NKI_SJS_2013-01-29.pdf
I sincerely request to pls support me in this development.
Thanks,
Mohit
Read more 
Answer
+0
moins plus
Hi Mohit,

Please check the below mentioned link and see if it helps:

http://en.kioskea.net/faq/2032-renaming-multiple-files-in-batch

The article in this link explains renaming multiple files in batch.

Kindly get back if there are any further queries.
Add comment
Answer
+0
moins plus
Thanks Zohaib... I have browsed thru the link and found the Ant Renamer 2 software very useful. However i still willing to get a small batch code to fulfill my requirement.

Also here too I am first deleting last 19 characters and then adding required 10 characters in files.

Altough I am deeply thankful to you for this help however pls support me for the required batch script.
Add comment
Answer
+0
moins plus
Hi Mohit,

I am glad to know that "Ant Renamer" helped you in fixing the issue to an extent. I will definitely try and look for the batch script. In case I find one, I will surely test it and post it here.

You can start following me on this forum, this will keep you updated if there are any updates regarding this from me.

Thanks & Regards
Zohaib R
#iworkfordell
Add comment
Answer
+0
moins plus
From the example that you gave, it seems to me that, your file has three parts. The first 8 characters are constant, then a date and then a time. You want to keep the constant part, take the date and make it one day earlier and drop the time part?. Is this the case ?
Add comment
Answer
+0
moins plus
Yes rizvisa1... u r rite in the understanding... only catch is that initial count is not fixed to 8... it could be variable length.....

However the ending date time stamp length will remain constant ie 20 (_2013-01-30-07-15-29) and yes i need to rename it to a date earlier and drop the time stamp.


KINDLY HELP!!!!!!
rizvisa1 4300Posts Thursday January 28, 2010Registration date ContributorStatus December 6, 2014 Last seen - Feb 3, 2013 05:46PM
Would a vb script work ?
Reply
Hurricane_G 5Posts Wednesday January 30, 2013Registration date February 5, 2013 Last seen - Feb 3, 2013 08:28PM
Yes ... it will work... i just need it to be done.... :)

Pls support!!!
Reply
rizvisa1 4300Posts Thursday January 28, 2010Registration date ContributorStatus December 6, 2014 Last seen - Feb 4, 2013 07:51AM
try this

Copy the code in a file and save with with extension VBS
Double click on file. It will ask for a file path, give it the full path where the files are
it will loop through all files in that folder and rename it as you wanted


Option Explicit 

'calls main method 
Call MainMethod() 

'this is main method 
Sub MainMethod() 
Dim filePath 
Dim FSO 
Dim FolderObject 
Dim fileObject 
Dim orgFileName 
Dim newFileName 
Dim periodPosition 

Dim fileNamePart 
Dim fileExtensionPart 
Dim fileDatePart 


    'Define file path. 
    filePath = InputBox("Enter full path to the folder/directory where files are") 
    If (Right(filePath, 1) <> "\") Then filePath = filePath & "\" 


    'Create the instance of the FSO. 
    Set FSO = CreateObject("Scripting.FileSystemObject") 
     
    'Set the folder you want to search. 
    Set FolderObject = FSO.GetFolder(filePath) 

    'Loop through each file in the folder. 
    For Each fileObject In FolderObject.Files 
     
        'Get complete file name with path. 
        orgFileName = fileObject.Path 
         
        'find position of last instance of . 
        periodPosition = InStrRev(orgFileName, ".") 
         
        'using the posion of last . , get the file extension 
        fileExtensionPart = Mid(orgFileName, periodPosition) 
         
        'get the none constant part of file including the extension 
        fileDatePart = Mid(orgFileName, periodPosition - 19) 
         
        'get the constant part of file 
        fileNamePart = Left(orgFileName, periodPosition - 19 - 1) 
         
        'get the date part of the file 
        fileDatePart = Left(fileDatePart, 10) 
         
        'shift back date by a day 
        fileDatePart = formatDate(CDate(fileDatePart) - 1) 
         
        'Build the new file name. 
        newFileName = fileNamePart & fileDatePart & fileExtensionPart 
         

        'Use the MoveFile method to rename the file. 
        FSO.MoveFile orgFileName, newFileName 
    Next 

    'Cleanup the objects. 
    Set FolderObject = Nothing 
    Set FSO = Nothing 

End Sub 

Function formatDate(rawDate) 
Dim newDate 

    newDate = Year(rawDate) 
    newDate = newDate & "-" 
    newDate = newDate & Right("0" & Month(rawDate), 2) 
    newDate = newDate & "-" 
    newDate = newDate & Right("0" & Day(rawDate), 2) 

    formatDate = newDate 
End Function 

Reply
Hurricane_G 5Posts Wednesday January 30, 2013Registration date February 5, 2013 Last seen - Feb 5, 2013 12:55AM
simply WOW.... Thanks a lot... and this is working perfectly fine for me.


May Godbless u!!!
:)
Reply
Add comment
This document entitled « Renaming multiple files in a folder » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.

Not a member yet?

sign-up, it takes less than a minute and it's free!

Members get more answers than anonymous users.

Being a member gives you detailed monitoring of your requests.

Being a member gives you additional options.