log.txt file not geneating
Dim objFSO, objFolder, strDirectory
strDirectory = "c:\logs"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strDirectory)
MsgBox "Just created " & strDirectory
0 Comments
[ - ] Hide Comments

so that the conversation will remain readable.
Answer this question
or Comment on this question for clarity
Answers
I'd say you're missing the part where you create a textfile...
Please log in to comment
strDirectory="C:\logs"Typo or mistake? (log<->logs)
strFile = "C:\log\micro.txt"
Please log in to comment
Dim objFSO, objFolder, strDirectory
Set objFolder = objFSO.CreateFolder(strDirectory)
MsgBox "Just created " & strDirectory
Please log in to comment
Mohammed,
the part that I don't get is that, while you do define a variable holding the path to the text file, you don't actually do anything with it.
I would expect something along the lines of
Set objFile = objFSO.CreateTextFile("C:\Logs\Micro.txt ")
but I don't see any line in your script that would actually create the file.
Rgds,
PJ
the part that I don't get is that, while you do define a variable holding the path to the text file, you don't actually do anything with it.
I would expect something along the lines of
Set objFile = objFSO.CreateTextFile("
but I don't see any line in your script that would actually create the file.
Rgds,
PJ
Please log in to comment
Hi, below have Script not working
Option Explicit
Dim objFSO, objFolder, strDirectory,strFile
strDirectory = "c:\logs"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strDirectory)
MsgBox "Just created " & strDirectory
Set objFile = objFSO.CreateTextFile
strFile = "C:\logs\micro.txt"
Option Explicit
Dim objFSO, objFolder, strDirectory,strFile
strDirectory = "c:\logs"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strDirectory)
MsgBox "Just created " & strDirectory
Set objFile = objFSO.CreateTextFile
strFile = "C:\logs\micro.txt"
Please log in to comment
Excellent. Now you can edit it so that it's a little more professional. Something like:
Option Explicit
Dim objFSO
DIm objFolder
Dim strDirectory
Dim strFileName
Dim strFile
strFileName = "micro.txt"
strDirectory = "c:\logs"
strFile = strDirectory & "\" & strFileName
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not IsObject(objFSO) Then
'// Maybe display an error message here?
WScript.Quit(False)
End If
With objFSO
Set objFolder = objFSO.CreateFolder(strDirectory)
If Not .FolderExists(strDirectory) Then
'// Maybe display an error message here?
WScript.Quit(False)
End If
MsgBox "Just created " & strDirectory
Set objFile = objFSO.CreateTextFile(strFile)
If Not .FileExists(strFile) Then
'// Maybe display an error message here?
WScript.Quit(False)
End If
End With
'// Clean up
Set objFile = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
Newcomers to coding always make the mistake of assuming that everything will always work. You should assume the exact opposite and code accordingly.Please log in to comment
Comments