java - How to implement JProgressbar for SimpleFileVisitor Class -


i have simple file visitor class scans drives within pc find specific extensions .txt. want display progress of operation jprogressbar. each scan, number of total matched files may change. prevents me calculating percentage of process display on jprogressbar.

my code based on this: recursive pattern matching

how can calculate , display percentage when total number of files changing?

the problem is, not know in advance how many files have. generelly, have option run through file system twice: first time, enter directories , count files.

based on number, can calculate percentage on second run, have @ files itself.

this enlongates process , again not have progress on first scan.

what can do, starting first scan in different thread. assuming pattern matching needs more time counting files, counting faster , can adjust jprogressbar dynamically. start unreliable , become more accurate on time.

i guess aproach similar 1 implemented in windows copy mechanism. scan files first without progress information , start copying progress information. however, may lead effects know windows-machines file operations have information "2 hours left" , after 2 minutes it's done, or vice versa.

edit:

sorry, right noticed want iterate through files on hard drive , not starting in point.

you may sum file size have seen already, if know free , total disk space, can compute percentage done. however, progress not smooth because file sizes tend different.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -