Solved

universal change filename

Posted on 2011-09-21
4
302 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 250 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

816 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now