Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

counting files

 
Steve Matthews
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic