简体   繁体   中英

Is there a way to find a list of over a thousand files any faster using File::Find::Rule?

My main directory has a lot of sub folders, each containing over a thousand files. I need to fetch the names of all files with an extension of .xml , aux , or .tex and store them in an array.

use File::Find::Rule;

$path_dir = "d:/testing/Projects/";

my @allfiles = File::Find::Rule->file()->
        name( "*.xml", "*.aux", "*.tex" )->
        in( $path_dir );

print join "\n", @allfiles;

system 'pause';

The above code is working fine but it takes over a minute to run. Is there any way to do this faster?

Try replacing this line:

name( "*.xml", "*.aux", "*.tex" )->

with this:

name( qr/\.(xml|aux|tex)$/ )->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM