Visual Basic > Files Directories Drives
Converting File Path names to paths or files
Converting File Path names to paths or files Below are two simple routines for returning either a file or path, from a full path and file name. 'Purpose : Convert a file and path to a path e.g. "C:\Windows\Win.ini" becomes "C:\Windows\" 'Inputs : sFilePathName The path and file name to convert 'Outputs : Returns the file path 'Notes : Also works with URL's Function PathFileToPath(sFilePathName As String) As String Dim lThisChar As Long PathFileToPath = sFilePathName 'Default return value lThisChar = InStrRev(sFilePathName, "\") If lThisChar Then PathFileToPath = Left$(sFilePathName, lThisChar) Else 'Check remote paths lThisChar = InStrRev(sFilePathName, "/") If lThisChar Then PathFileToPath = Left$(sFilePathName, lThisChar) End If End If End Function 'Purpose : Convert a file and path to a file e.g. "C:\Windows\Win.ini" becomes "win.ini" 'Inputs : sFilePathName The path and file name to convert 'Outputs : Returns the file name 'Notes : Also works with URL's Function PathFileToFile(sFilePathName As String) As String Dim lThisChar As Long PathFileToFile = sFilePathName 'Default return value lThisChar = InStrRev(sFilePathName, "\") If lThisChar Then PathFileToFile = Mid$(sFilePathName, lThisChar + 1) Else 'Check remote paths lThisChar = InStrRev(sFilePathName, "/") If lThisChar Then PathFileToFile = Mid$(sFilePathName, lThisChar + 1) End If End If End Function
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