Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

universal change filename

Posted on 2011-09-21
4
Medium Priority
?
334 Views
Last Modified: 2012-05-12
Hi,

I have 500 pdf, the filename has bunch of "_", some are 9, some have 10.

is there a way to trim 7th "_" and after for all files?  thx
0
Comment
Question by:mcrmg
  • 2
  • 2
4 Comments
 

Author Comment

by:mcrmg
ID: 36576780
actually, not the 7th one, should be second one from the right...possible?  thx
0
 
LVL 11

Expert Comment

by:X_layer
ID: 36576818
Can you post one filename for example.
0
 

Author Comment

by:mcrmg
ID: 36576899
sure


file_123456_dco1_doc_abc_aa_20110919_ABC123456_987_20110919_130000.pdf


to


file_123456_dco1_doc_abc_aa_20110919_ABC123456_987.pdf
0
 
LVL 11

Accepted Solution

by:
X_layer earned 1000 total points
ID: 36576985
Try this, but please put only few files into c:\temp folder to try script.
Dim fso, sfolder, folder, files, tempfilename, newfilename

Set fso = CreateObject("Scripting.FileSystemObject")
sfolder = "C:\Temp"
Set folder = fso.GetFolder(sfolder)
Set files = folder.Files
  
For each folderIdx In files
	tempfilename = Left(folderIdx.Name, Len(folderIdx.Name) - (Len(folderIdx.Name) - (InStrRev(folderIdx.Name, "_"))) - 1)
	newfilename = Left(tempfilename, Len(tempfilename) - (Len(tempfilename) - (InStrRev(tempfilename, "_"))) - 1)
	fso.MoveFile sfolder & "\" & folderIdx.Name, sfolder & "\" & newfilename & ".pdf"
Next

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question