[Perl]找出目录下面以*.zip结尾的文件

原创 2015年07月06日 21:33:15

[Perl]找出目录下面以*.zip结尾的文件

直接上code.

#!perl
use strict;
use warnings;

use File::Find;

my $local_file = "D:\\temp\\log";

sub wanted {
    if ( -f $File::Find::name ) {
        if ( $File::Find::name =~ /\.zip$/ ) {
            print "$File::Find::name\n";
            print "$File::Find::dir\n";
            print "$_\n";
            print "\n\n";  
        }
    }
}

find(\&wanted, $local_file);

print "end\n";

以下為 find 的使用說明:

=begin comment

find(\&wanted, @directories);
find(\%options, @directories);

finddepth(\&wanted, @directories);
finddepth(\%options, @directories);

These are functions for searching through directory trees doing work on each file found similar to the Unix find command.

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.
In fact, its return value is ignored.

The wanted function takes no arguments but rather does its work through a collection of variables.

$File::Find::dir is the current directory name,
$_ is the current filename within that directory
$File::Find::name is the complete pathname to the file.

The above variables have all been localized and may be changed without affecting data outside of the wanted function.

For example, when examining the file /some/path/foo.ext you will have:

$File::Find::dir  = /some/path/
$_                = foo.ext
$File::Find::name = /some/path/foo.ext

Reference:
https://metacpan.org/pod/File::Find#The-wanted-function

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

C++从某个目录中找出某一类型的所有文件

因为需要除了某个路径下的所有图片,因此通过网络搜索等方法完成了这段代码。 #include #include #include #include #include us...

找出指定目录中最大的几个文件

日常我们在管理后台的时候,经常会碰到要找出当前目录中比较大文件,一般要将他们move掉或者直接删除,下面这句脚本即可实现: du -ah . | sort -nrk 1 | head 这个语...

1.作业:找出指定目录下所有.xml文件的相关信息

package com.cavaness.quartzbook.chapter3; import java.io.File; import java.io.FileFilter; import ja...

将文件夹下面的文件打包成zip

package cn.gov.csrc.base.util; import java.io.BufferedInputStream; import java.io.BufferedOutputSt...

用Perl动态建立ZIP压缩文件

Perl提供大量处理不同文件格式的内置函数和外来模块。特别是,它可以通过Archive::Zip模块,动态建立和阅读ZIP压缩文件,而不必依赖外来工具和实用工具。本教程说明这个模块的基础理论和常用方法...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)