📄 file::find.3
字号:
is worse than just taking time, the option \fIfollow\fR should be used..SpThis is also a no-op on Win32..ie n .IP """follow_skip""" 3.el .IP "\f(CWfollow_skip\fR" 3.IX Item "follow_skip"\&\f(CW\*(C`follow_skip==1\*(C'\fR, which is the default, causes all files which areneither directories nor symbolic links to be ignored if they are aboutto be processed a second time. If a directory or a symbolic linkare about to be processed a second time, File::Find dies..Sp\&\f(CW\*(C`follow_skip==0\*(C'\fR causes File::Find to die if any file is about to beprocessed a second time..Sp\&\f(CW\*(C`follow_skip==2\*(C'\fR causes File::Find to ignore any duplicate files anddirectories but to proceed normally otherwise..ie n .IP """dangling_symlinks""" 3.el .IP "\f(CWdangling_symlinks\fR" 3.IX Item "dangling_symlinks"If true and a code reference, will be called with the symbolic linkname and the directory it lives in as arguments. Otherwise, if trueand warnings are on, warning \*(L"symbolic_link_name is a danglingsymbolic link\en\*(R" will be issued. If false, the dangling symbolic linkwill be silently ignored..ie n .IP """no_chdir""" 3.el .IP "\f(CWno_chdir\fR" 3.IX Item "no_chdir"Does not \f(CW\*(C`chdir()\*(C'\fR to each directory as it recurses. The \f(CW\*(C`wanted()\*(C'\fRfunction will need to be aware of this, of course. In this case,\&\f(CW$_\fR will be the same as \f(CW$File::Find::name\fR..ie n .IP """untaint""" 3.el .IP "\f(CWuntaint\fR" 3.IX Item "untaint"If find is used in taint-mode (\-T command line switch or if \s-1EUID\s0 != \s-1UID\s0or if \s-1EGID\s0 != \s-1GID\s0) then internally directory names have to be untaintedbefore they can be chdir'ed to. Therefore they are checked against a regularexpression \fIuntaint_pattern\fR. Note that all names passed to the user's\&\fI\fIwanted()\fI\fR function are still tainted. If this option is used whilenot in taint-mode, \f(CW\*(C`untaint\*(C'\fR is a no-op..ie n .IP """untaint_pattern""" 3.el .IP "\f(CWuntaint_pattern\fR" 3.IX Item "untaint_pattern"See above. This should be set using the \f(CW\*(C`qr\*(C'\fR quoting operator.The default is set to \f(CW\*(C`qr|^([\-+@\ew./]+)$|\*(C'\fR.Note that the parentheses are vital..ie n .IP """untaint_skip""" 3.el .IP "\f(CWuntaint_skip\fR" 3.IX Item "untaint_skip"If set, a directory which fails the \fIuntaint_pattern\fR is skipped,including all its sub-directories. The default is to 'die' in such a case..Sh "The wanted function".IX Subsection "The wanted function"The \f(CW\*(C`wanted()\*(C'\fR function does whatever verifications you want oneach file and directory. Note that despite its name, the \f(CW\*(C`wanted()\*(C'\fRfunction is a generic callback function, and does \fBnot\fR tellFile::Find if a file is \*(L"wanted\*(R" or not. In fact, its return valueis ignored..PPThe wanted function takes no arguments but rather does its workthrough a collection of variables..ie n .IP "$File::Find::dir is the current directory name," 4.el .IP "\f(CW$File::Find::dir\fR is the current directory name," 4.IX Item "$File::Find::dir is the current directory name,".PD 0.ie n .IP "$_ is the current filename within that directory" 4.el .IP "\f(CW$_\fR is the current filename within that directory" 4.IX Item "$_ is the current filename within that directory".ie n .IP "$File::Find::name is the complete pathname to the file." 4.el .IP "\f(CW$File::Find::name\fR is the complete pathname to the file." 4.IX Item "$File::Find::name is the complete pathname to the file.".PD.PPThe above variables have all been localized and may be changed withouteffecting data outside of the wanted function..PPFor example, when examining the file \fI/some/path/foo.ext\fR you will have:.PP.Vb 3\& $File::Find::dir = /some/path/\& $_ = foo.ext\& $File::Find::name = /some/path/foo.ext.Ve.PPYou are \fIchdir()\fR'd to \f(CW$File::Find::dir\fR when the function is called,unless \f(CW\*(C`no_chdir\*(C'\fR was specified. Note that when changing todirectories is in effect the root directory (\fI/\fR) is a somewhatspecial case inasmuch as the concatenation of \f(CW$File::Find::dir\fR,\&\f(CW\*(Aq/\*(Aq\fR and \f(CW$_\fR is not literally equal to \f(CW$File::Find::name\fR. Thetable below summarizes all variants:.PP.Vb 4\& $File::Find::name $File::Find::dir $_\& default / / .\& no_chdir=>0 /etc / etc\& /etc/x /etc x\&\& no_chdir=>1 / / /\& /etc / /etc\& /etc/x /etc /etc/x.Ve.PPWhen <follow> or <follow_fast> are in effect, there isalso a \f(CW$File::Find::fullname\fR. The function may set\&\f(CW$File::Find::prune\fR to prune the tree unless \f(CW\*(C`bydepth\*(C'\fR wasspecified. Unless \f(CW\*(C`follow\*(C'\fR or \f(CW\*(C`follow_fast\*(C'\fR is specified, forcompatibility reasons (find.pl, find2perl) there are in addition thefollowing globals available: \f(CW$File::Find::topdir\fR,\&\f(CW$File::Find::topdev\fR, \f(CW$File::Find::topino\fR,\&\f(CW$File::Find::topmode\fR and \f(CW$File::Find::topnlink\fR..PPThis library is useful for the \f(CW\*(C`find2perl\*(C'\fR tool, which when fed,.PP.Vb 2\& find2perl / \-name .nfs\e* \-mtime +7 \e\& \-exec rm \-f {} \e; \-o \-fstype nfs \-prune.Ve.PPproduces something like:.PP.Vb 10\& sub wanted {\& /^\e.nfs.*\ez/s &&\& (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_)) &&\& int(\-M _) > 7 &&\& unlink($_)\& ||\& ($nlink || (($dev, $ino, $mode, $nlink, $uid, $gid) = lstat($_))) &&\& $dev < 0 &&\& ($File::Find::prune = 1);\& }.Ve.PPNotice the \f(CW\*(C`_\*(C'\fR in the above \f(CW\*(C`int(\-M _)\*(C'\fR: the \f(CW\*(C`_\*(C'\fR is a magicalfilehandle that caches the information from the preceding\&\f(CW\*(C`stat()\*(C'\fR, \f(CW\*(C`lstat()\*(C'\fR, or filetest..PPHere's another interesting wanted function. It will find all symboliclinks that don't resolve:.PP.Vb 3\& sub wanted {\& \-l && !\-e && print "bogus link: $File::Find::name\en";\& }.Ve.PPSee also the script \f(CW\*(C`pfind\*(C'\fR on \s-1CPAN\s0 for a nice application of thismodule..SH "WARNINGS".IX Header "WARNINGS"If you run your program with the \f(CW\*(C`\-w\*(C'\fR switch, or if you use the\&\f(CW\*(C`warnings\*(C'\fR pragma, File::Find will report warnings for several weirdsituations. You can disable these warnings by putting the statement.PP.Vb 1\& no warnings \*(AqFile::Find\*(Aq;.Ve.PPin the appropriate scope. See perllexwarn for more info about lexicalwarnings..SH "CAVEAT".IX Header "CAVEAT".ie n .IP "$dont_use_nlink" 2.el .IP "\f(CW$dont_use_nlink\fR" 2.IX Item "$dont_use_nlink"You can set the variable \f(CW$File::Find::dont_use_nlink\fR to 1, if you want toforce File::Find to always stat directories. This was used for file systemsthat do not have an \f(CW\*(C`nlink\*(C'\fR count matching the number of sub-directories.Examples are \s-1ISO\-9660\s0 (CD-ROM), \s-1AFS\s0, \s-1HPFS\s0 (\s-1OS/2\s0 file system), \s-1FAT\s0 (\s-1DOS\s0 filesystem) and a couple of others..SpYou shouldn't need to set this variable, since File::Find should now detectsuch file systems on-the-fly and switch itself to using stat. This works evenfor parts of your file system, like a mounted CD-ROM..SpIf you do set \f(CW$File::Find::dont_use_nlink\fR to 1, you will notice slow-downs..IP "symlinks" 2.IX Item "symlinks"Be aware that the option to follow symbolic links can be dangerous.Depending on the structure of the directory tree (including symboliclinks to directories) you might traverse a given (physical) directorymore than once (only if \f(CW\*(C`follow_fast\*(C'\fR is in effect).Furthermore, deleting or changing files in a symbolically linked directorymight cause very unpleasant surprises, since you delete or change filesin an unknown directory..SH "NOTES".IX Header "NOTES".IP "\(bu" 4Mac \s-1OS\s0 (Classic) users should note a few differences:.RS 4.IP "\(bu" 4The path separator is ':', not '/', and the current directory is denotedas ':', not '.'. You should be careful about specifying relative pathnames.While a full path always begins with a volume name, a relative pathnameshould always begin with a ':'. If specifying a volume name only, atrailing ':' is required..IP "\(bu" 4\&\f(CW$File::Find::dir\fR is guaranteed to end with a ':'. If \f(CW$_\fRcontains the name of a directory, that name may or may not end with a\&':'. Likewise, \f(CW$File::Find::name\fR, which contains the completepathname to that directory, and \f(CW$File::Find::fullname\fR, which holdsthe absolute pathname of that directory with all symbolic links resolved,may or may not end with a ':'..IP "\(bu" 4The default \f(CW\*(C`untaint_pattern\*(C'\fR (see above) on Mac \s-1OS\s0 is set to\&\f(CW\*(C`qr|^(.+)$|\*(C'\fR. Note that the parentheses are vital..IP "\(bu" 4The invisible system file \*(L"Icon\e015\*(R" is ignored. While this file mayappear in every directory, there are some more invisible system fileson every volume, which are all located at the volume root level (i.e.\&\*(L"MacintoshHD:\*(R"). These system files are \fBnot\fR excluded automatically.Your filter may use the following code to recognize invisible files ordirectories (requires Mac::Files):.Sp.Vb 1\& use Mac::Files;\&\& # invisible() \-\- returns 1 if file/directory is invisible,\& # 0 if it\*(Aqs visible or undef if an error occurred\&\& sub invisible($) {\& my $file = shift;\& my ($fileCat, $fileInfo);\& my $invisible_flag = 1 << 14;\&\& if ( $fileCat = FSpGetCatInfo($file) ) {\& if ($fileInfo = $fileCat\->ioFlFndrInfo() ) {\& return (($fileInfo\->fdFlags & $invisible_flag) && 1);\& }\& }\& return undef;\& }.Ve.SpGenerally, invisible files are system files, unless an odd applicationdecides to use invisible files for its own purposes. To distinguishsuch files from system files, you have to look at the \fBtype\fR and \fBcreator\fRfile attributes. The MacPerl built-in functions \f(CW\*(C`GetFileInfo(FILE)\*(C'\fR and\&\f(CW\*(C`SetFileInfo(CREATOR, TYPE, FILES)\*(C'\fR offer access to these attributes(see MacPerl.pm for details)..SpFiles that appear on the desktop actually reside in an (hidden) directorynamed \*(L"Desktop Folder\*(R" on the particular disk volume. Note that, althoughall desktop files appear to be on the same \*(L"virtual\*(R" desktop, each diskvolume actually maintains its own \*(L"Desktop Folder\*(R" directory..RE.RS 4.RE.SH "BUGS AND CAVEATS".IX Header "BUGS AND CAVEATS"Despite the name of the \f(CW\*(C`finddepth()\*(C'\fR function, both \f(CW\*(C`find()\*(C'\fR and\&\f(CW\*(C`finddepth()\*(C'\fR perform a depth-first search of the directoryhierarchy..SH "HISTORY".IX Header "HISTORY"File::Find used to produce incorrect results if called recursively.During the development of perl 5.8 this bug was fixed.The first fixed version of File::Find was 1.01.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -