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

Append Current Date to file name

Status
Not open for further replies.

CrystalVis

Technical User
Jun 26, 2002
200
US
Is there a way to automate so that the system automatically append the current date to the file name. For example, I have an Excel file, before the server email the file to the user, I would like to add the current date to the filename. Any help/suggestion is greatly appreciated.
TIA
 
CrystalVis

Rename files using the FileSystemObject

If it is not a preset set of files. What I mean is the same filenames every time, then you will need to look at more of the functions associated with the Filesystemobject.

With it you can use the filesystemobject files collection to identify each file. With it, it has the ability to break each filename down to the name and the extension.

With that you can use the VBScripts date time functions to create the string you want to append to each file, and then rename the file for processing via your email.

If your looking to accomplish this for a number of filles then your looking at looping, again available via VBScript.

Hope this helps.
DougCranston
 
DougCranston,

Thank you for your respond. I look at the link and not sure where to add the code to my existing code. I'm not a VB programmer. This is what I have in the ActiveX task to send the email and the file to the user:

Option Explicit
'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()

Dim objNewMail

Set objNewMail = CreateObject("CDONTS.NewMail")

Call objNewMail.AttachFile("\\Tfl\Users\Shared\Letters\Counts.xls", "Daily Counts.xls")

objNewMail.Send "jdoe@nextel.com", "jdoe@nextel.com;jsmith@nextel.com", "Letter Counts ", " Attached is the daily counts output file."

Set objNewMail = Nothing

Main = DTSTaskExecResult_Success

End Function

the Counts.xls will be in the directory everyday. I just need to make it Counts0505.xls

how do I incorporate these line of codes make it works?

<%
Dim fso
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
fso.MoveFile &quot;d:dummytest.txt&quot;, &quot;d:dummytest2.txt&quot;
%>

Thanks for anything you can offer.
 
CrystalVis,

I noticed you were referencing the file locations as what appeared to be UNC.

The following should work in that environment, but have used this as mapped drive locations via TCP/IP. Only suggest you try it and see with your addressing and see if it functions for you.


Option Explicit
'*********************************************************
' Visual Basic ActiveX Script
'*********************************************************

Function Main()
Dim objNewMail
Set objNewMail = CreateObject(&quot;CDONTS.NewMail&quot;)
objNewMail.AttachFile(&quot;\\Tfl\Users\Shared\Letters\Counts.xls&quot;, &quot;Daily Counts.xls&quot;)
objNewMail.Send &quot;jdoe@nextel.com&quot;, &quot;jdoe@nextel.com;jsmith@nextel.com&quot;, &quot;Letter Counts &quot;, &quot;Attached is the daily counts output file.&quot;
Set objNewMail = Nothing
Main = DTSTaskExecResult_Success

Dim dy
Dim mo
Dim counts
dim dailycounts

dy = day(now)
mo = month(now)

counts = &quot;Counts&quot; & mo & dy & &quot;.xls&quot;
dailycounts = &quot;Counts Daily&quot; & mo & dy & &quot;.xls&quot;

Dim objFSO
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
objFSO.MoveFile &quot;C:\FSO\counts.xls&quot; ,&quot;C:\FSO\&quot; & counts
objFSO.MoveFile &quot;C:\FSO\counts.xls&quot; ,&quot;C:\FSO\&quot; & dailycounts

End Function

More info on FSO see Check out the sidebar.

Hope this Helps.
DougCranston
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top