CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2000
    Posts
    69

    Check if file exists

    Is there a good example of how to check if the file with a prticular name already exists.
    Also it would be nice to find a good mechanism that automaticaly create a versioned file name like myfile_001 or myfile_002 if myfile and myfile_001 already exist.

    Thank you!



  2. #2
    Join Date
    Jun 2001
    Location
    Memphis, TN
    Posts
    146

    Re: Check if file exists

    Here is a fairly simple method to detect if a file exists or not..


    Dim fso
    set fso = CreateObject("scripting.FileSystemObject")

    If Not fso.FileExists("test.txt") then
    msgbox "This file does not exist!"
    End if






  3. #3
    Join Date
    Jun 2001
    Location
    Israel
    Posts
    228

    Re: Check if file exists

    An even simple would be:

    if Dir(MyFile.txt)<>"" then... 'file exists!




    ----------
    The @host is everywhere!
    ----------

  4. #4
    Join Date
    Aug 2000
    Posts
    69

    Re: Check if file exists

    this is actualy better

    FileName = Dir(path & SearchStr, vbNormal Or vbHidden Or vbSystem _
    Or vbReadOnly)




    thank you.


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

Featured