VB and VBA Users Source Code: Converting File Path names to paths or files
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Converting File Path names to paths or files
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, November 20, 2000
Hits:
578
Category:
Files/Directories/IO
Article:
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 'Author : Andrew Baker 'Date : 25/03/2000 '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 'Author : Andrew Baker 'Date : 25/03/2000 '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
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder