+ Reply to Thread
Results 1 to 6 of 6

Rename all files in a folder

  1. #1
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Rename all files in a folder

    Hi everyone,

    I have a folder which contains all files exported from Dropbox. All these files have been named using the date when they are created. The names have the format as: YYYY-MM-DD HH.MM.SS. For example, 2023-05-31 15.29.51.

    I just want to rename them as: YYYY_MM_DD. If there are multiple files with the same date, then just make it as: YYYY_MM_DD (1), YYYY_MM_DD (2), ...

    Do you know how I can use a smart VBA code to automate this task?

  2. #2
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,032

    Re: Rename all files in a folder

    Does this work for you?

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this ...


    Quote Originally Posted by BNCOXUK View Post
    Do you know how I can use a smart VBA code to automate this task?
    A VBA demonstration for starters to fit for what you forgot / misexplained :

    PHP Code: 
    Sub Demo1()
      Const 
    "D:\Tests4Noobs\"
            F = Dir(P & "
    ????-??-?? ??.??.??*"):  If F = "" Then Exit Sub
        With CreateObject("
    Scripting.FileSystemObject")
        Do
            B = P & Left(F, 11) & "
    ("
            C = 0
            E = "
    )" & Mid(F, 20)
            Do:  C = C + 1:  N = B & C & E:  Loop While .FileExists(N)
            Name P & F As N
            F = Dir
        Loop Until F = ""
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  4. #4
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Re: Rename all files in a folder

    Hello ByteMarks, Marc, your codes work really perfectly. Thank you for sharing knowledge.

  5. #5
    Forum Contributor
    Join Date
    06-18-2012
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    347

    Re: Rename all files in a folder

    Hello ByteMarks and Marc,

    My apologies to come back. I have tried to apply the code to a folder which contains that date/time format. The question also needs to change hyphen - to underscore _

    Would it be possible to update the code to accommodate that task please? Thank you.

  6. #6
    Forum Expert
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    2,032

    Re: Rename all files in a folder

    Following on from Marc's code, maybe

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Loop through all files in a folder and rename the files considering a pattern
    By excelactuary in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-22-2022, 10:57 AM
  2. [SOLVED] Copy Folder then rename files in new folder from list in Excel
    By jimjones1958 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2021, 05:00 PM
  3. Rename .pdf files in a folder
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-11-2019, 01:11 AM
  4. Replies: 18
    Last Post: 11-27-2018, 05:25 AM
  5. rename files in folder
    By anilg0001 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2014, 08:22 AM
  6. rename files in a folder
    By Varun Nair in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2006, 05:05 AM
  7. [SOLVED] rename all files in a folder
    By DIBS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-05-2006, 02:50 AM

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