Results 1 to 12 of 12
Thread: directory file list....
- 05-19-2010, 01:11 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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
- 05-19-2010, 01:58 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 266
- Rep Power
- 4
Your approach should work. print our your string_variable and make sure it's a good path.
- 05-19-2010, 02:03 AM #3
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?
- 05-19-2010, 11:13 AM #4
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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.
- 05-19-2010, 12:02 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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?
- 05-19-2010, 02:22 PM #6
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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 ()"
- 05-19-2010, 02:52 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 05-19-2010, 04:45 PM #8
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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....
- 05-19-2010, 04:52 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 05-19-2010, 04:54 PM #10
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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
- 05-19-2010, 05:04 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Rule 1 for sorting out problems, make sure the code is working with the data you think it's working with.
:)
- 05-22-2010, 04:19 PM #12
Member
- Join Date
- Mar 2010
- Posts
- 13
- Rep Power
- 0
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
-
List directory
By dman in forum New To JavaReplies: 4Last Post: 08-21-2009, 01:32 AM -
Populating a gui list box with the files in a directory
By josejvelezcolon in forum New To JavaReplies: 1Last Post: 08-10-2009, 04:50 PM -
how to list certain files in a given directory in java
By corpusluteum in forum New To JavaReplies: 6Last Post: 09-24-2008, 12:19 AM -
[SOLVED] File chooser selecting file from directory...?
By prabhurangan in forum AWT / SwingReplies: 12Last Post: 06-18-2008, 04:08 AM -
How can I get list of files in a directory
By karma in forum New To JavaReplies: 2Last Post: 12-14-2007, 11:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks