免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2197 | 回复: 8
打印 上一主题 下一主题

关于查找文件路径和名字的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-02-17 11:08 |只看该作者 |倒序浏览
大家好。。我想问个问题。。。比如我有文件夹A,里面有3个文件分别是1.txt 2.txt 3.txt并且在A文件夹中有一个文件夹B,B中有3个文件4.txt 5.txt. 6.txt文件夹B中有个文件夹C里面也有3个文件7.txt 8.txt 9.txt
我就是想问这种文件夹套文件夹时。我如何可以得到所有A中包含着的文件名字和目录。。就是1-9.txt我都要得到这些文件名字和路径。。我该如何处理。。谢谢。。

论坛徽章:
2
CU大牛徽章
日期:2013-04-17 11:46:28CU大牛徽章
日期:2013-04-17 11:46:39
2 [报告]
发表于 2013-02-17 11:17 |只看该作者

论坛徽章:
0
3 [报告]
发表于 2013-02-17 11:19 |只看该作者
$ find -type f |grep "pl"
./.cpan/build/Crypt-OICQ-1.1-LFMGTj/test.pl
./1.pl
./2.pl
./3.pl
./cobrawgl.pl
./ly5066113.pl
./manson/login.pl
./manson/LWP/basicauth.pl
./manson/LWP/get.pl
./manson/LWP/HTTP.pl
./manson/LWP/POST.pl
./manson/test.pl
./test.pl
./ttt.pl

论坛徽章:
0
4 [报告]
发表于 2013-02-17 15:55 |只看该作者

论坛徽章:
1
数据库技术版块每日发帖之星
日期:2016-06-23 06:20:00
5 [报告]
发表于 2013-02-18 09:48 |只看该作者
find . -type f -name "*.txt" -print

论坛徽章:
0
6 [报告]
发表于 2013-02-18 10:29 |只看该作者
谢谢。我去看下回复 2# cdtits


   

论坛徽章:
0
7 [报告]
发表于 2013-02-18 10:30 |只看该作者
谢谢,我去看下回复 4# ludio333


   

论坛徽章:
0
8 [报告]
发表于 2013-02-18 13:02 |只看该作者
为何不谢我呢?
$ cat find.pl
#!perl

use File::Find;
use Cwd;

find(\&wanted, '/home/he');

sub wanted {
my $curdir;

    $curdir = getcwd();
    next if /^\./;
    print "$curdir/$_\n" if(-f && /\d\.txt$/);
}

he@he-THINK ~/manson
$ vi find.pl

he@he-THINK ~/manson
$ perl find.pl
/home/he/manson/A:/home/he/manson/A/1.txt
/home/he/manson/A:/home/he/manson/A/2.txt
/home/he/manson/A:/home/he/manson/A/3.txt
/home/he/manson/A/B:/home/he/manson/A/B/4.txt
/home/he/manson/A/B:/home/he/manson/A/B/5.txt
/home/he/manson/A/B:/home/he/manson/A/B/6.txt
/home/he/manson/A/B/C:/home/he/manson/A/B/C/7.txt
/home/he/manson/A/B/C:/home/he/manson/A/B/C/8.txt
/home/he/manson/A/B/C:/home/he/manson/A/B/C/9.txt

论坛徽章:
0
9 [报告]
发表于 2013-02-18 13:19 |只看该作者
啊呀。。漏了漏了。。非常感谢非常感谢!!!回复 8# dahe_1984


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP