How to Return the Path portion of a file (in two ways)
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 'File/Folder Handling - How to Return the Path portion of a file (in two ways) Option Explicit 'Non FSO Method: Public Function GetPathUsingNonFSO(ByVal sFileName As String) As String GetPathUsingNonFSO = Mid$(sFileName, 1, InStrRev(sFileName, "\")) End Function 'FSO Method: Public Function GetPathUsingFSO(ByVal sFileName As String) As String 'Set a reference to "Microsoft Scripting Runtime" Dim FSO As Scripting.FileSystemObject Set FSO = New Scripting.FileSystemObject GetPathUsingFSO = FSO.GetParentFolderName(sFileName) Set FSO = Nothing End Function |