Checking for random file existence in Visual Basic 
Author Message
 Checking for random file existence in Visual Basic

How do you check for file exists in Visual Basic when using random files?

thanks in advance.



Sat, 15 Nov 2003 22:47:09 GMT  
 Checking for random file existence in Visual Basic

Simplest way is to open the file for input, if it fails it's not
there. You can also use GetAttr() and catch the error if it doesn't
exist.

Quote:
>How do you check for file exists in Visual Basic when using random files?

>thanks in advance.

Regards, Frank.


Sun, 16 Nov 2003 00:03:01 GMT  
 Checking for random file existence in Visual Basic
I'm using

Function FileExists(pfad$) As Boolean
If Dir(path$) <> "" Then FileExists = True
End Function

Works fine for me.



Sun, 16 Nov 2003 02:05:59 GMT  
 Checking for random file existence in Visual Basic

enlighten us with :

Quote:
>How do you check for file exists in Visual Basic when using random files?

>thanks in advance.

Try this out. Put the code in a module, or change appropriately for
placement in a form's code section :

Public Const MAX_PATH = 260
Public Const INVALID_HANDLE = -1
Public Type FILETIME
    dwLowDateTime   As Long
    dwHighDateTime  As Long
End Type
Public Type WIN32_FIND_DATA
    dwFileAttributes    As Long
    ftCreationTime      As FILETIME
    ftLastAccessTime    As FILETIME
    ftLastWriteTime     As FILETIME
    nFileSizeHigh       As Long
    nFileSizeLow        As Long
    dwReserved0         As Long
    dwReserved1         As Long
    cFileName           As String * MAX_PATH
    cAlternate          As String * 14
End Type
Public Declare Function FindClose Lib "kernel32" (ByVal hFindFile As
Long) As Long
Public Declare Function FindFirstFile Lib "kernel32" Alias
"FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As
WIN32_FIND_DATA) As Long
Public Declare Function FindNextFile Lib "kernel32" Alias
"FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As
WIN32_FIND_DATA) As Long
Public Function Exist(ByVal FileName As String) As Boolean
    Dim FData As WIN32_FIND_DATA
    Dim Handle As Long
    Handle = FindFirstFile(FileName, FData)
    Exist = CBool(Handle <> INVALID_HANDLE)
    Handle = FindClose(Handle)
End Function

        HTH,
        J.
        Jeremiah D. Seitz
        Porch karaoke king and the guy who runs with 8< scissors >8
        Omega Techware
        http://omegatechware.hypermart.net



Sun, 16 Nov 2003 02:40:03 GMT  
 Checking for random file existence in Visual Basic

Quote:
> I'm using

> Function FileExists(pfad$) As Boolean
> If Dir(path$) <> "" Then FileExists = True
> End Function

> Works fine for me.

The above could use a small improvement:

Function FileExists(fSpec As String) As Boolean
If Trim$(fSpec) <> "" Then
    FileExists = (Dir(fSpec) <> "")
End if
End Function

There is a bug in the Dir function, that lets it return a random file name
if you pass it an empty string. (may only happen in VB5??)



Sun, 16 Nov 2003 05:21:35 GMT  
 Checking for random file existence in Visual Basic
Oh God - here we go again.

Always use Dir - especially in deeply embedded routines - it makes
life so much more interesting for the users.

Never use GetAttr to check for a file's existence - or even FileLen -
or the FindFirstFile API .

We need a FAQ


Quote:
>How do you check for file exists in Visual Basic when using random files?

>thanks in advance.



Sun, 16 Nov 2003 19:46:38 GMT  
 Checking for random file existence in Visual Basic


Quote:
>We need a FAQ

Yeah, but we'll fight over what we'll put into it  ;-)
I'm kinda working on it, but it's going slow.This is like writing a
doc file. Ugh... Once i get a few pages up i'll post it for approval
and aditions. Unless somene else is doing one already ? Please ? :)

Regards, Frank.



Sun, 16 Nov 2003 20:34:13 GMT  
 Checking for random file existence in Visual Basic
I think Larry Serflaten and/or Bob Butler are playing around with the concept, although I
haven't heard anything in the last couple of weeks. You might want to contact them
(posting a request on the microsoft.public.vb.general.discussion newsgroup might catch
their eye quicker).

Rick


Quote:


> >We need a FAQ

> Yeah, but we'll fight over what we'll put into it  ;-)
> I'm kinda working on it, but it's going slow.This is like writing a
> doc file. Ugh... Once i get a few pages up i'll post it for approval
> and aditions. Unless somene else is doing one already ? Please ? :)

> Regards, Frank.



Sun, 16 Nov 2003 21:48:07 GMT  
 Checking for random file existence in Visual Basic
Best just one FAQ - maybe design a structure

     <!-- STRUCTURE
           ID=XYZ123
           Section=Filing
           Title=Random Access
           Author=XYZ
     -->      

And then perhaps automate the building of the site.

A post form could do the trick.

This looks quite interesting as a project.  

I've always liked the www.AllAPI.net guide's content - but the
programming is horrible.



Quote:


>>We need a FAQ

>Yeah, but we'll fight over what we'll put into it  ;-)
>I'm kinda working on it, but it's going slow.This is like writing a
>doc file. Ugh... Once i get a few pages up i'll post it for approval
>and aditions. Unless somene else is doing one already ? Please ? :)

>Regards, Frank.



Sun, 16 Nov 2003 22:44:04 GMT  
 Checking for random file existence in Visual Basic
I'd be very interested to have a copy of your FAQ, Tom, even in its
unfinished state. In fact, why not post it here and we can then all reply
with other stuff that we think should go into it. That should make life
interesting again. Also, between us we can ensure that all of the answers it
contains are absolutely sound. None of us can do this thing alone, but
between us we should definitely be able to produce something that is "water
tight" and that will be extremely useful to others.

Mike


Quote:


> >We need a FAQ

> Yeah, but we'll fight over what we'll put into it  ;-)
> I'm kinda working on it, but it's going slow.This is like writing a
> doc file. Ugh... Once i get a few pages up i'll post it for approval
> and aditions. Unless somene else is doing one already ? Please ? :)

> Regards, Frank.



Sun, 16 Nov 2003 22:52:29 GMT  
 Checking for random file existence in Visual Basic

net.com> writes

Quote:
>We need a FAQ

We do indeed. I guess it would have to have be a communal effort. I
might able to offer some bits and bobs at the very simplest end of VB
where most of the repeated questions seem to occur.

Regards.

--
Martin Trump



Mon, 17 Nov 2003 00:35:59 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. To Any visual basic Pro's :Random-Acess file functions

2. A2K Check for Existence of Back End File

3. Checking for the existence of a file

4. How to check for existence of a file on harddisk form OL VBscript

5. Check File Existence?

6. Checking for the Existence of a File

7. Checking for existence of a file???

8. Check for existence of a file?

9. Checking for existence of a file...

10. Check for the existence of a file.

11. Checking the Existence of a File

12. Newbie Question: File existence checking

 

 
Powered by phpBB® Forum Software