How to cut off part of a string (parse)

darkmastergyz

Registered User.
Local time
Yesterday, 19:53
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!!
 
Look at the InStrRev Function to find the last "/".
 
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!!
 
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))
 
We've posted several functions on this forum that breaks a fullpath to it's corresponding root directory, file path, filename, and file extension
 
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!!
 
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.
 
Sorry I wasn't clear. Your code worked. I want it to also tell me only the folder path, rather than only the file.
 
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

Back
Top Bottom