由于各种原因,我陷入了Access 97并且只需要获取完整路径名的路径部分.
例如,名称
c:\whatever dir\another dir\stuff.mdb
应该成为
c:\whatever dir\another dir\
该网站提供了一些有关如何操作的建议:http: //www.ammara.com/access_image_faq/parse_path_filename.html
但它们看起来相当可怕.必须有更好的方法,对吧?
你可以做一些简单的事情: Left(path, InStrRev(path, "\"))
例:
Function GetDirectory(path) GetDirectory = Left(path, InStrRev(path, "\")) End Function
我总是用FileSystemObject
这种东西.这是我使用的一个小包装函数.一定要参考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
这似乎有效.以上不适用于Excel 2010.
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 Object Set filesystem = CreateObject("Scripting.FilesystemObject") StripFilename = filesystem.GetParentFolderName(sPathFile) & "\" Exit Function End Function