im a java beginner (started about 8 weeks ago) and i have a problem. how do you count the number of files from a folder? basically the program that im working on is reading from many different folders and for now, each time i change the name of the folder, i have to manually (from the code) change the number of files in it. is there a way so that i dont have to that everytime? any ideas?
On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name and a last name. The first name can abbreviated by an initial, but not the last name. Since yours does not conform with it, please take a moment to change it, which you can do right here.
As to your question, the java.io.File.listFiles method returns an array of File objects that exist in a given directory. So the length of that array would be the number of files.
Joined: Jun 05, 2008
oh i might have missed reading that. but ive changed it to comply to the rules now..
and thanks. i'll try to check on that. but do you know where i might find examples on how to use it?