+ Reply to Thread
Results 1 to 28 of 28

Find files(.jpg and .png) with same names and rename them all sequentially

  1. #1
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Find files(.jpg and .png) with same names and rename them all sequentially

    Hey Guys,

    Though this is my First post in the Forum, I have been costantly following up many threads for a while...........And need ur help now

    I have a directory where users name 2 files (one with .jpg ext and other with .png extension)with same names...................

    I need to identify files (.jpg and .png) with same names and rename all as sequential names.............

    Assume there are files Test1.jpg, Test1.png and Test 2.jpg and Tet2.png..................After running the Macro..........test1 should be replaced as 1..............that is 1.jpg and 1.png...............And Test2 as 2................That is 2.jpg and 2.png...............Only the names should be renamed seq and there should be no change in their file extensions................

    Can someone please help me on the same.....................
    Last edited by selva2k25; 07-08-2011 at 02:42 AM. Reason: error in post

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello selva2k25,

    Welcome to the Forum!

    When parsing text it is important that the example be true to the actual text.
    1. Will the sequence number always be at the end of the file name?
    2. Will there ever be other numbers present in the file name?
    3. Can you post several examples of actual file names?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Leith thanks for your quick response.......................

    As I said the file name can be anything initially..............Care is only taken to see if the .jpg file and its associated .png file are named with same file names..................

    After running the macro...............The macro needs to find .jpg files and .png files with same names and should start renaming them as 1.jpg, 1.png, 2.jpg, 2.png, 3.jpg, 3.png and so on......................

    Sorry if this is not what you asked, kindly revert for any more response from my end..............

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello selva2k25,

    Say you have the following file names "SKU501442.jpg" and "SKU501442.png". Would the new file names be " 501442.jpg" and "501442.png"?

    Another case might be "Loc 14A-1.jpg" and "Loc 14A-1.png". Would the new file names be "1.jpg" and "1.png"?

  5. #5
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Leith, it does not matter what the files are named initially it can be any names................However there are 2 file extensions (.jpg and .png) with same names....................................

    For example if the files are loc.jpg and loc.png and walter.jpg and walter.png...............................

    After running the macro they should be named as 1.jpg and 1.png and 2.jpg and 2.png respectively.........................

    Hope, the condotion is clear now...................Sorry if I had confused you.............................

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello selva2k25,

    As I understand the process, you want to separate all the .jpg and .png files in directory, match them by title, and then assign the files a sequential number starting with 1. Is that correct?

  7. #7
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Yes Leith.....................And please note that all .jpg and .png files are in same folder and after renaming also will be in the same folder too..................So there is no need for any changing of their directories in this case..............................

    And also care should be taken that after renaming..................files initially with same names are renamed with same names too...........................For example Loc.jpg and Loc.png are renamed as 1.jpg and 1.png

    Hope am kinda clear now...........................

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello selva2k25,

    This macro has not been fully tested. It should do want you want in renaming the files with a serial number in the same directory.
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Leith, am checking the same and will reply you at the earliest...................Thanks a lot for your prompt reply......................

  10. #10
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Leith, I get the below error : [After changing the Appropriate directory under path]

    "Object Variable or with block variable not set"

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello sleva2k25,

    Change the Dim statement below.
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Done, Leith..........................Now the error does not occur and the code runs..................But the files have not got renamed....................Still reflecting old file names....................

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello selva2K25,

    I fixed a couple problems with the code. This version should work. Change the Path to what you are using before you run it.
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Sorry Leith....................
    The code runs here too....................But no change in the filenames..............

  15. #15
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    or

    Please Login or Register  to view this content.
    Adapt the path 'E:\OF\' into the desired foldername.



  16. #16
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello sleva2K25,

    It is probably because the path is not the working directory. Change the last For...Next loop.
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Leith, sorry still does not rename.................

    This was the updated code, for your referance...............

    Please Login or Register  to view this content.

  18. #18
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello selva2K25,

    Okay, I have tested this version and it works. I change the working directory to the specified path. Use this version since it works.
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Sorry Leith....................The same does not work for me..................Please check the below code

    Please Login or Register  to view this content.

  20. #20
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Hello sleva2k25,

    It worked fine on my test folder using Excel 2003. Without error messages or some other usable information, I am unable to help to you further on this problem.

  21. #21
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Quote Originally Posted by Leith Ross View Post
    Hello sleva2k25,

    It worked fine on my test folder using Excel 2003. Without error messages or some other usable information, I am unable to help to you further on this problem.
    Thank you for your help Leith.................

    But Will there be any problem when it is runs on Excel 2007 Leith....................Can you please confirm the same...................

  22. #22
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Quote Originally Posted by snb View Post
    or

    Please Login or Register  to view this content.
    Adapt the path 'E:\OF\' into the desired foldername.

    SNB, Your code works good.......................However only 1 file got renamed and not the rest................And moreover i want them to be renamed from 0 to N.

    Can you please help me on the same.

  23. #23
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Please do not quote whole posts:

    You must have adapted the code to run it on your system. Please post that code her.
    I you get a error message in any line , use F8 to indicate in which line.
    The more precise your feedback, the more precise the answer you will get.
    Take care there's no file '1.jpg' or '1.png' in your folder.

  24. #24
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    SNB,

    There was no error when your code was run.......................However only one file (one jpg and its png) got renamed as 1.jpg and 1.png........................Rest were unharmed

    Please find my code below,

    Please Login or Register  to view this content.

  25. #25
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    You need to add a backslash ( like in the code I provided):

    c00 = "D:\BirthdayMailers\"

  26. #26
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    When I do that and when I run the Macro I get the below error :

    Run - time error '58' :

    File Already Exists

  27. #27
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Did you rename before running the code the 2 files that had been renamed earlier in 1.jpg and 1.png ?

  28. #28
    Registered User
    Join Date
    06-06-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Find files(.jpg and .png) with same names and rename them all sequentially

    Yup all that is done.....................

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1