Solved

Dos batch script to rename a file

Posted on 2011-02-23
4
599 Views
Last Modified: 2012-06-27
I am new to scripting and I need a solution to rename the following files.
We receive files from our vendors that look something like the ones listed
below.
PO_ordern1_20110223.txt
Emp_dir1_20110223.tx

I want to prepend "bcgsndr" to each of these files name.  For example,
bcgsndr_PO_ordern1_20110223.txt
bcgsndr_Emp_dir1_20110223.txt

How can I do this with a script.

Thanks
0
Comment
Question by:SyFy
4 Comments
 
LVL 12

Accepted Solution

by:
Amick earned 250 total points
ID: 34967323
for %i in (dir *.txt) do ren %i bcbg_%i
0
 
LVL 8

Expert Comment

by:jimsweb
ID: 34967325
Try thsi one:

@echo off 
ren ???????????????????.txt  bcgsndr???????????????????.txt
ren ?????????????????.txt  bcgsndr?????????????????.txt

Open in new window


Hope this also is helful to you:
http://en.kioskea.net/faq/6533-bat-command-to-insert-a-char-in-a-file-name
0
 
LVL 6

Assisted Solution

by:dax_bad
dax_bad earned 250 total points
ID: 34968150
In case you prefer using vbscript, this should do the trick

Change the path & save the snippet as .vbs
path = "" 'ie. C:\Temp:\FTP 
pattern1 = "PO_" 'first pattern to look for in a file
pattern2 = "Emp_" 'Second pattern to look for in a file
addString = "bcgsndr_"

Set objFS = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFS.GetFolder(path)

Set objRE1 = new RegExp
Set objRE2 = new RegExp
objRE1.Pattern = pattern1
objRE2.Pattern = pattern2
objRE1.IgnoreCase = True
objRE2.IgnoreCase = True

For Each objFile In objFolder.Files
	If objRE1.Test(objFile.Name) Then
   			objFile.Name = addString + objFile.Name
   	Else 
		If objRE2.Test(objFile.Name) Then
    			objFile.Name = addString + objFile.Name
   		End If
	End If
Next

Open in new window

0
 

Author Closing Comment

by:SyFy
ID: 34970231
Thanks Guys !
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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

785 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