INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Applications

How do I create a text file using the date? by tintin2000
Posted: 27 Jan 04 (Edited 27 Jan 04)

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
' ***************************************************************

Back to VBScript FAQ Index
Back to VBScript Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close