Renaming a file names in folder.

  • Am having more than 100 documents in folder.


    Actual name is “16603411-FinancialTables_Translated.docx” it should be rename as

    “16603411-FinancialTables.docx” just elimination “_Translated.docx” in every file in a folder. Please help me in this regards.


    Please find the attachment for better understanding.


    First 8 Digits are fixed for every file name and that number are amend with “_Translated.docx”

  • Try on a copy of your folder with files first.

    Code
    Sub Maybe()
    Dim c As Range
    For Each c In Range("A2:A" & Cells(Rows.Count, 1).End(xlUp).Row)    '<----- Assumes data starts in A2
    If InStr(c.Value, "_Translated") <> 0 Then c.Value = Left(c, Len(c) - 16) & ".docx"
    Next c
    End Sub
  • And another possibility.

    Which one is the best depends on if there is a possibility of mistakes/differences in the naming of the files.

    I guess you can always keep them in your library for future use.

    Code
    Sub Maybe_C()
    Dim c As Range
    For Each c In Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row)
    If InStr(c.Value, "_") <> 0 Then c.Value = Left(c, InStrRev(c.Value, "_") - 1) & ".docx"
    Next c
    End Sub
  • I want to rename a files as a batch, its not working, can you please review once.....


    I've used this in the past, it uses 2 macros one to fetch names, the other to rename. Change the folder location and filetype as necessary. Run the first one, it will get your file names, return them to column A, make a copy in Column B, and search/replace _Translated.docx with nothing"". Run the second one it will rename your files. You might want to run a couple tests firsts on some sample files and folders.



    Please review once and update and thank you so much for replying.......:)

  • Change references like Folder names and paths where required.

    The original files to be moved are in Column A, starting at Row 2.

    The nenamed files are in Column B with the original and new name in the same Row.

    Code
    Sub Maybe()
    Dim strPath_Old As String
    Dim strPath_New As String
    Dim i As Long
    strPath_Old = "C:\Temp"    '<---- Folder where the files to be renamed are in
    strPath_New = "C:\Temp\Temp"    '<---- Folder where the files are to be moved into
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    Name strPath_Old & "\" & Cells(i, 1) As strPath_New & "\" & Cells(i, 1).Offset(, 1).Value
    Next i
    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!