由买买提看人间百态

topics

全部话题 - 话题: opendir
(共0页)
a**n
发帖数: 313
1
来自主题: Unix版 - my script Re: how would you do this?
change part of code to the new code, and let it to all sub-dirs:
#################Your code ##################
# put all files in an array
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
# put all files in an array
while (defined($file = readdir(DIR))) {
push @files, $file;
}
#############################################
##################New Code ###################
push @dirlist $dirname;
while(defined($curdir=pop(@dirlist))){
opendir(DIR, $curdir) or die "cannot open $c
w**n
发帖数: 88
2
来自主题: Unix版 - how to search a pattern in all files
Your syntax for opendir is wrong ...
perldoc -f opendir
L*1
发帖数: 11537
3
Try this:
#!/usr/bin/perl
my $dir = "/tmp"; # change it!
print "$dir\n";
opendir(DIR, $dir) || die "Error in opening dir $dir\n";
chdir($dir);
while( ($filename = readdir(DIR)))
{
next if (-d $filename);
print "$filename\n";
my $new_filename = uc($filename);
print "-- $new_filename\n";
#system("mv $filename $new_filename");
}
closedir(DIR);
exit;
~
y*h
发帖数: 107
4
来自主题: Programming版 - 程序不认opendir() , pdir(), readdir()
我把BOOST都加上了, 还是找不到. 怎么办咧?
k****f
发帖数: 3794
5
来自主题: Programming版 - 问个c的问题
opendir??
d******l
发帖数: 12
6
来自主题: Programming版 - 问个c的问题
opendir是linux环境下的把
d******l
发帖数: 12
7
来自主题: Programming版 - 问个c的问题
opendir是linux环境下的把
h**********r
发帖数: 174
8
来自主题: Programming版 - a PERL opendir/readdir question
Here is what is the directory:
-bash-3.00$ ls -al
total 7
drwxr-xr-x 5 x student 512 Aug 14 16:54 .
drwx------ 11 x student 3072 Aug 14 16:55 ..
-rw-r--r-- 1 x student 0 Aug 14 16:54 a.txt
drwxr-xr-x 5 x student 512 Aug 14 14:55 blackHole
-rw-r--r-- 1 x student 0 Aug 14 16:54 b.xml
drwxr-xr-x 2 x student 1024 Aug 14 16:42 coloring
drwxr-xr-x 11 x student 512 Aug 14 14:55 composed
As you can see, there are THREE directories and TWO normal files. I want to
process all of them.
t****t
发帖数: 6806
9
来自主题: Programming版 - a PERL opendir/readdir question
quote perldoc -f readdir:
If you’re planning to filetest the return values out of a
"readdir", you’d better prepend the directory in question.
Otherwise, because we didn’t "chdir" there, it would have been
testing the wrong file.
end quote
h**********r
发帖数: 174
10
来自主题: Programming版 - a PERL opendir/readdir question
thanks. This helps.
t****t
发帖数: 6806
11
来自主题: Programming版 - Listing files under a directory in C++
you may use opendir() family function, which is specified in POSIX.1-2001.
g******1
发帖数: 295
12
来自主题: Programming版 - perl 文件夹搜索路径一问
在path1下有个文件夹叫.dir1, 我的perl script myscript.pl在path2下,
在myscript.pl中我想打开.dir1,
opendir DOT, '.dir1' or die("Can't open .dir1 for scanning.\n");
但在path2下运行myscript.pl始终显示"Can't open .dir1 for scanning.\n"
在myscript.pl中看$ENV{PATH}中已经有path1
print "Current PATH is: ", $ENV{PATH}, "\n";
请问是什么原因?谢谢。
w******p
发帖数: 166
13
来自主题: Programming版 - perl 文件夹搜索路径一问
opendir doesn't consider PATH.
you can use either the full path to dir1, or use the FinBin module to find
where your binary is, and use relative pathing to get to dir1
k******d
发帖数: 8
14
来自主题: Unix版 - how to search a pattern in all files
recursively under a specific directory?
I write a perl, to recursive read files under all subdirectories, but failed
with error msg: "Bad symbol for filehandle" for the lime of code below:
if (!opendir($dirvar, $dirname)){
...............
so I'm thinking of "sac" or sth?
help!
t**c
发帖数: 97
15
来自主题: Unix版 - my script Re: how would you do this?
If the directory list need to be printed, I think it's better to use a hash
table %counter to count the number of times the filename appears:
####################################################################
my (%counter,%detail,@dirlist,$filename,$curdir);
# put all files in the hashes according to their filenames
push @dirlist,$dirname;
while(defined($curdir=pop(@dirlist))){
opendir(DIR, $curdir) or die "cannot open $curdir $!\n";
while (defined ($filename = readdir(DIR)))
{
if
j******y
发帖数: 700
16
"Arguments too long" Error means your file list is too big for find to
handle. Try to use perl, here's how:
perl -e 'opendir(DIR, "."); @all = grep //, readdir DIR; closedir
DIR; for (@all) { do something }'
g**********t
发帖数: 475
17
来自主题: Statistics版 - 大牛帮忙:批处理读入多个文件!!
#!/usr/bin/perl -w
use strict;
opendir DIR, "./" or die "$!\n";
for (grep {m/^RC_/} readdir DIR){
open IN, $_ or die "$1\n";
open OUT, ">C_$_" or die "$!\n";
print OUT (join (",", grep {$_} map {$1 if /^\s*([^\s]+)\s+Numeric/} <
IN>), "\n");
close IN;
open IN, "D_$_" or die "$!\n";
print OUT ;
close IN;
close OUT;
}
代码保存为.pl文件放到数据文件夹下直接运行即可
(共0页)