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

How do I create a text file using the date?

Applications

How do I create a text file using the date?

by  tintin2000  Posted    (Edited  )
After searching through the group and a little tinkering, I came up with this that allows you to create a file with the date. The format is such as it will be easier to find in a folder later YYMMDD.

Hope this helps someone! Thanks to those who helped me.


' ********************************************
' * Script Name: FileandDate.vbs *
' * Author: TD 9343 *
' * Address: *
' * Created: 26/01/04 *
' ********************************************

' **** Perform script initialization here ****

Option Explicit

On Error Resume Next

Dim fsoObject, open_File, target_File, thisday
Set fsoObject = WScript.CreateObject("Scripting.FileSystemObject")

' ********* Main processing section **********

' ### call function to get the date ###
today_date()

' ### set the file name to include the variable from the process above
target_File = "C:\temp\vb\" & thisday & ".txt"


' ### open the file and put a header on the page ###
Open_My_File()

open_File.WriteLine "*******************************************"
open_File.WriteLine "* Daily Checks for: " & date & ". *"
open_File.WriteLine "* Run at: " & time & ". *"
open_File.WriteLine "* This file is named: " & thisday & ".txt *"
open_File.writeline "*******************************************"
open_File.WriteLine " "


Close_my_File()




' *********** Procedures go here *************
' ### This function opens a file ###

Function Open_My_File()

If (fsoObject.FileExists(target_File)) Then
Set open_File = fsoObject.OpenTextFile(target_File, 8)
Else
Set open_File = fsoObject.OpenTextFile(target_File, 2, "True")
End If

End Function
' ***************************************************************

' ***************************************************************
' ### This function closes a file ###

Function Close_My_File()

open_File.Close()

End Function
' ***************************************************************
' ***************************************************************
' ### This funtion gets the date in format yymmdd ###
Function Today_Date()

thisday=Right(Year(Date),2) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2)

End Function
' ***************************************************************
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top