file-find

Is there a cleaner way for File::Find to return a list of wanted files?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:28:45
问题 I find the design choice behind File::Find::find a little surprising. The examples I've come across all show find used in void context. The documentation also clarifies that the \&wanted coderef in find( \&wanted, @dirs ) is not meant to be a filter (emphasis my own): The wanted() function does whatever verifications you want on each file and directory. Note that despite its name, the wanted() function is a generic callback function, and does not tell File::Find if a file is "wanted" or not.

Yii2: Finding file and getting path in a directory tree

六月ゝ 毕业季﹏ 提交于 2019-12-10 22:04:45
问题 I'm trying to search for a single filename in a bunch of directories and returning its path. I thought FileHelper::findFiles() would be a helping hand but it seems it doesn't accept a filename to search for but just a particular root directory and then it returns an array of found filenames. Anyone who knows another Yii2 helper to accomplish this? 回答1: You should simply try: $files = yii\helpers\FileHelper::findFiles('/path', [ 'only' => ['filename.ext'], 'recursive' => true, ]); Read more

When using Perl's File::Find what's a quick & easy way to limit search depth?

家住魔仙堡 提交于 2019-12-10 18:59:16
问题 I want to be able to limit Perl's File::Find to a directory depth (below the specified search) to the specified directory and 1 & 2 subdirectories beneath it. I want to be able to enumerate the files at the same time, if this is possible. It must work with absolute paths. 回答1: This perlmonks node explains how to implement mindepth and maxdepth from GNU's find. Basically, they count the number of slashes in a directory, and use that to determine the depth. The preprocess function will then

How can I make Perl's File::Find faster?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 10:57:46
问题 I have a folder named Lib and I am using the File::Find module to search that folder in whole dir say, D:\ . It's taking a long time to search, say even 5 mins if the drive has a lot of subdirectories. How can I search that Lib faster so it will be done in seconds? My code looks like this: find( \&Lib_files, $dir); sub Lib_files { return unless -d; if ($_=~m/^([L|l]ib(.*))/) { print"$_"; } return; } 回答1: Searching the file system without a preexisting index is IO bound. Otherwise, products

How do I pass parameters to the File::Find subroutine that processes each file?

点点圈 提交于 2019-12-01 14:04:44
问题 Using File::Find, how can I pass parameters to the function that processes each file? I have a Perl script that traverses directories in order to convert some 3-channel TIFF files to JPEG files (3 JPEG files per TIFF file). This works, but I would like to pass some parameters to the function that processes each file (short of using global variables). Here is the relevant part of the script where I have tried to pass the parameter: use File::Find; sub findFiles { my $IsDryRun2 = ${$_[0]}

perl script to recursively list all filename in directory

流过昼夜 提交于 2019-11-30 08:55:23
I have written following perl script but problem is its always going in else part and reporting not a file. I do have files in the directory which I am giving in input. What am I doing wrong here? My requirement is to recursively visit every file in a directory, open it and read it in a string. But the first part of the logic is failing. #!/usr/bin/perl -w use strict; use warnings; use File::Find; my (@dir) = @ARGV; find(\&process_file,@dir); sub process_file { #print $File::Find::name."\n"; my $filename = $File::Find::name; if( -f $filename) { print " This is a file :$filename \n"; } else {

perl script to recursively list all filename in directory

梦想与她 提交于 2019-11-29 13:37:37
问题 I have written following perl script but problem is its always going in else part and reporting not a file. I do have files in the directory which I am giving in input. What am I doing wrong here? My requirement is to recursively visit every file in a directory, open it and read it in a string. But the first part of the logic is failing. #!/usr/bin/perl -w use strict; use warnings; use File::Find; my (@dir) = @ARGV; find(\&process_file,@dir); sub process_file { #print $File::Find::name."\n";