Announcement

Collapse
No announcement yet.

File Exists command???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • File Exists command???

    Is there a command in PB/DLL6 that will allow me to
    check for the presence of an EXE file and if so, return
    a value (1) that can be used if the file was found and a
    (0) for instance if the file wasn't found?
    I looked at DIR$, but that did'nt seem like what I needed.

    Thanks,
    Gary Stout

    ------------------
    Thanks,
    Gary Stout
    gary at sce4u dot com

  • #2
    Code:
    ErrClear
    a = GetAttr( sFileName )
    If Err = 0 And IsFalse( a And %FILE_ATTRIBUTE_DIRECTORY ) Then
    'File found...
    End If


    ------------------
    hellobasic

    Comment


    • #3
      Gary,

      This is an old one of Dave Navarro's that has been doing the job for years.
      Code:
      FUNCTION Exist&(fname$)
        FUNCTION = Len( Dir$(fname$, 17) ) > 0
      END FUNCTION
      Regards,

      [email protected]


      ------------------
      hutch at movsd dot com
      The MASM Forum

      www.masm32.com

      Comment


      • #4
        Thanks guys,
        I will give them both a try. Going to use this to enable or disable
        menu items in EZGUI. If the EXE being search for is not found, then
        then the menu item will be greyed out and disabled, otherwise,
        it will be normal and able to be selected.

        Thanks again,
        Gary Stout

        ------------------


        [This message has been edited by Gary Stout (edited May 29, 2001).]
        Thanks,
        Gary Stout
        gary at sce4u dot com

        Comment


        • #5
          Steve, which number in Dir$(path,number) will display all files? Ive been using Dir$(file,39) for the last year for some reason that I cant remember
          The decimal values of each attribute:
          readonly 1
          hidden 2
          system 4
          directory 16
          archive 32
          normal 128

          so Im assuming i put 39 together from 32+4+2+1 , which seems to be working fine to detect all files, regardless of their attributes
          I prefer using a number such as 39 rather than %FILE_ATTRIBUTE_READONLY + %FILE_ATTRIBUTE etc etc
          Which number do you use for files (regardless of the files attributes), and which for dirs?

          Best regards,
          Wayne


          ------------------
          -

          Comment


          • #6
            Wayne, only Hidden (2), System (4), and Directory (16) are search attributes.
            So, to match all files, you just need 2+4+16 = 22.

            The "normal" attribute is an oddball addition by Microsoft late in the game.
            "Normal" used to be simply a file with no other attributes set. It is not
            clear why a specific number is needed for "normal" or whether you can expect
            to see it in combination with other bits, or exactly why Microsoft chose 128
            when they must have known that Novell has always used this to mean "protected".


            ------------------
            Tom Hanlin
            PowerBASIC Staff

            Comment


            • #7
              On the same subject, I wonder what is the best way to perform this
              test on a network file, allowing for graceful recovery in the case
              where say the connection may not currently exist.

              Is it simply a case of trapping the error, or I wonder if timeouts
              are involved ?

              Could someone explain the pros & cons please ?

              Thanks -

              [This message has been edited by Paul Noble (edited May 30, 2001).]
              Zippety Software, Home of the Lynx Project Explorer
              http://www.zippety.net
              My e-mail

              Comment


              • #8
                You could test the errors such as the way this function (I've used this one for 3 years now)...
                Test hDir for return error...
                If the file exists but the pathing/mapping is wrong because of a network error you should get something like 'Network path not found'.


                Code:
                Function Exist(ByVal filespec As String) Export As Long
                  Local hDir     As Long
                  Local FindData As WIN32_FIND_DATA
                
                  FindData.dwFileAttributes = %FILE_ATTRIBUTE_DIRECTORY
                  hDir = FindFirstFile(ByVal StrPtr(filespec), FindData)
                  Function = hDir
                  If hDir = %INVALID_HANDLE_VALUE Then
                    Exit Function     'file not found
                  End If
                  FindClose hDir
                End Function
                ------------------
                Scott
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  Thanks Scott, I just tested that and my own method (same as the
                  one originally posted), and both work fine in that situation.

                  The reason for asking was that a few years ago, I had a problem
                  in VB5 where it waited for ages before deciding it couldn't see
                  say "\\server\data\file.dat". I don't remember the outcome
                  now, but it certainly appears that it's not an issue from PB
                  Zippety Software, Home of the Lynx Project Explorer
                  http://www.zippety.net
                  My e-mail

                  Comment


                  • #10
                    ah...Well I see that when I open explorer, it goes out and makes sure the credentials are still good etc, makes sure the folder/share are still there...

                    And this function will ptu a lag on it too the first time you use the file/share if you have not logged in for a while...

                    I'm not sure what causes that exactly, perhaps just refreshing credentials


                    ------------------
                    Scott
                    Scott Turchin
                    MCSE, MCP+I
                    http://www.tngbbs.com
                    ----------------------
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                    Comment


                    • #11
                      Sure. Network settings such as "Quick logon" and "Logon and restore connections" can definitely affect the speed of the first access to a network (mapped) drive.

                      ------------------
                      Lance
                      PowerBASIC Support
                      mailto:[email protected][email protected]</A>
                      Lance
                      mailto:[email protected]

                      Comment

                      Working...
                      X