Home
DBPix
Download
Order
Testimonials
Support
Tutorials
Samples
KnowledgeBase
Links
Revision History
Documentation
Search
Contact
Site Map

Graph: DBPix image storage vs OLE Embedding and Linking in Microsoft Access


    
The Access Image FAQ < Previous ArticleNext Article >

Parse the Folder or Filename from a Full Path


    
Sample Newsgroup Questions 
Parsing a file reference from a path
Extract file name from path
Capturing File Name As Opposed To The Full File Path
Splitting a file path
Retrieving a file name to store in a field
Strip File Name & Folder Name from path
Get File Name from Path
Need filename only not location
Trimming filenames
Extracting filename from path


As we saw in the article Store Images using Relative Paths it is usually preferable to only store an image filename in the database, not the full path. In this and other situations it may be necessary to obtain a filename from a full-path (and similarly to obtain just the folder part).

Implementations are provided below for two functions: 'FileNameFromPath' and 'FolderFromPath'. Note that the string returned by 'FolderFromPath' includes a trailing back-slash.

1) Access 2000 and later.

If you only need to support Access 2000 and later the following versions are the simplest and most efficient. These implementations use the 'InStrRev' function, which has reportedly caused problems on some systems. In case of such problems use the Access 97 versions below.


Public Function FileNameFromPath(strFullPath As String) As String
    FileNameFromPath = Right(strFullPath, Len(strFullPath) - InStrRev(strFullPath, "\"))
End Function

Public Function FolderFromPath(strFullPath As String) As String
    FolderFromPath = Left(strFullPath, InStrRev(strFullPath, "\"))
End Function


2) Access 97 and later.

If you need to support Access 97 then use this method. .

Note that other approaches are possible which avoid the loop (and are therefore potentially slightly more efficient), but these either require use of the "Dir" function (which can give rise to recursion problems) or need additional references.


Public Function FileNameFromPath(strFullPath As String) As String
    Dim I As Integer

    For I = Len(strFullPath) To 1 Step -1
        If Mid(strFullPath, I, 1) = "\" Then
            FileNameFromPath = Right(strFullPath, Len(strFullPath) - I)
            Exit For
        End If
    Next
End Function

Public Function FolderFromPath(strFullPath As String) As String
    Dim I As Integer

    For I = Len(strFullPath) To 1 Step -1
        If Mid(strFullPath, I, 1) = "\" Then
            FolderFromPath = Left(strFullPath, I)
            Exit For
        End If
    Next
End Function




Related Articles

Get the Path to the Database (.mdb) File
Use autonumber fields for image file names
Use Relative Paths for Linked Images




Imaging for Access that's Easy, Efficient & Fast
  • NO OLE Bloat
  • NO App Dependencies
  • NO Complex Coding
  • NO Performance Penalty
  •  DBPix logo
    Read More


    Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.