Go Premium for a chance to win a PS4. Enter to Win

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

Dos batch script to rename a file

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
SyFy
Asked:
SyFy
2 Solutions
 
AmickCommented:
for %i in (dir *.txt) do ren %i bcbg_%i
0
 
jimswebCommented:
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
 
dax_badCommented:
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
 
SyFyAuthor Commented:
Thanks Guys !
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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