dcsimg
Results 1 to 4 of 4

Thread: [RESOLVED] Rename files in folder

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    6

    Resolved [RESOLVED] Rename files in folder

    Hi all!
    Please forgive me if this is not the correct room to ask this question. I am VERY new to VB and I searched for what I thought was the right room to ask this question. If not please direct me to the correct area. Thx!

    I am trying to rename about 1100 files in a folder with a vb script. The names of the files have 14 characters long plus the file extension of .jpg. I need to extract the 7th-11th characters (skip 12th) and include the 13th & 14th plus file extension. Example 064383010056_A.jpg needs to end up as 01005_A.jpg.

    I found a script to remove the leading 6 characters but I'm having trouble removing the 12th and putting the two together to get my desired result. Could someone help me out? I've been searching the web for the last 7 hours trying to fix this myself.

    Thank you for the help!!!

    Code:
    folderspec = "C:\Temp\Test\"
    strRename = ""
    
    Set fs = CreateObject("Scripting.FileSystemObject")
    set f = fs.GetFolder(folderspec)
    
    for each f1 in f.files
    	Filename = folderspec & f1.name
    	NewFilename = replace(Filename, "064383", strRename)
    	fs.MoveFile Filename, NewFilename
    next
    
    msgbox "Done"

  2. #2
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    1,006

    Re: Rename files in folder

    Strike 2 on posting in the right forum btw, but that's ok I've asked it to be moved to the VBScript forum.

    Assuming that all the files exactly follow the format you've described above, then this line of code should properly take the original filename and produce the new correct filename:

    Code:
    NewFilename =  folderspec & mid(f1.name, 7, 5) & right(f1.name, 6)

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2020
    Posts
    6

    Re: Rename files in folder

    OptionBase1, I am so embarrassed, but I REALLY appreciate your help. That worked perfectly!!! THANK YOU THANK YOU!!!

  4. #4
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    7,406

    Re: Rename files in folder

    Never mind

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width