+ Reply to Thread
Results 1 to 3 of 3

rename files in a folder with foldername

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-06-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    193

    rename files in a folder with foldername

    when i select a folder then i need to change all the .jpg files in a particular criteria
    eg;
    path=E:/Myfolder/KL21B/
    file names are
    2sdfs35.jpg
    1.jpg
    sder3.jpg
    35sder4.jpg

    for these file rename as

    KL21B-A = 1.jpg
    KL21B-B = 2sdfs35.jpg
    KL21B-C = sder3.jpg
    KL21B-D = 35sder4.jpg

    continue sequencies(A,B,C,D,E,F,G,H.......)

    rememberable thing is 1.jpg must be the first picture (KL21B-A).

    can i create a macro for that??

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: rename files in a folder with foldername

    How are you sorting the pictures? why is sder3 between 2sdfs35 and 35sder4?

  3. #3
    Forum Contributor
    Join Date
    04-06-2013
    Location
    india
    MS-Off Ver
    Excel 2007
    Posts
    193

    Re: rename files in a folder with foldername

    Thank you Mr.Yudlugar

    i did not sort the file names if need we can sort but the 1.jpg must be (Foldername)-A picture

    but we should be care if a image having the name 0E53S (starting from zero).
    currently i am using this code

    Also when we extract file name to excel it will be as assending order.

    i am not a programmer so if any change pls inform
    Sub FileRename()
    
    Dim MyFolder As String
    Dim MyFile As String
    Dim FolderName As String
    Dim j As Integer
    Dim i As Integer
    Dim acount
    acount = Range("A" & Rows.Count).End(xlUp).Row
    Columns("A:B") = ""
    Range("A1").Select
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .Show
        MyFolder = .SelectedItems(1)
    End With
    MyFile = Dir(MyFolder & "\*.*")
    Do While MyFile <> ""
        j = j + 1
        Cells(j, 1).Value = MyFile
        MyFile = Dir
    Loop
    
    'Range("C1").Value = Split(MyFolder, "\")(UBound(Split(MyFolder, "\")))
    FolderName = Split(MyFolder, "\")(UBound(Split(MyFolder, "\")))
    
    If Range("A1").Value <> "" Then
    Range("B1").Value = FolderName & "-A.jpg"
    End If
    If Range("A2").Value <> "" Then
    Range("B2").Value = FolderName & "-B.jpg"
    End If
    If Range("A3").Value <> "" Then
    Range("B3").Value = FolderName & "-C.jpg"
    End If
    If Range("A4").Value <> "" Then
    Range("B4").Value = FolderName & "-D.jpg"
    End If
    If Range("A5").Value <> "" Then
    Range("B5").Value = FolderName & "-E.jpg"
    End If
    If Range("A6").Value <> "" Then
    Range("B6").Value = FolderName & "-F.jpg"
    End If
    If Range("A7").Value <> "" Then
    Range("B7").Value = FolderName & "-G.jpg"
    End If
    If Range("A8").Value <> "" Then
    Range("B8").Value = FolderName & "-H.jpg"
    End If
    If Range("A9").Value <> "" Then
    Range("B9").Value = FolderName & "-I.jpg"
    End If
    If Range("A10").Value <> "" Then
    Range("B10").Value = FolderName & "-J.jpg"
    End If
    If Range("A11").Value <> "" Then
    Range("B11").Value = FolderName & "-K.jpg"
    End If
    If Range("A12").Value <> "" Then
    Range("B12").Value = FolderName & "-L.jpg"
    End If
    If Range("A13").Value <> "" Then
    Range("B13").Value = FolderName & "-M.jpg"
    End If
    If Range("A14").Value <> "" Then
    Range("B14").Value = FolderName & "-N.jpg"
    End If
    If Range("A15").Value <> "" Then
    Range("B15").Value = FolderName & "-O.jpg"
    End If
    If Range("A16").Value <> "" Then
    Range("B16").Value = FolderName & "-P.jpg"
    End If
    If Range("A17").Value <> "" Then
    Range("B17").Value = FolderName & "-Q.jpg"
    End If
    If Range("A18").Value <> "" Then
    Range("B18").Value = FolderName & "-R.jpg"
    End If
    If Range("A19").Value <> "" Then
    Range("B19").Value = FolderName & "-S.jpg"
    End If
    If Range("A20").Value <> "" Then
    Range("B20").Value = FolderName & "-T.jpg"
    End If
    If Range("A21").Value <> "" Then
    Range("B21").Value = FolderName & "-U.jpg"
    End If
    If Range("A22").Value <> "" Then
    Range("B22").Value = FolderName & "-V.jpg"
    End If
    If Range("A23").Value <> "" Then
    Range("B23").Value = FolderName & "-W.jpg"
    End If
    If Range("A24").Value <> "" Then
    Range("B24").Value = FolderName & "-X.jpg"
    End If
    If Range("A25").Value <> "" Then
    Range("B25").Value = FolderName & "-Y.jpg"
    End If
    If Range("A26").Value <> "" Then
    Range("B26").Value = FolderName & "-Z.jpg"
    End If
    For i = 1 To Range("A1").End(xlDown).Row
    oldfilename = Cells(i, 1).Value
    newfilename = Cells(i, 2).Value
    If Not Dir(oldfilename) = “” Then Name oldfilename As newfilename
    Next
    End Sub

+ 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. Rename .pdf files in a folder
    By vijanand1279 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-11-2019, 01:11 AM
  2. [SOLVED] Rename Files in A folder
    By pradeepjassal in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-12-2012, 10:36 AM
  3. [SOLVED] rename files in a folder
    By Varun Nair in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-18-2006, 08:25 AM
  4. [SOLVED] rename files in a folder
    By Varun Nair in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-18-2006, 05:05 AM
  5. [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