Hi, does anyone know the most simple way i can check is i file exists in a directory in VB6? i'm trying to make a validation routine for saving a file, so when the user clicks save the program will check is the file already exists and then respond accordingly. thanks.
Visual basic 6 - file existance
Miscellaneous Forums/General Discussion/Visual basic 6 - file existance Hi, i tried the code from that page, but it doesn't seem to work for me, i changed the variables accordingly to my project, could be that i'm not understanding the code properly, could you please explain the concept behind the code. thanks
the filesystemobject doesn't seem to be recognised as a variable type for some reason, i've looked in the msdn for it and it does have information on it but it still doesn't work, any ideas why? thanks
Try this.
Dim l_FS As Object
Set l_FS = CreateObject("Scripting.FileSystemObject")
(edit - I forgot this line) l_FS.FileExists("file")
Dim l_FS As Object
Set l_FS = CreateObject("Scripting.FileSystemObject")
(edit - I forgot this line) l_FS.FileExists("file")
And without the FileSystemObject:
FileExists=Dir$(FileName$)<>""
Is it possible to do by checking file size?
I don't know if this work or not though...
I don't know if this work or not though...
Is it possible to do by checking file size?
No, because a file can exist with a size of 0 bytes. Googleed some results
http://www.vbforums.com/archive/index.php/t-349990.html
http://www.freevbcode.com/ShowCode.asp?ID=346
http://www.pbdr.com/vbtips/gen/fileexst.htm
If you use size check, -1 may present as "not exist" or "error", handle with care.
http://www.vbforums.com/archive/index.php/t-349990.html
http://www.freevbcode.com/ShowCode.asp?ID=346
http://www.pbdr.com/vbtips/gen/fileexst.htm
If you use size check, -1 may present as "not exist" or "error", handle with care.
> Is it possible to do by checking file size?
Why would you want to though? The proper method of checking for file existance is easy, well once you get past the incorrect documentation.
Why would you want to though? The proper method of checking for file existance is easy, well once you get past the incorrect documentation.
This habit actually came from using PureBasic... check the file size return -1 if not exist, -2 if directory, I don't know if it applies to other languages