Check if 2 files exist

Posted on 2012-09-05
Last Modified: 2012-09-05
I am making a registration module that compare 2 files contents
i have a Boolean function that checks if files exist
    Dim sFileOneExists As Boolean
    Dim sFileTwoExists As Boolean

sFileOneExists = FileExists(sFileNameOne)
sFileTwoExists = FileExists(sFileNameTwo)

whats the best way to write this ?
if neither exists then they are created
if only one exists then the program has been hacked
if they both exist then they are opened and compared
using vb6
Question by:isnoend2001
    LVL 13

    Expert Comment

    That can be done using the FileSystemObject model in VB6.

    See this: Link

    P.S. If I get a chance I might write some of the code to check for the files, but I can't guarantee anything.

    Hope it helps.
    LVL 44

    Accepted Solution

        Dim sFileOneExists As Boolean
        Dim sFileTwoExists As Boolean
        On Error Resume Next
        sFileOneExists = (GetAttr("Path and file name 1") And vbDirectory) = 0
        sFileTwoExists = (GetAttr("Path and file name 2") And vbDirectory) = 0
        On Error GoTo 0
        Select Case True
            Case Not sFileOneExists And Not sFileTwoExists
                MsgBox "create files"
            Case sFileOneExists And sFileTwoExists
                MsgBox "Compare"
            Case Else
                MsgBox "Hacked"
        End Select

    Open in new window


    Author Comment

    LIONKING, not looking for file open, save or exists

    Author Closing Comment

    thank you MartinLiss, just what i needed
    LVL 44

    Expert Comment

    by:Martin Liss
    You're welcome and I'm glad I was able to help.

    My profile contains links to some articles I've written that may interest you.
    Marty - MVP 2009 to 2012

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now