my dog learned polymorphism*
The moose likes Beginning Java and the fly likes counting files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "counting files" Watch "counting files" New topic
Author

counting files

Steve Matthews
Greenhorn

Joined: Apr 18, 2002
Posts: 6
Dear members
I would like to know of an easy way to count the number of files (not directories) within a given folder. Is there such a method available within the 'file' class ?
Thanks,
Steve
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
bigSteve -
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I know the File class has methods that allow you to do that. You will create a File object and have it reference the directory you want to list, and then loop through the object listing all the file. You can even filter for specific extensions if you need to. Check the API for more details.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
arun mahajan
Ranch Hand

Joined: Dec 07, 2001
Posts: 305
If I coould remember properly there is a metod listFiles which gives the array of files but it includes the directory also you can seggrate them by using either isDirectory or isFile method..I am not sure if it counts for the files 7 directory of its subfolder or not.
regards,
Arun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: counting files
 
Similar Threads
Can I add folder in WEB-INF/lib ?
monitoring querys
how we integrate ?
java API
renameTo() problem