...

View Full Version : Extract filename out of absolute path



junior1025
07-03-2008, 09:00 PM
Hi,

I got a list of URL's( Absolute Path's) from which I have to return only the list of filenames ( Relative Path's).

Ex:
AbsolutePath -- C:/Programfiles/hello/abc.txt

I need to pull the RelativePath --- abc.txt.

I really appreciate your help.

Thanks.

oracleguy
07-03-2008, 11:15 PM
We aren't telepaths. You have to give us more information. What language are you using? Do you just want the filename or do you want the relative path from where the code is executing from?

Pennimus
07-04-2008, 04:50 PM
If this is a one time thing, just use Excel, and split by "/", or do a wildcard find/replace.

junior1025
07-07-2008, 02:41 PM
Iam sorry!

It is in Java.
I need only the files names.

Please tell how todo in either cases.

Thanks.

oracleguy
07-07-2008, 05:30 PM
Then I will move this over to the Java forum.

brad211987
07-07-2008, 07:26 PM
If you have the URLs stored in strings then here are 2 options off the top of my head.

First you could use the split method of the String class to split the url using / as a delimiter.

Otherwise you could use the substring method starting at lastIndexOf('/') +1.

maidenrockdan
07-16-2008, 12:05 AM
Original post deleted

shyam
07-16-2008, 05:39 AM
Ex:
AbsolutePath -- C:/Programfiles/hello/abc.txt

I need to pull the RelativePath --- abc.txt.


you mean the filename...


String path = "C:/Programfiles/hello/abc.txt";
String fileName = new File(path).getName();



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum