Solved

Looking for a batch file to rename files to remove "Sheet (1) from each filename

Posted on 2010-09-20
3
409 Views
Last Modified: 2012-05-10
When printing from autocad to PDF Creator it will add a suffix to the file name before the extesion to indicate which layout printed.  

Example M01 FLOOR PLAN FIRST FLOOR GRID A SHEET (1).pdf.

I am trying to remove the "SHEET (1)" without having to rename each file manually.

thanks for your help
0
Comment
Question by:808TEC
  • 2
3 Comments
 
LVL 3

Expert Comment

by:arweeks
ID: 33722247
Are you happy with vbscript instead of batch?  It's a little neater for something like this.  You need to take the below code, and put it in a text file called rename.vbs.  If you prefer to run from a batch file, create a batch file that has the path to rename.vbs using the syntax
@echo off
cscript "c:\myscripts\rename.vbs"

or something like that.  
Obviously, you will need to edit the two variables below - one for the rootFolder (Where the documents are stored) and the other with the string you want to remove.  I've left this as "SHEET (1)"

Let me know if I can help further.  Also, it's case sensitive, but  that is easily resolved if you want.

option explicit
dim rootfolder, fso, oFol, f, replaceString
' change these two, as you need to

rootFolder = "C:\Users\arweeks\Desktop"
replaceString = 

' ----   no need to change below here unless you have a reason to -----

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFol = fso.GetFolder(rootFolder)

for each f in oFol.files
	if instr(f.name,replaceString) then
		fso.MoveFile rootFolder & "\" & f.name, rootFolder & "\" & replace(f.name,replaceString,"")
	end if
next

Open in new window

0
 
LVL 3

Accepted Solution

by:
arweeks earned 500 total points
ID: 33722253
oops = line 6 should be

replaceString =  "SHEET (1)"
0
 

Author Closing Comment

by:808TEC
ID: 33728241
Thanks for the help.  Works great and I appreciate since this has just become a urgent need.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

776 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