Results 1 to 7 of 7
  1. #1

    error in creating a file

    Hi ,

    i am tring to create a text file using the following function. I get a error saying "bad filename or number" what may be the problem ?

    Sub CreateLog()
    Set fso = CreateObject("Scripting.FileSystemObject")
    timestamp = Now()
    timestamp = Replace (timestamp," ","_")
    timestamp = Replace (timestamp,"/","_" )
    timestamp = Replace (timestamp,":","_")
    logFileName = screenshot_path + "\" + language + "\" + "Uninstall_Log_" + language + "_" + timestamp + ".txt"
    ' Screshot_path is the path where the screen shot is stored
    ' Language is a folder with in the screen shot
    Set logFile = fso.CreateTextFile(logFileName, True)
    set logFile = nothing
    set fso = nothing
    End Sub

  2. #2
    SQA Knight
    Join Date
    Jul 1999
    Grand Rapids, MI

    Re: error in creating a file

    1. If the file's folder does not exist I think that could cause this type of error.

    2. The path/filename may be malformed, which could cause this error. Use a:

    msgBox logFile

    before calling fso.CreateTextFile() to debug this problem.

  3. #3

    Re: error in creating a file

    Your Log file name is coming up as "\\Uninstall_Log__1_17_2008_9_49_33_AM.txt"

    which is wrong. If you want to create the log in the current directory which would bin directory in QTP then you can need to remove the \\ thing. If you want a proper path then add the folder path also to the file name.

  4. #4

    Re: error in creating a file

    I want the file to be created at the run time.. The name of the language changes here every iteration. The following is the folder structure:

    language can be english,french..
    How the text file has to be created in this scenario ?


  5. #5

    Re: error in creating a file

    do something like

    lang = "english"
    fileName= "C:\Screenshots\" & lang & "\Uninstall_log.txt"

  6. #6

    Re: error in creating a file

    Hi Tarun,

    I cannot do like this as the screen_shot variable is picked from the environment variable and it is used in other functions too. is there some work around for the same.


  7. #7

    Re: error in creating a file

    Check if the value of the variable logFileName is coming correctly.


    logFileName = screenshot_path & "\" & language & "\" & "Uninstall_Log_" & language & "_" & timestamp +&".txt"

    Check the value of logFileName after the above step.If it is a valid file name the file should be created



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 05:39 PM.

Copyright BetaSoft Inc.