博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Perl Modules about File
阅读量:6608 次
发布时间:2019-06-24

本文共 2530 字,大约阅读时间需要 8 分钟。

hot3.png

文件存取与处理 

Cwd             取得现行工作目录的路径名 
DirHandle       提供处理目录代码的对象方法 
Fcntl           载入C的Fcntl.h中的定义 

File::Basename 分割文件名数据 

File::CheckTree 对一连串文件串做许多测试 
File::Copy      拷贝文件或文件句柄 
File::Find      寻找文件 
File::Path      产生或移除一连串目录 
FileCache       允许打开多于系统限制的文件句柄 
FileHandle      提供处理文件句柄的对象方法 

File::Find

Traverse a directory tree.

find() does a depth-first search over the given @directories in the order they are given.

finddepth() works just like find() except that it invokes the &wanted function for a directory after invoking it for the directory's contents. It does a postorder traversal instead of a preorder traversal, working from the bottom of the directory tree up where find() works from the top of the tree down.

#!/usr/bin/perluse warnings;use strict;use File::Find;print "find():\n";find(\&wanted,'.');print "\n\n";print "finddepth():\n"finddepth(\&wanted,'.');sub wanted {        print $File::Find::name,"\n" if ($_ =~ /^test/);        print "*";}

其中有三个变量:
1.$File::Find::dir  :当前处理的目录名
2.$_                :当前处理的文件名
3.$File::Find::name :目录加文件名
find是在进行目录测试后在进行目录内容的测试。从目录树根往下。

finddepth 是先内容后目录,从叶子往树根。

wanted函数是一个回调函数。回调函数是指:一般不自己调用而是由别的程序调用,这里是由find调用。find两个参数第一个是对遍历到文件的行为,一个是待查找的目录。

%option

The first argument to find() is either a code reference to your &wanted function, or a hash reference describing the operations to be performed for each file. 

  1. wanted : The value should be a code reference. This code reference is described in the wanted function , The &wanted subroutine is mandatory
  2. bydepth Reports the name of a directory only AFTER all its entries have been reported. Entry point finddepth() is a shortcut for specifying { bydepth => 1 } in the first argument offind().
  3. preprocess The value should be a code reference. This code reference is used to preprocess the current directory.The name of the currently processed directory is in $File::Find::dirIt is called with a list of strings (actually file/directory names) and is expected to return a list of strings.The code can be used to sort the file/directory names alphabetically, numerically, or to filter out directory entries based on their name alone. When follow or follow_fast are in effect, preprocess is a no-op(空操作).
  4. postprocessThe value should be a code reference. It is invoked just before leaving the currently processed directory.This hook is handy for summarizing a directory, such as calculating its disk usage. When follow or follow_fast are in effect, postprocess is a no-op.
  5. followCauses symbolic links to be followed
  6. follow_fast:

File::Password

转载于:https://my.oschina.net/u/347414/blog/268051

你可能感兴趣的文章
RecyclerView侧滑删除功能
查看>>
记一个hystrix异常
查看>>
9.02-Spring IOC 容器中Bean的生命周期
查看>>
6.6 tar打包
查看>>
微信自动抢红包的实现(Demo已增加查看TopActivity功能)
查看>>
Spring MVC核心技术
查看>>
TCP协议如何保证传输的可靠性
查看>>
Spring Cloud云架构 - SSO单点登录之OAuth2.0 登出流程(3)
查看>>
编程之美 测试赛 石头剪刀布
查看>>
签名问题
查看>>
软件开发各阶段交付物列表
查看>>
2018-05-24 Linux学习
查看>>
ntp服务器的搭建
查看>>
我的友情链接
查看>>
sysstat 安装
查看>>
六、nginx搭建织梦DedeCms网站
查看>>
Tair学习小记
查看>>
网卡绑定(服务器&&交换机),缓存服务器Squid架构配置
查看>>
web网站加速之CDN(Content Delivery Network)技术原理
查看>>
打算写一款框架来提高自己 写个结构吧
查看>>