Finding if File and Path Exists? 
Author Message
 Finding if File and Path Exists?

I'm looking for a file based on what a user types in.  I'm trying to use
the dir() command to see if the file exists.  My problem is that the user
could type in an invalid path.  If this happens, I get a path not found
error.  How can I check to see if the file and path both exist?


Fri, 31 Jul 1998 03:00:00 GMT  
 Finding if File and Path Exists?

Quote:
>I'm looking for a file based on what a user types in.  I'm trying to use
>the dir() command to see if the file exists.  My problem is that the user
>could type in an invalid path.  If this happens, I get a path not found
>error.  How can I check to see if the file and path both exist?

You could go ahead and use dir() and just trap errors, and ask for
re-input when an error occurs.

You can test for the file \sub\dir\path\. (note period at end) to
determine if subdirectory \sub\dir\path exists.  If it does, you'll get
the name of the first real file in it.  If it doesn't, you'll get a path
not found error that you can trap.  If it exists but it's empty, you'll
get a null string.

Steve Young
Young Computing



Fri, 31 Jul 1998 03:00:00 GMT  
 Finding if File and Path Exists?

reservoirs of wisdom:

Quote:
>I'm looking for a file based on what a user types in.  I'm trying to use
>the dir() command to see if the file exists.  My problem is that the user
>could type in an invalid path.  If this happens, I get a path not found
>error.  How can I check to see if the file and path both exist?

trap the error with an On Error. react to Path Not Found errors,
and tell the user.


--
Newbiehood is not a period of time, it's a way of life.

http://www.sn.no/~balchen
ftp://ftp.sn.no/user/balchen/



Fri, 31 Jul 1998 03:00:00 GMT  
 Finding if File and Path Exists?

Quote:

>I'm looking for a file based on what a user types in.  I'm trying to use
>the dir() command to see if the file exists.  My problem is that the user
>could type in an invalid path.  If this happens, I get a path not found
>error.  How can I check to see if the file and path both exist?

My method for doing so, while perhaps not the most elegant, works just fine:
Create an integer variable (e.g. tempnum), and a string variable (e.g.
FileExists$). Then use this code:
On Error Goto NoFile
tempnum = FileLen(<path typed by user>)
If (FileExists$ <> "None")
        <whatever>
Else
        <whatever>
End if
Exit Sub

NoFile:
FileExists$ = "None"
Resume Next



Mon, 10 Aug 1998 03:00:00 GMT  
 Finding if File and Path Exists?

Quote:


>>I'm looking for a file based on what a user types in.  I'm trying to use
>>the dir() command to see if the file exists.  My problem is that the user
>>could type in an invalid path.  If this happens, I get a path not found
>>error.  How can I check to see if the file and path both exist?

to check file name I use:
On error resume next

a = filedatetime(user file)
if err<>0 then file_dont_exist = true

To check a path simply strip away the filename and try changing the
dir: chdir(user path)

hope this helps

Rune Moe



Tue, 11 Aug 1998 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Opening a dBase file : file not found but it exists really

2. Calling a DLL gives "File Not Found", but File Exists

3. Find the file path of a program file

4. File exists in Dos Path?

5. Reading Target path from *existing* shortcut files.

6. Long Path Names give Runtime error 76 - Path not found

7. find if a file exist in code

8. In QBasic how to find if File Exists???

9. how do i find if a file already exists

10. Finding if file exists using Dir$ Function

11. HowTo: Find out if File Exists

12. How do I find out if a file exists on the server side

 

 
Powered by phpBB® Forum Software