Results 1 to 7 of 7
  1. #1
    ivvgangadhar is offline Member
    Join Date
    Nov 2008
    Posts
    13
    Rep Power
    0

    Default How to know system folder path

    Hi,

    I have some folder name in my system(eg:-e://xxx).Can i know that folder is located in E Drive through java Code.

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Take a look at the API docs for File.

  3. #3
    DevzAbhi's Avatar
    DevzAbhi is offline Member
    Join Date
    Jul 2008
    Posts
    67
    Rep Power
    0

    Default

    import java.io.*;

    public class DirListing1 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    Boolean flag=false;
    File f =new File("e:/");
    String [] s=f.list();
    for(int index =0 ; index<s.length;index++){
    if(s[index].equals("e:/xxx")){

    flag=true;

    }

    System.out.println(s[index]);


    }



    }

    }

  4. #4
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    6

    Default

    @DevzAbhi's code fragment starts with the explicit statement to look on E:

    If the real question is: I have a directory somewhere, and its called XXX, how do I find it?

    This is harder, because the concept of an E: drive is Windows specific,
    You could, altho its crude, just run through a loop of all drive letters, A through Z, but with UNC names, that isn't guarenteed to be complete

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by ivvgangadhar View Post
    Hi,

    I have some folder name in my system(eg:-e://xxx).Can i know that folder is located in E Drive through java Code.
    I'm not clear what you are asking here. Are you want to find that a specific folder(as you said xxx) is located on drive E or not? So you have to search recursively all drives in the system.

    But as fishtoprecords says, it's Widows specific, in UNC systems you don't have drive letters to find.

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    I said to look at File, because, if you do getParentFile() until it returns null, the "File" for which it returned null is the root for the File you started with.

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by masijade View Post
    I said to look at File, because, if you do getParentFile() until it returns null, the "File" for which it returned null is the root for the File you started with.
    Yes, that's a nice approach. How should I forget that getParentFile() :( . But still I'm not clear what our thread starter is looking.

Similar Threads

  1. How to create Folder View
    By jazz2k8 in forum Advanced Java
    Replies: 2
    Last Post: 10-24-2008, 02:04 PM
  2. want to run my code from any folder ?
    By Shyam Singh in forum New To Java
    Replies: 1
    Last Post: 08-12-2008, 01:31 PM
  3. folder cloning
    By jad in forum Advanced Java
    Replies: 1
    Last Post: 07-01-2008, 12:28 AM
  4. add password to folder
    By ismailsaleh in forum AWT / Swing
    Replies: 1
    Last Post: 01-08-2008, 05:46 AM
  5. creation of new folder in the mail
    By an8086 in forum Advanced Java
    Replies: 1
    Last Post: 07-15-2007, 05:10 PM

Posting Permissions

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