- 浏览: 390209 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
in my working environment, the home directory may contains some speical cache directory where you others may not be able to use. So normally we don't want to go through the directory nor we want to display result in that directory;
I am writting a small perl script to help me do that :
use warnings; use strict; use Carp; use File:Find; my $file = pop @ARGV; my $exclude = pop @ARGV || ""; croack "syntax: $0 [\$ignore_prefix] \$file" unless defined $file && $file ne ""; @ARGV = (".") unless @ARGV; find (\$process_file, @ARGV); sub process_file { if ($exclude ne "") { if ($File::Find::name !~ /^(?:$exclude)/ && $File::Find::name =~ /$file) { print $File::Find::name, "\n"; } } elsif ($File::Find::name =~ /$file/) { print $File::Find::name, "\n"; } }
However, I used to think that it might work if I use the expression and use the negative lookback assertion (anchor), and I wrote the following code.
sub process_file { if ($exclude ne "") { if ($File::Find::name =~ /^(?<!$exclude).*$file)/) { print $File::Find::name, "\n"; } elsif ($File::Find::name =~ /$file/) { print $File::Find::name, "\n"; } } }
Guess why, given a pattern which is ./.oldFiles/anyfile, if the $exclude = ./.oldFiles, and $file = anyfile, the problem it is some greedy match, so .* may extend to matched hte ./.oldFiles. so you end up errors.
the above code works in a callback manner, where it goes to every folder and check if that current check file matches, sometimes we don't want to go into some folder (due to permission or performanc), we can choose to use readdir, opendir, rewinddir calles.
here is the code:
use strict; use Carp; # from Metacpan.org # https://metacpan.org/module/IO::File # File::Fu - File and directory objects # more details on opendir # http://perldoc.perl.org/functions/opendir.html # more details on readdir # http://perldoc.perl.org/functions/readdir.html my $file = pop @ARGV; my $exclude = pop @ARGV || ""; croak "$0: \$[exclude_file] \$[file]" unless defined $file && $file ne ""; process_dir("."); sub process_dir { my $dir = shift; return unless defined $dir; opendir (my $d_h, $dir) || die "Cannot open $dir $!"; if ($exclude ne "") { my @files = grep { -f "$dir/$_" && !/$exclude/ && /$file/ } readdir($d_h); for my $match (@files) { print "$dir/$match", "\n"; } rewinddir($d_h); my @sub_dirs = grep { -d "$dir/$_" && !/^\.$/ && !/^\.\.$/ && !/$exclude/} readdir($d_h); for my $sub_dir (@sub_dirs) { process_dir($dir . "/" . $sub_dir); } } else { my @files = grep { -f "$dir/$_" && /$file/ } readdir ($d_h); for my $match (@files) { print "$dir/$match", "\n"; } rewinddir($d_h); my @sub_dirs = grep { -d "$dir/$_" && !/^\.$/ && !/^\.\.$/} readdir($d_h); for my $sub_dir (@sub_dirs) { process_dir($dir . "/" . $sub_dir); } } }
发表评论
-
gcc,pkg-config,libyaml and etc..
2014-04-14 09:36 1016order of lib imports in ... -
不安装Visual Studio,只用Windows SDK搭建VC环境
2013-12-31 21:52 15290首先你需要下载的是 Microsoft Windows S ... -
联想A798T刷机实战
2013-10-13 20:05 1224刷机的基本准备 一些 ... -
Office – 管理 Master-Subdocument
2013-06-29 17:29 798标题:Office – 管理Master-Subdocum ... -
svn - what is SVN and how to get started
2013-04-23 15:05 0What is the SVN: 1. What is ... -
tools - gpupdate to update the group policy settings
2012-11-20 17:23 461you can update your local group ... -
Exceed to remote connect to Linux box
2012-11-13 17:58 364in this post, I will introduce ... -
Cmd - Remove directories on Windows
2012-10-31 11:18 763on windows, there is no rm -rf ... -
tools - shell script example 1
2012-10-16 17:17 0#! /ms/dist/fsf/PROJ/bash/lo ... -
tools - .net 4.0 related tools patch
2012-09-24 12:43 804As the tools in .net 4.0 has em ... -
c# - Teamcity ldap integration
2012-09-21 14:31 727CI is becoming more and more th ... -
c# - class designer: facilitate your design work
2012-09-14 15:04 633it is more powerful to design y ... -
tools - vim to increment/decrement number under cursor
2012-09-13 21:35 802in VIM, you can do increment or ... -
tool - internal filter commands/concepts/tools
2012-09-13 11:13 0General Command to use to pu ... -
Tool - tip on the registry to enable quick search on search bar
2012-08-31 09:54 412There are some registry that ca ... -
VS - tips some useful command tips to Visual Sudio
2012-08-27 12:15 661Set as Startup Project How ...
相关推荐
赠送jar包:hk2-utils-2.4.0-b34.jar; 赠送原API文档:hk2-utils-2.4.0-b34-javadoc.jar; 赠送源代码:hk2-utils-2.4.0-b34-sources.jar; 赠送Maven依赖信息文件:hk2-utils-2.4.0-b34.pom; 包含翻译后的API文档...
赠送jar包:hk2-utils-2.4.0-b34.jar; 赠送原API文档:hk2-utils-2.4.0-b34-javadoc.jar; 赠送源代码:hk2-utils-2.4.0-b34-sources.jar; 赠送Maven依赖信息文件:hk2-utils-2.4.0-b34.pom; 包含翻译后的API文档...
Tomcat 在设置跨域 jar包的二部分,java-property-utils-1.9.1.jar,java-property-utils-1.10.jar
linux centos7.5 nfs-utils 网络共享资源离线rpm安装包,包括nfs-utils 的依赖包,方便使用
exfat 文件系统linux格式化代码,非常好用,直接交叉编译,就能使用,快速格式化代码
maven-shared-utils-3.2.1.jar
nfs离线安装包,也可通过离线命令下载到本地目录: yum -y install --downloadonly --downloaddir /root/nfs nfs-utils
nfs-utils及相关依赖rpm,用于离线安装nfs-utils。
xorg-x11-server-utils-7.5-13.el6.x86_64.rpm
里面包含安装mtd-utils所有涉及到的安装包,给具有同样需求的人方便: mtd-utils-1.5.0.tar.bz2 lzo-2.06.tar.gz zlib-1.2.8.tar.gz
[root@localhost yum-utils]# rpm -e --nodeps yum-utils-1.1.31-40.el7.noarch 上传离线版本包并解压 安装 [root@localhost yum-utils]# rpm -ivh yum-utils-1.1.31-50.el7.noarch.rpm 查看更新版本 [root@...
赠送jar包:qrcode-utils-1.1.jar; 赠送原API文档:qrcode-utils-1.1-javadoc.jar; 赠送源代码:qrcode-utils-1.1-sources.jar; 赠送Maven依赖信息文件:qrcode-utils-1.1.pom; 包含翻译后的API文档:qrcode-...
离线安装amabri-2.7.4,之 HDP-UTILS-1.1.0.22-centos7.tar.gz
alsa-lib alsa-utils 在android编译成功 warning: shared library text segment is not shareable error: treating warnings as errors 编译器的选项要加上 --no-fatal-warnings 可无论怎么加, 加到那儿都变成了...
alsa-utils-1.0.25 和alsa-utils-0.0.5版本包括lib库
Hashcat-utils are a set of small utilities that are useful in advanced password cracking Brief description They all are packed into multiple stand-alone binaries. All of these utils are designed to...
json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码json-utils最新代码...
mtd-utils-2.0.2.tar.bz2 在使用openwrt进行编译的时候很容易出现下载 mtd-utils-2.0.2.tar.bz2 失败,那么就将该资源下载后放到openwrt/dl/文件夹下面
前端项目-jszip-utils,与JSZIP一起使用的跨浏览器实用程序集合。
适用于centos6的iscsi target安装包,用来配置iscsi服务端。 安装方法:rpm -ivh scsi-target-utils-1.0.24-18.el6.x86_64.rpm