• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Renaming a file names in folder.

nmkhan3010

New Member
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”

My objective was to delete “_Translated.docx” from a folder (In a folder having more than 100 Doc's)
 

Attachments

  • Tags (Soure name).JPG
    Tags (Soure name).JPG
    53.8 KB · Views: 12
  • Tags (Target name).JPG
    Tags (Target name).JPG
    54.2 KB · Views: 8
See a tool to rename files
The sub List prepare the list of the file in the active folder
In the user sheet in the file attached yoiu have to the new name infro,t of the old one
Take care that there is formulas to care of your personal need =LEFT(C4,FIND("_",C4)-1) & ".docx"
Code:
Option Explicit
Sub List()
Dim OLD  As Range
Dim I As Integer
Dim WkPath As String
Dim ActF As String
Dim FileAr
Dim F

Dim FSO
    WkPath = ActiveWorkbook.Path
    ActF = ActiveWorkbook.Name
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set FileAr = FSO.Getfolder(WkPath).Files

    Set OLD = Range("OLD")
    Range([OLD](2), Cells(Rows.Count, OLD.Column).End(3)(2, 2)).ClearContents

    For Each F In FileAr
        If Not (F.Name Like "*" & ActF & "*") Then
            I = I + 1
            [OLD](1 + I) = F.Name
        End If
    Next F
End Sub


Sub Rename()
Dim OLD  As Range
Dim I As Integer
Dim WkPath As String
Dim WkRg  As Range, Rg  As Range

Dim FSO
    WkPath = ActiveWorkbook.Path
    Set FSO = CreateObject("Scripting.FileSystemObject")

    Set OLD = Range("OLD")
    Set WkRg = Range([OLD](2), Cells(Rows.Count, OLD.Column).End(3))
    For Each Rg In WkRg
        If (Rg(1, 2) <> "") Then _
            FSO.GetFile(WkPath & "\" & Rg).Name = Rg(1, 2)
    Next Rg
    MsgBox ("Job Done")
End Sub
 

Attachments

  • Rename files.xlsm
    22.1 KB · Views: 19
Back
Top