DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    4

    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.

    regards,
    djshanx.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    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
    Posts
    635
    I think something like this would work, however it'd probably be slow.

    Code:
    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
    Posts
    4

    Thumbs up thanks :)

    hello,

    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!

    Regards,
    djshanx.

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

Bookmarks

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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links