CodeItBetter Programming Another VB Programming Blog

How to Return the file portion of a file + pathname (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 file portion of a file + pathname (in two ways)
Option Explicit
 
'Non FSO Method:

Public Function GetFileUsingNonFSO(ByVal sFileName As String) As String
    GetFileUsingNonFSO = Mid$(sFileName, InStrRev(sFileName, "\") + 1)
End Function
 
'FSO Method:

Public Function GetFileUsingFSO(ByVal sFileName As String) As String
'Set a reference to "Microsoft Scripting Runtime"
    Dim FSO As Scripting.FileSystemObject
    Set FSO = New Scripting.FileSystemObject
    GetFileUsingFSO = FSO.GetFileName(sFileName)
    Set FSO = Nothing
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.