[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 416
  • Last Modified:

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

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
808TEC
Asked:
808TEC
  • 2
1 Solution
 
arweeksCommented:
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
 
arweeksCommented:
oops = line 6 should be

replaceString =  "SHEET (1)"
0
 
808TECAuthor Commented:
Thanks for the help.  Works great and I appreciate since this has just become a urgent need.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now