Results 1 to 6 of 6

Thread: finding files

  1. #1

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Question

    hi,

    i'm creating a file using this code

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set a = fs.CreateTextFile("C:\nax.txt", True)
    a.writeline ("Part one completed, reg code will finally go here")
    a.Close

    and i want a want a way on form load that i can check to see if that file excists or not

    thanks

    Merlin ?

  2. #2
    Addicted Member
    Join Date
    Jun 1999
    Location
    Los Angeles
    Posts
    186
    Try opening it:

    Set File= fs.GetFile("C:\nax.txt")

    If len(file)=0 then
    'File not found!!
    end if

    cheers,
    André

  3. #3

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Exclamation finding files

    thanks andre

    but now im getting the message

    "Object not found "

    Any Ideas

    Merlin ?

  4. #4
    Addicted Member
    Join Date
    Jun 1999
    Location
    Los Angeles
    Posts
    186
    Is the error message "Object Required" ?
    If yes, you probably did not Set the fs object in your form load, try this:

    Private Sub Form_Load()

    On Error Resume Next

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set File = fs.GetFile("C:\nax.txt")

    If Err.Number = 53 Then 'File not found
    MsgBox "File Not Found"
    End If

    If Err.Number = 0 Then 'File found
    MsgBox "File Found"
    End If


    End Sub

  5. #5

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Cool Thanks a lot

    hi,

    thanks andre it works brilliantly now


    i have got the program fully working now

    Cheers again

    Merlin ?

  6. #6
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Thumbs up FileExists

    An alternative method is the use the .FileExists function. This returns true if the file exists and false if it doesn't.

    Code:
    Set fs = CreateObject("Scripting.FileSystemObject") 
    
    If fs.FileExists("c:\nax.txt") then
      'do whatever
    Else
      MsgBox "File Not Found"
    End If
    [Edited by Iain17 on 05-18-2000 at 04:05 PM]
    Iain, thats with an i by the way!

Posting Permissions

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



Click Here to Expand Forum to Full Width