- 浏览: 399948 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 1086order of lib imports in ... -
不安装Visual Studio,只用Windows SDK搭建VC环境
2013-12-31 21:52 15342首先你需要下载的是 Microsoft Windows S ... -
联想A798T刷机实战
2013-10-13 20:05 1277刷机的基本准备 一些 ... -
Office – 管理 Master-Subdocument
2013-06-29 17:29 823标题: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 487you 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 816on 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 863As 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 665it is more powerful to design y ... -
tools - vim to increment/decrement number under cursor
2012-09-13 21:35 842in 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 436There are some registry that ca ... -
VS - tips some useful command tips to Visual Sudio
2012-08-27 12:15 694Set as Startup Project How ...
相关推荐
"exfat-utils-1.0.1.tar.gz" 是一个包含ExFAT实用程序的源码包,版本号为1.0.1。这个压缩包提供了在Linux环境下操作ExFAT文件系统所需的各种工具,如格式化、挂载和检查ExFAT分区。使用tar命令解压后,我们可以得到...
alsa-utils
在给定的场景中,`java-property-utils-1.9.1.jar` 和 `java-property-utils-1.10.jar` 是这个库的两个不同版本,它们被用在Tomcat服务器上进行跨域设置。在Web开发中,跨域问题是一个常见的挑战,它涉及到浏览器的...
3. 接下来,解压mtd-utils-1.5.0.tar.bz2,进入目录,运行`./configure`(可能需要指定lzo和zlib的安装路径),之后执行`make`和`sudo make install`。 4. 安装完成后,你可以使用新安装的mtd-utils工具,如`flash_...
【nfs-utils.tar.gz】是一个包含NFS(Network File System)工具的离线安装包,主要服务于Linux系统,用于实现不同计算机之间的文件共享。NFS是一种标准的协议,允许一台计算机(客户端)透明地访问另一台计算机...
[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包: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文档...
标题 "HDP-UTILS-1.1.0.22-centos7.tar.gz" 提供的是一个软件包的名称,这通常代表了一个特定版本的工具集合,用于在CentOS 7操作系统上与Hadoop Distributed File System (HDFS)相关的操作。HDP全称为Hortonworks ...
离线安装nfs-utils用,安装nfs-utils所需依赖也都在里面 复制到服务器后直接执行以下命令即可顺利安装: sudo rpm -ivh *.rpm --force --nodeps sudo systemctl start rpcbind sudo systemctl enable rpcbind ...
《Linux系统中的BlueZ-utils-3.36:蓝牙功能移植与应用详解》 在Linux操作系统的世界里,蓝牙技术的运用日益广泛,特别是在设备间的数据传输、无线音频播放以及物联网(IoT)设备的交互中扮演着关键角色。BlueZ是...
linux centos7.5 nfs-utils 网络共享资源离线rpm安装包,包括nfs-utils 的依赖包,方便使用
这个压缩包中的【jszip-utils-master】目录很可能是项目的源代码仓库,用户可以从中获取到完整的项目结构和相关代码。 首先,我们要了解JSZIP库的核心功能。JSZIP能够处理二进制数据,如Base64编码、Blob对象或...
赠送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-...
1. 下载源码:首先从官方网站或者镜像站点获取nfs-utils 2.4.3的源代码包,解压到本地目录,例如`tar -zxvf nfs-utils-2.4.3.tar.gz`。 2. 配置源码:执行`./configure`命令,配置编译选项。针对ARM平台,可能需要...
maven-shared-utils-3.2.1.jar
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...
cifs-utils-4.8.1-10.el6.i686.rpm是centos工具包。
webgl函数库(cuon-matrix、cuon-utils、webgl-debug、webgl-utils) webgl公共函数
本文将深入探讨"Xorg-x11-server-utils-7.5.zip"这个压缩包所包含的Xorg X11服务器工具集,以及与之相关的知识点。 Xorg X11 Server是X Window系统的核心组件,负责管理显示器、键盘和鼠标等输入输出设备,为用户...
在这个"cors-filter-2.5 + java-property-utils-1.9.1.zip"压缩包中,主要包含了两个关键组件:CORS Filter和Java Property Utils。 1. CORS Filter: CORS Filter是处理跨域请求的一种解决方案,它作为一个...