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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming and adding a date to a file 1

Status
Not open for further replies.

darren77uk

IS-IT--Management
Apr 23, 2001
78
0
0
CA
Can anyone tell me how I can write a basic script to take a specific file on a daily basis, copy rename it as something else with a datestamp?

Would appreciate that.

Cheers.
 
'==========================================================================
'
' VBScript Source File --
'
' NAME: CopyShutDownExe.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL : ' DATE : 11/13/2002
'
' COMMENT: This script will copy a file from one location to another.
'
'==========================================================================

Set fso = CreateObject("Scripting.FileSystemObject")

If Not fso.FileExists("c:\test2.txt") Then
fso.CopyFile "c:\test.txt", "c:\test2.txt",True
End If
 
Hello darren77uk,

File's property such path, name, datecreated, datelastmodified, datelastaccessed are either in string or in date-time format. You convert dt format to string and concatinate to the original filename. Only point you have to be careful is to avoid "/" often but not necessarily universally appeared in the dt format. So, if it is there, replace it by something legal for the filesystem.
Code:
const src_Folder="d:\test\"
const trgt_Folder="d:\test\"
const src_Filename="abc.txt"
const separator="-"

dtData=date	'or whatever you have in mind e.g. #mm/dd/yyyy# highly localized data
'dtData=#2/13/2004#
stmpDate=cstr(dtData)
'wscript.echo stmpDate
stmpDate=replace(stmpDate,"/",separator) & separator
'wscript.echo stmpDate

set fso=createobject("scripting.filesystemobject")
fso.copyfile srcFolder & src_Filename, trgt_Folder & stmpDate & src_Filename
set fso=nothing
regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top