Get the Full Path of a File

By | 2019-08-24

This is a very simple way to get just the full directory path of a file passed in.

Public Function GetTheFilePath(ByVal strFile) As String
   Files = Split(strFile, "\")
   For I = 0 to (UBound(Files) - 1)
      FilePath = FilePath & Files(I) & "\"
   Next
   GetTheFilePath = FilePath
End Function

Usage

MyFilePath = GetTheFilePath("C:\testing\jim\file.txt")

will return:

C:\testing\jim\

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.