universal change filename

Posted on 2011-09-21
Medium Priority
Last Modified: 2012-05-12

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
Question by:mcrmg
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Author Comment

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

Expert Comment

ID: 36576818
Can you post one filename for example.

Author Comment

ID: 36576899



LVL 11

Accepted Solution

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"

Open in new window


Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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