Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with scriipt or Dos bat file 2

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I want to move a file that has the same name every week but have the new file renamed with date added to file name when moved
File name is backup.bkf on c: drive and new files name would be backup041007.bkf if it happened today.

using robocopy on Windows Server 2003
Example
robocopy c:\ d:\ *.bkf ?????

any help appreciated


DougP, MCP, A+
 
Maybe like this...

Code:
Option Explicit
'On Error Resume Next

Dim srcFile : srcFile = "c:\temp\backup.bkf"
Dim dstFile : dstFile = "d:\temp\backup" & GetDate & ".bkf"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile srcFile, dstFile

Function GetDate
	Dim arrTemp : arrTemp = Split(Date, "/")
	Dim i, strTemp, strOutput
	For i = 0 To UBound(arrTemp)
		strTemp = arrTemp(i)
		If Len(strTemp) = 1 Then
			strOutput = strOutput & "0" & strTemp
		ElseIf Len(strTemp) = 4 Then
			strOutput = strOutput & Mid(strTemp, 3)
		Else
			strOutput = strOutput & strTemp
		End If
	Next
	GetDate = strOutput
End Function

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
If you want a DOS batch
Code:
set dd=%date:~4,2%
set mm=%date:~7,2%
set yy=%date:~10,4%
ren backup.bkf backup%dd%%mm%%yy%.bkf
robocopy ...
Type set /? for more info on set. It is more versatile than the one on DOS6..Win98
 
Oops: just realized you have US date format and I have done it in UK format. Maybe you have to check what %DATE% gives you before using the DOS version.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top