Results 1 to 12 of 12
  1. #1
    viewer is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default directory file list....

    hello.....

    i have problem with getting file list from directory.
    normally, if i gave path string, i can get.
    "]File main_dir = new File ("C:");"
    but i want to get file list with using string variable....
    "File temp_dir = new File (string_variable);"
    string_variable comes from a jtree.
    when i did, it returned empty, there was no array.

    soneone know how can i do?

    regards

  2. #2
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    Your approach should work. print our your string_variable and make sure it's a good path.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Please put the code in a short program to demo your problem.

    The source of a string for the File() parameter should have no bearing on the results.
    Do a println() of the string_variable that you are using to see what the problem is.

    What is returned by File.list() when there is nothing in the directory? or the File is not a directory?

  4. #4
    viewer is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    String temp_string = null;
    String temp_path=jTree1.getSelectionPath().toString();
    for (int counnt=0;counnt<temp_path.length();counnt++ ){
    char control;
    control=temp_path.charAt(counnt);
    if (control==(char)(44)){
    temp_string = temp_string +(char)(92)+(char)(92);
    }
    else{
    if (control!= (char)(91)) {
    if (control!= (char)(93)) {
    if (counnt==1) {
    temp_string = Character.toString(control);
    }
    else{
    temp_string = temp_string + Character.toString(control);
    }
    }
    }
    }
    }
    temp_path = temp_string;

    JOptionPane.showMessageDialog(jComboBox1,temp_path , "selection chanced", WIDTH);


    DefaultMutableTreeNode temp_node = (DefaultMutableTreeNode)jTree1.getLastSelectedPath Component();
    DefaultTreeModel temp_model = (DefaultTreeModel)jTree1.getModel();
    int plc = temp_model.getIndexOfChild(temp_model.getRoot(), temp_node);
    JOptionPane.showMessageDialog(jComboBox1,Integer.t oString(plc), " get selection", WIDTH);

    File temp_dir=new File(temp_string);
    File[] temp_dir_list = temp_dir.listFiles();
    JOptionPane.showMessageDialog(jComboBox1,Integer.t oString(temp_dir_list.length), "control", WIDTH);
    String [] temp_dir_files = temp_dir.list();
    int xcount= temp_dizin_list.length;


    code is that....
    jtree model is non hidden folders list
    i wanna create child model under model selection.
    with non hidden folders..
    files at selected directory will list at list box.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Print the value of temp_path or temp_string before doing the File part.

    What are you doing to the string at the top there?

  6. #6
    viewer is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Print the value of temp_path or temp_string before doing the File part.

    What are you doing to the string at the top there?
    what can i do?.....
    i see string with messagedialogbox.....
    there is no problem at there normally...
    the string comes from jtee include ";" between every subfolder....
    i checked them and change then with "\\" in a loop....
    i use temp_string for create new "formal path string"
    string formally corect...
    if i write same string at code as manually....
    there is no problem...
    it works well...
    but i can not transfer this string as variable to "new File ()"

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    And the value is?

    I haven't used JTree before, so wasn't sure what you got back...but I would bet that there's something up with that formatting process you're doing. So print out the value of the string.

  8. #8
    viewer is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    C:\\ uif2iso -> println result of string after my loop
    i do not understand......
    there is space....
    i do not see when i dispaly same string with showmessagedialog....

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    There you go.
    Figure out why that speace is appearing and you might have your answer.
    Find out what it looks like when it comes out of the JTree...something like println("#" + string + "#"). The '#'s are to show up spaces.

    If it's not there out of the JTree then you've added it somehow.

  10. #10
    viewer is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    i added an extra case for spaces to my loop...
    string look like ex one but works this time...
    thanks a lot for everyone....
    who care me.....
    who read my messages...
    who write answer...

    with my best regards

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default

    Rule 1 for sorting out problems, make sure the code is working with the data you think it's working with.
    :)

  12. #12
    viewer is offline Member
    Join Date
    Mar 2010
    Posts
    13
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    Rule 1 for sorting out problems, make sure the code is working with the data you think it's working with.
    :)
    you are right....
    i learned it so hard way....
    firm gave me 200 000 records for development and testing....
    i wrote code with them....
    everything worked correctly for them....
    i gave the program to frim...
    when program begun to work with real data (over then 100 million);
    it was broken as glass :D
    next three days, i could not sleep....
    i wrote code again :D
    thanks for everything...

Similar Threads

  1. List directory
    By dman in forum New To Java
    Replies: 4
    Last Post: 08-21-2009, 01:32 AM
  2. Populating a gui list box with the files in a directory
    By josejvelezcolon in forum New To Java
    Replies: 1
    Last Post: 08-10-2009, 04:50 PM
  3. how to list certain files in a given directory in java
    By corpusluteum in forum New To Java
    Replies: 6
    Last Post: 09-24-2008, 12:19 AM
  4. [SOLVED] File chooser selecting file from directory...?
    By prabhurangan in forum AWT / Swing
    Replies: 12
    Last Post: 06-18-2008, 04:08 AM
  5. How can I get list of files in a directory
    By karma in forum New To Java
    Replies: 2
    Last Post: 12-14-2007, 11:20 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
  •