Java – use progress bar in file search

I am writing an application that will search for specific files from the corresponding path During the search process, I need to deploy a progress bar that must run according to the search What should I do? Release the code if possible?

Solution

This is a thorny problem I don't remember seeing any instances of non - indexed searches display progress bars Can anyone prove me wrong

I recommend using the following method (an extension of Benny Hallett's proposal), which may provide more particle size

Suppose you are searching the entire file system for a specific file name pattern (for example, searching for all *. JPG files on / in Unix)

First, divide the progress bar into N parts (where n is the number of directories in the search root path)

Each time you drill down to the directory heirachy, the total process bar length allocated to the parent directory will be divided according to the number of subdirectories it contains When the catalog search is complete, the section assigned to it is added to the progress bar For more details, you can further divide the allocation by the number of file directories in the current directory

This method should ensure that you only need to traverse the directory structure once, and it should better deal with uneven directories (uneven I mean a mix of directories with high and low search costs)

As an example, let's assume a directory structure like this:

/
    clipart
    photos
        family    
        holiday
    wallpapers
        anime
        landscapes

(each indentation indicates a deeper level in the directory tree and assumes that all directory traversals are done alphabetically)

You first look at '/' and see that there are three directories (clip art, photos and wallpaper), so you initially divided the progress bar into one-third

Then, you search the clip art directory, and when finished, update the progress bar to one third Then you go into the internal photos and see that there are two subdirectories This means that when you finish searching for families, you will add one sixth to the progress bar, because there are two subdirectories (family and holidays), and the progress of each subdirectory constitutes one third of the photos assigned

The summary is as follows:

Completed clip art increased by a third

Complete photos / family increase by 1 / 6

Completed photos / vacation increased by 1 / 6

Completed wallpaper / animation increased by one sixth

The completion of wallpaper / landscape increased by one sixth

1.0 (or 100%) in total (ignoring floating point precision)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>