Validating a path/filename 
Author Message
 Validating a path/filename

I allow the user to save an export file to a path and filename he specifies
(ex. d:\data\file.txt).
How can I determine that the path part (d:\data\) is valid (exists).

How can I determine that the file does not aleady exists.

I tried using the dir function but that does not really do it.

Does VBA have functions to return the various parts of a fully qualified
pathname?

--
Please respond to the newsgroup AND the author:

Thanks
Shawn



Sat, 03 Nov 2001 03:00:00 GMT  
 Validating a path/filename
In VBA, you are intended allow the error to occur, and use error
handling
to recover if necessary. Because there are so many things that can go
wrong during the writing of a file (invalid path, invalid device, device
not ready, illegal file name, drive full, file already exists, network
failed, etc., etc.), I would encourage you do take this approach, and
rely on the VBA error handler to cope with the possible errors.

Sample:
------------------------------------
Function WriteFile(sPath) As Boolean
On Error GoTo Err_WriteFile

    ' Code to write the file here.
    WriteFile = True    ' If we got this far, it worked.
Exit_WriteFile:
    Exit Function

Err_WriteFile:
    MsgBox Err.Description, , "Error " & Err.Number & " writing file."
    Resume Exit_WriteFile
End Function
------------------------------------

Quote:

> I allow the user to save an export file to a path and filename he specifies
> (ex. d:\data\file.txt).
> How can I determine that the path part (d:\data\) is valid (exists).

> How can I determine that the file does not aleady exists.

> I tried using the dir function but that does not really do it.

> Does VBA have functions to return the various parts of a fully qualified
> pathname?

> --
> Please respond to the newsgroup AND the author:

> Thanks
> Shawn



Sun, 04 Nov 2001 03:00:00 GMT  
 Validating a path/filename

Let Windows do the job by using the file-Open-API (Gives you a prooved
filename).



Sun, 04 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. getting just the filename, not the filename path from the opendialog control

2. Validate filename

3. Validating a path using Regulare Expressions

4. Validating an UNC path

5. Validating a file path.....

6. Validate path

7. Absolute FileName Path

8. Retrieving Full path and Filename vs Open Dialog Box

9. just retrieving the file path without specifying a filename

10. Getting filename out of fully qualified path

11. Path and Filename

12. Looping through a path to get all filenames?

 

 
Powered by phpBB® Forum Software