Solved

Dos batch script to rename a file

Posted on 2011-02-23
4
595 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now