determining the total no of files in the hard disk

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: determining the total no of files in the hard disk

  1. #1
    Join Date
    May 2006

    Question determining the total no of files in the hard disk

    hello all,

    i'm trying to build a desktop search engine using java. i would like to know if there is any way by which i can determine the total number of files in the hard disk. our algorithm doesnt do any indexing as such. each time a search string is entered, the searching of the hard disk is done.

    to enable the progress bar, we need to specify the maximum value. to specify this maximum value, i need to determine the total number of files in the hard disk.

    hoping to get an early reply.


  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    There has to be a way to "visit" each file on the disk and allow the increment of a count, using a combination of the FileSystemView and File class. Looks to me that FileSystemView.getFiles() in conjunction with the other disk traversing methods will return a list of files in each directory, which you can dimension and then delete (if you are just counting).

  3. #3
    Join Date
    Mar 2004
    I think something like this would work, however it'd probably be slow.

    File root = new File("C:/");
    public int countFiles(File file)
         File[] files = file.listFiles();
         int count = files.length;
         for(int i=0; i<files.count;i++)
              if (files[i].isDirectory())
                   count += countFiles(files[i]);
         return count;

  4. #4
    Join Date
    May 2006

    Thumbs up thanks :)


    thanks a lot for reading my problem and giving replies.. it helped me a lot and i was successful in determining the total number of files.

    thanks once again!


Similar Threads

  1. Replies: 1
    Last Post: 12-08-2005, 08:02 PM
  2. need to return total record count, but here is the trick...
    By barbarosa80503 in forum VB Classic
    Replies: 2
    Last Post: 10-28-2005, 03:33 PM
  3. accessing hard disk with webstart
    By ozmanbozman in forum Java
    Replies: 1
    Last Post: 05-02-2005, 05:36 PM
  4. Replies: 1
    Last Post: 08-02-2004, 03:00 PM
  5. Backup of exchage data in a hard disk
    By precious in forum Enterprise
    Replies: 1
    Last Post: 11-24-2000, 07:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center