Announcement

Collapse
No announcement yet.

Check if file exists?

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

  • Lance Edmonds
    replied
    No one has said GetAttr() would not work... like many programming problems, there are often several solutions available.

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

    Leave a comment:


  • Edwin Knoppert
    replied
    This topic has been discussed before.
    I'm curious why GetAttr is not good enough??

    I'm always using this and never had a problem.
    Only with PB/DLL20<>VB3.

    This is how i use it:
    Errclear
    a = GetAttr( FileName )
    If Err = 0 And IsFalse( a And %FILE_ATTRIBUTE_DIRECTORY ) then

    '''''''

    End If

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

    Leave a comment:


  • Lance Edmonds
    replied
    Searching the BBS for "exists" in Subject-Only gets about 20 hits. In summary:

    There is an EXISTS() function in COMMON32.BAS using DIR$():
    Code:
    FUNCTION Exist(file AS STRING) EXPORT AS INTEGER  
      FUNCTION = LEN(DIR$(file, 17)) > 0
    END FUNCTION
    However, using DIR$() in the above code may cause problems if it is called from within a DIR$() file search loop. Something like this may be more useful: (Thanks to Fred Oxenby for this code)

    Code:
    Function FSO_FileExists(ByVal FileSpec$)Export As Long
    Local fd As WIN32_FIND_DATA
    Local fAttr As Dword
    Local hFind&
      If Len(FileSpec$)= 0 Then Function = %false:Exit Function
      hFind& = FindFirstFile(ByVal StrPtr(FileSpec$), fd)
      If hFind& = %INVALID_HANDLE_VALUE Then Function = %False:Exit Function
      Call FindClose(hFind&)
      fAttr = fd.dwFileAttributes
      Function = %True
      'NotDirectory|NotTemporary
      If (Bit(fAttr, 4)=1) Or (Bit(fAttr,8)=1) Then Function = %false
    End Function
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Edwin Knoppert
    replied
    GetAttr()

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

    Leave a comment:


  • Aldo Cavini
    replied
    I do OPEN it for INPUT, and check ERR. If ERR = 53, then the file doesn't exist. If success, remember you have an OPENed file - If it is only for test (not to work on it) you should CLOSE the file.

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

    Leave a comment:


  • Ariel Benzakein
    started a topic Check if file exists?

    Check if file exists?

    Does anyone have a function that will check to see if a file
    exists?


    ------------------
Working...
X