Visual Basic Codes
ActiveX
Miscellaneous
Applications
Code Snippets
Common Dialogs
Special Effects
Database Stuff
Date Time
Files Drives
Forms
Graphics Games
Internet Stuff
Multimedia
Other
Strings
Windows
Visual Basic > Files Directories Drives sample source codes
Removing Paths and Extensions
Removing Paths and Extensions Public Function StripPath(FileName As String, _ Optional Extension As Boolean) As Function 'Dimension some variables. Dim TMP As String Dim I As Long Dim FName As String FName = Filename 'Make sure there is a path to strip. If InStr(1, FName, "\") Then For I = 0 To 256 'Maximum filename length. TMP = Right$(FName, I) If Left$(TMP, 1) = "\" Then Exit For Next I FName = Right$(TMP, (I - 1)) End If 'Check whether we should remove extension. If Extension = True Then For I = 1 To 5 'Max. extension length + 1 to capture . TMP = Right$(FName, I) If Left$(TMP, 1) = "." Then Exit For Next I FName = Left$(FName, (Len(FName) - I)) End If StripPath = FName End Function
Privacy Policy
|
Link to Us
|
Links