c***y 发帖数: 114 | 1 several ppl asked for my code so i'm posting my shabby-but-worked code here
any improvement suggestion are welcome | a**n 发帖数: 313 | 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
| c***y 发帖数: 114 | 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...
| c***y 发帖数: 114 | 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.
| a**n 发帖数: 313 | 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?
| t**c 发帖数: 97 | 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 ###################
| c***y 发帖数: 114 | 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))) : {
| t**c 发帖数: 97 | 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?
|
|