Redian新闻
>
my script Re: how would you do this?
avatar
my script Re: how would you do this?# Unix - 噫吁兮,危乎高哉
c*y
1
several ppl asked for my code so i'm posting my shabby-but-worked code here
any improvement suggestion are welcome
avatar
a*n
2
This one will not work for the files in any level subdirectories...

【在 c***y 的大作中提到】
: several ppl asked for my code so i'm posting my shabby-but-worked code here
: any improvement suggestion are welcome

avatar
c*y
3
nod, only works for 1 dir now, i'll update it later to push all the subdir to
an array, then work through the array, b/c i only care the duplicates in
the same dir.

【在 a**n 的大作中提到】
: This one will not work for the files in any level subdirectories...
avatar
c*y
4
or does anyone know a better idea? maybe develops a dir tree, than work on
each node on the tree?

【在 c***y 的大作中提到】
: nod, only works for 1 dir now, i'll update it later to push all the subdir to
: an array, then work through the array, b/c i only care the duplicates in
: the same dir.

avatar
a*n
5
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

【在 c***y 的大作中提到】
: or does anyone know a better idea? maybe develops a dir tree, than work on
: each node on the tree?

avatar
t*c
6
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

【在 a**n 的大作中提到】
: 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 ###################

avatar
c*y
7
cool! thanks~~
one problem: stat(9) works fine on Unix, but when I put the script on
Redhat Advanced Server 3, the last modified time returns the earlist
date redhat can handle:
Found Duplicate File:
call_1.html Wed Dec 31 18:00:00 1969
Call_1.html Wed Dec 31 18:00:00 1969
and stat call_1.html directly returns the correct timestamp
anyone has any idea?

【在 t**c 的大作中提到】
: 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)))
: {

avatar
t*c
8
try to add the full path to the filename?

【在 c***y 的大作中提到】
: cool! thanks~~
: one problem: stat(9) works fine on Unix, but when I put the script on
: Redhat Advanced Server 3, the last modified time returns the earlist
: date redhat can handle:
: Found Duplicate File:
: call_1.html Wed Dec 31 18:00:00 1969
: Call_1.html Wed Dec 31 18:00:00 1969
: and stat call_1.html directly returns the correct timestamp
: anyone has any idea?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。