' NewFileEC.vbs ' Sample VBScript to create a file with error-correcting Code ' Author Guy Thomas http://computerperformance.co.uk/ ' VBScript Create File ' Modified by Robert Holland (RH) ' ------------------------------------------------' Option Explicit Dim objFSO, objFolder, objShell, objFile, objTextFile, strText Dim strDirectory, strFile 'Added by RH Dim First, Middle, Last, AllText, strInput 'RH strDirectory = "e:\logs" Set objShell = CreateObject("WScript.Shell") strInput = UserInput( "Enter the URL:" ) Function UserInput( myPrompt ) ' Check if the script runs in CSCRIPT.EXE If UCase( Right( WScript.FullName, 12 ) ) = "\CSCRIPT.EXE" Then ' If so, use StdIn and StdOut WScript.StdOut.Write myPrompt & " " UserInput = WScript.StdIn.ReadLine Else ' If not, use InputBox( ) UserInput = InputBox( myPrompt ) End If End Function strDirectory = "." strFile = "_MakeRH.html" strText = "" First = "Redirecting..." Middle = "" Last = "" AllText = First & Middle & Last ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") ' Check that the strDirectory folder exists 'RH If objFSO.FolderExists(strDirectory) Then 'RH Set objFolder = objFSO.GetFolder(strDirectory) 'RH Else 'RH Set objFolder = objFSO.CreateFolder(strDirectory) 'RH WScript.Echo "Just created " & strDirectory 'RH End If 'RH If objFSO.FileExists(strDirectory & strFile) Then 'RH Set objFolder = objFSO.GetFolder(strDirectory) 'RH Else 'RH Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'RH Wscript.Echo "Just created " & strDirectory & strFile 'RH End If 'Check that the file exists. If objFSO.FileExists(strFile) Then Wscript.echo "File Exists... Quitting!" Wscript.Quit Else Set objFile = objFSO.CreateTextFile(strFile) Wscript.Echo "Just created " & strFile End If 'RH set objFolder = nothing set objFile = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 8 Set objTextFile = objFSO.OpenTextFile _ (strFile, ForAppending, True) '(strDirectory & strFile, ForAppending, True) ' Writes strText every time you run this VBScript 'objTextFile.WriteLine(strText) objTextFile.WriteLine(AllText) objTextFile.Close If err.number = vbEmpty then Set objShell = CreateObject("WScript.Shell") objShell.run ("Explorer" & " " & strDirectory & "\" ) Else WScript.echo "VBScript Error: " & err.number End If WScript.Quit ' End of VBScript to create a file with error-correcting Code