Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the directory part (minus the filename) of a full path in access 97

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?

like image 310
apenwarr Avatar asked Jan 06 '09 23:01

apenwarr


People also ask

What is the complete path of the filename?

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.

Which of the following returns the current MS Access database directory?

The Microsoft Access CurDir function returns the current path.

How do I get the filename from a path in Visual Basic?

Using System.IO.Path.GetFileName GetFileName that returns the file name and extension of the specified path string.


2 Answers

You can do something simple like: Left(path, InStrRev(path, "\"))

Example:

Function GetDirectory(path)    GetDirectory = Left(path, InStrRev(path, Application.PathSeparator)) End Function 
like image 104
Makah Avatar answered Sep 23 '22 08:09

Makah


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 
like image 21
John Mo Avatar answered Sep 22 '22 08:09

John Mo