Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up Extract filename out of absolute path

    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.

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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?
    OracleGuy

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    If this is a one time thing, just use Excel, and split by "/", or do a wildcard find/replace.

  • #4
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Iam sorry!

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

    Please tell how todo in either cases.

    Thanks.

  • #5
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Then I will move this over to the Java forum.
    OracleGuy

  • #6
    Regular Coder brad211987's Avatar
    Join Date
    Sep 2005
    Location
    Ohio
    Posts
    631
    Thanks
    10
    Thanked 50 Times in 50 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Jul 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile The correct solution

    Original post deleted
    Last edited by maidenrockdan; 07-16-2008 at 12:06 AM. Reason: Wrong language

  • #8
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    Quote Originally Posted by junior1025 View Post
    Ex:
    AbsolutePath -- C:/Programfiles/hello/abc.txt

    I need to pull the RelativePath --- abc.txt.
    you mean the filename...
    Code:
    String path = "C:/Programfiles/hello/abc.txt";
    String fileName = new File(path).getName();
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •