Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get directory's name from path

Status
Not open for further replies.

Helen1greece

Technical User
Jun 4, 2003
85
GR
Is there a way to get directory's name from path? For example if I have in string variable the path "C:\My files\Pictures" how can I get in a string variable the word "Pictures"? Can somebody give me an example code?
 
Use the Split function, then use UBound on the resulting array.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Hi

From MSDN Library:
InStrRev Function

Description:

Returns the position of an occurrence of one string within another, from the end of string.

Syntax:

InstrRev(string1, string2[, start[, compare]])

Hope this helps.
[flowerface]



"All I ask is the chance to prove that money can't make me happy." - Spike Milligan
 
I tried do to it but I couldn't! Can you pleease give me an example code?
 
Private Sub DisplaySubFolders()

Dim strFolder As String
Dim strSubFolders() As String
Dim intIndex As Integer


strFolder = "C:\My files\Pictures"

strSubFolders = Split(strFolder, "\", -1, vbBinaryCompare)

For intIndex = LBound(strSubFolders) To UBound(strSubFolders)
MsgBox strSubFolders(intIndex)
Next intIndex


End Sub
 
If you wanted example from me . . .

Dim x As String
Dim i As Integer

x = "C:\My files\Pictures"
i = InStrRev(x, "\", , vbTextCompare)

MsgBox Mid$(x, i + 1)

[flowerface]

"All I ask is the chance to prove that money can't make me happy." - Spike Milligan
 
You could also use the File System Object:

Dim Fso As FileSystemObject
Dim MyPath As String

Set Fso = CreateObject("Scripting.FileSystemObject")
MyPath = "C:\My files\Pictures"

MsgBox Fso.GetFileName(MyPath)

Swi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top