For various reasons, I'm stuck in Access 97 and need to get only the path part of a full pathname.
For example, the name
c:\whatever dir\another dir\stuff.mdb
should become
c:\whatever dir\another dir\
This site has some suggestions on how to do it: http://www.ammara.com/access_image_faq/parse_path_filename.html
But they seem rather hideous. There must be a better way, right?
A full path or absolute path is a path that points to the same location on one file system regardless of the working directory or combined paths. It is usually written in reference to a root directory. The distinction between files and directories isn't catered for with a path.
The Microsoft Access CurDir function returns the current path.
Using System.IO.Path.GetFileName GetFileName that returns the file name and extension of the specified path string.
You can do something simple like: Left(path, InStrRev(path, "\"))
Example:
Function GetDirectory(path) GetDirectory = Left(path, InStrRev(path, Application.PathSeparator)) End Function
I always used the FileSystemObject
for this sort of thing. Here's a little wrapper function I used. Be sure to reference the Microsoft Scripting Runtime
.
Function StripFilename(sPathFile As String) As String 'given a full path and file, strip the filename off the end and return the path Dim filesystem As New FileSystemObject StripFilename = filesystem.GetParentFolderName(sPathFile) & "\" Exit Function End Function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With