0

I tried to make a script to generate log files with the characteristics as follow: "test_date_time.log" my script is like this:

Set objfso = createobject("scripting.filesystemobject")

informacion = " " & DATE & " " & TIME & " "

Set archivoog = objfso.createtextfile("C:\Users\gdlabrui\Desktop\Pick_folder\programs\vbs\ex1 searchAstringAndCopyingOnTxt\" & informacion & ".log",true)

but it appears an error but i dont know how to follow.

Update: Error: Bad file name or number

Code: 800A0034

Source: Microsoft VBScript runtime error.

1
  • 1
    What error are you getting? please update your question with the stack trace
    – Bill F
    Apr 20, 2018 at 22:50

1 Answer 1

1

Using the automatic conversion of DATE and TIME to string is not recommended because the format is only defined by your current regional settings. The format of DATE and TIME will change if the script is run on a different computer with different regional settings. This format could have forward slashes (/) in it that could make your file creation impossible in a single command because those would represents subfolders that do not yet exists.

What I recommend you is to make yourself a function that will generate a string that represents date and time in a format that you have 100% control over. You can take this one below if you want. It will generate date and time in the YYYYMMDD_HHMM format.

Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")

Set LogFile = fso.CreateTextFile("C:\Users\gdlabrui\Desktop\Pick_folder\programs\vbs\ex1 searchAstringAndCopyingOnTxt\" + CurrentDateTimeText() + ".log",true)

Function CurrentDateTimeText()

    CurrentDateTimeText = CStr(Year(Now))+ _
                          Right("0"+CStr(Month(Now)),2)+ _
                          Right("0"+CStr(Day(Now)),2) + "_" + _
                          Right("0"+CStr(Hour(Now)),2) + _
                          Right("0"+CStr(Minute(Now)),2)

End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.