How to Get file extension for a given 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 19 20 21 | 'File/Folder Handling - How to Get file extension for a given file (in two ways) Option Explicit 'Using FSO: Public Function GetFileExtensionUsingFSO(ByVal sFile As String) As String 'Set a reference to "Microsoft Scripting Runtime" Dim FSO As Scripting.FileSystemObject Set FSO = New Scripting.FileSystemObject GetFileExtensionUsingFSO = FSO.GetExtensionName(sFile) Set FSO = Nothing End Function 'How can I call this function: 'Debug.Print GetFileExtensionUsingFSO("C:\Temp\b\test1.txt") 'Using String Manipulation: Public Function GetFileExtensionUsingStringManip(ByVal sFile As String) As String GetFileExtensionUsingStringManip = Mid$(sFile, InStrRev(sFile, ".") + 1) End Function 'How can I call this function: 'Debug.Print GetFileExtensionUsingStringManip("C:\Temp\b\test1.txt") |
Related posts:
- How to get file size of a given file (in three ways)
- How to Return the file portion of a file + pathname without extension (in two ways)
- How to get the file name without its extension and path
- How to find whether the given directory is empty (in three ways)
- How to Return the file portion of a file + pathname (in two ways)
- How to Return the Path portion of a file (in two ways)
- How to Move Folder from one directory to another (in two ways)
- How to count number of files in a given directory (in two ways)
- How to write text in a given text file (in three ways)
- How to Move File from one directory to another (in three ways)