Create a text file???????

Results 1 to 2 of 2

Thread: Create a text file???????

  1. #1
    Join Date
    Dec 1969

    Default Create a text file???????

    I have information from a shopping cart that is wrote to a text file. I need to be able to create a new file and call it a unique name. Here is my code that I am using now:<BR><BR>&#060;SCRIPT LANGUAGE=VBScript RUNAT=Server&#062;<BR>Function WriteToLogFile(strLogMessage) &#039example use of Err object<BR> ForAppending = 8 &#039ASP doesn&#039t recognize this is some releases<BR> WriteToLogFile = False &#039default return value of function <BR> On Error Resume Next<BR> Set objFSO = CreateObject("Scripting.FileSystemObject")<BR> Set objLogFile = objFSO.OpenTextFile("C:inetpubwwwrootK12logfilesMy Log.txt", ForAppending)<BR> Select Case Err.Number<BR> Case 0 &#039OK, do nothing<BR> Case 5, 50, 53 &#039standard file or path not found errors<BR> &#039create the custom error values and raise it back to the system<BR> intErrNumber = vbObjectError + 1073 &#039create a custom error number<BR> strErrDescription = "Log file has been deleted or moved."<BR> strErrSource = "WriteToLogFile function"<BR> Err.Raise intErrNumber, strErrSource, strErrDescription<BR> Exit Function<BR> Case Else &#039some other error<BR> &#039raise the standard error back to the system<BR> Err.Raise Err.Number, Err.Source, Err.Description<BR> Exit Function<BR> End Select<BR> objLogFile.WriteLine(strLogMessage)<BR> objLogFile.Close<BR> WriteToLogFile = True<BR>End Function<BR>&#060;/SCRIPT&#062;<BR><BR><BR>

  2. #2
    Keith Fowler Guest

    Default RE: Create a text file???????

    The File Scripting Object has a method called GetTempName.<BR>It&#039s actually a random filename generator. Simply set it up to retrieve name for you and pass it to the OpenTextFile Method.<BR><BR>strFileName = objFSO.GetTempName<BR>Set objLogFile = objFSO.OpenTextFile("("C:inetpubwwwrootK12logfiles \" & strFileName & ".txt", ForAppending)<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts