CodeItBetter Programming Another VB Programming Blog

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:

  1. How to get file size of a given file (in three ways)
  2. How to Return the file portion of a file + pathname without extension (in two ways)
  3. How to get the file name without its extension and path
  4. How to find whether the given directory is empty (in three ways)
  5. How to Return the file portion of a file + pathname (in two ways)
  6. How to Return the Path portion of a file (in two ways)
  7. How to Move Folder from one directory to another (in two ways)
  8. How to count number of files in a given directory (in two ways)
  9. How to write text in a given text file (in three ways)
  10. How to Move File from one directory to another (in three ways)

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.