Solved

universal change filename

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 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