How to cut off part of a string (parse) (1 Viewer)

darkmastergyz

Registered User.
Local time
Today, 13:50
Joined
May 7, 2006
Messages
85
Hi! I have a string right now:

c:/test/anotherfolder/hello.wav

and I want to parse it to "hello.wav", and cut off the rest. I tried using fso, and just decided to settle on just parsing the file name, to hello.wav. What code should I use to make it cut everything before the last "/" out , and leave only "hello.wav". Thank you!!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 13:50
Joined
Aug 30, 2003
Messages
36,124
Look at the InStrRev Function to find the last "/".
 

darkmastergyz

Registered User.
Local time
Today, 13:50
Joined
May 7, 2006
Messages
85
Could you please provide an example using these vars?

var_file = "c:/file/anotherfile/test.wav"
'then can you give me an example to parse it
Thanks!!
 

boblarson

Smeghead
Local time
Today, 13:50
Joined
Jan 12, 2001
Messages
32,059
You didn't say what you needed it for, so I'm just going to say you were assigning it to a text box and you can change the assignment if necessary.

Me.YourTextBoxNameHere = Right(strInput, Len(strInput) - InStrRev(strInput, "\", , vbTextCompare))
 

modest

Registered User.
Local time
Today, 16:50
Joined
Jan 4, 2005
Messages
1,220
We've posted several functions on this forum that breaks a fullpath to it's corresponding root directory, file path, filename, and file extension
 

darkmastergyz

Registered User.
Local time
Today, 13:50
Joined
May 7, 2006
Messages
85
That code works great! How can I use it, now to cut off only the file name and the "/" that precedes it, to only create:

"c:/test/file", from "c:/test/file/test.wav"

Thanks!!
 

boblarson

Smeghead
Local time
Today, 13:50
Joined
Jan 12, 2001
Messages
32,059
That code works great! How can I use it, now to cut off only the file name and the "/" that precedes it, to only create:

"c:/test/file", from "c:/test/file/test.wav"

Thanks!!

It should have done so as I tested it before posting and it returne only the file name. Is there a reason why you are using forward slashes in your string? File system syntax would have a backslash as forward slashes are for Internet URL addressing.

Anyway, Windows may just change them automatically if you use them. But, if you are, then you have to change my code so it is looking for forward slashes instead of backslashes.
 

darkmastergyz

Registered User.
Local time
Today, 13:50
Joined
May 7, 2006
Messages
85
Sorry I wasn't clear. Your code worked. I want it to also tell me only the folder path, rather than only the file.
 

boblarson

Smeghead
Local time
Today, 13:50
Joined
Jan 12, 2001
Messages
32,059
Oh, sorry about that. Then replace the function with this:

Left(strInput, InStrRev(strInput, "\", , vbTextCompare))

and if you don't want the last backslash then use

Left(strInput, InStrRev(strInput, "\", , vbTextCompare) -1)
 

Users who are viewing this thread

Top Bottom