• Post Reply Bookmark Topic Watch Topic
  • New Topic

folder contains multiple folders

 
pramod reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai all.
i want to display the documents which contains the size more than 150kb.
my problem is ,when the user gives the folder to search the documents,and if the folder contains another folder or multiple folders in it,
how can i iterate the folders till the documents i get?
is there any api support for this?
this must be develop in Swing concept only........




any suggestions appreciate.............
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you got so far and where are you stuck?

For nested folders, you can use recursion.
For filtering files in the JFileChooser you can use FileFilter
 
pramod reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my program contains
one JTextField,
JTextArea,
JButton submit .
if the user enters the folder name in the textfield and clicks the submit button,
the files which are having size more than 150kb should be diplayed in the textarea.........
my problem is
if the user enters a folder1 name, which contains another folder2 in the folder1,
,how can we get the files which are in folder2 ?
i.e the user just enters the folder name and the program should display all the files in that folder and also the subfolder files.

is there any method to iterate the folders until we get the files in the folders.
i am using the JFileChooser.

give me any suggestion to fix the problem ..........

thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JFileChoose will not fit your requirement as you want to display the files in your text area.

Like I said before, you need to use recursion.
Pseudo code:
1) Accept the folder name from the user
2) Create a File object from it
3) Check if the file exists
4) Obtain all children (folders as well as files) for the said file object
5) If the child is a folder, obtain its children.
6) If the child is a file, obtain its size
7) If the size matches your filter criteria append its name to the text area.

Check out the File API. It has methods to list (hint) files as well as methods to find the length (hint) of the file in bytes.
After this, if you are stuck, show us what you have coded and we will help you point in the right direction.
 
pramod reddy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your suggestion.
i tried like what you said,
its working fine.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!