VB and VBA Users Source Code: Formating a path to always end with a backslash
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Formating a path to always end with a backslash
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, October 02, 2003
Hits:
1607
Category:
Files/Directories/IO
Article:
The following function is useful for adding the trailing backslash to a path and for combining lots of paths sub paths into a single path. 'Purpose : Ensures a path always finishes with a trailing backslash 'Inputs : sPath The path to complete ' [avPaths] Optional paths to append to sPath 'Outputs : Returns a path with a trailing backslash 'Author : Andrew Baker 'Date : 03/09/2000 14:17 'Notes : 'Revisions : Function FormatPath(sPath As String, ParamArray avPaths() As Variant) As String Dim vThisPath As Variant FormatPath = sPath If Right$(FormatPath, 1) <> "\" Then 'Add backslash FormatPath = FormatPath & "\" End If 'Append with a sub paths For Each vThisPath In avPaths If Len(vThisPath) Then If Left(vThisPath, 1) = "\" Then FormatPath = FormatPath & Mid$(vThisPath, 2) Else FormatPath = FormatPath & vThisPath End If End If Next If Right$(FormatPath, 1) <> "\" Then 'Add backslash FormatPath = FormatPath & "\" End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder