由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Unix版 - my script Re: how would you do this?
相关主题
有关Unix shell script的问题how to contral tar-ed file size?
HELP: 怎样用SCRIPT实现如下功能?HELP.
bash script question: read in textHow FTP the whole Dir(include Subdir) in UNIX?
怎么替换一批文件里的某个字符?how to grep a string in all sub-dirs?
向高人请教:怎么从大量的文件中grepWhat's the quickest way to change various filenames with same format under unix?
group permissionRe: What's the quickest way to change various filenames with same form
怎样用mail把某一文本文件发送给一个email地址?what's wrong with gcc?
what is the problem? what can I do?如何用mail命令发送代附件的信
相关话题的讨论汇总
话题: dir话题: curdir话题: dirlist话题: opendir话题: dirname
进入Unix版参与讨论
1 (共1页)
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?

1 (共1页)
进入Unix版参与讨论
相关主题
如何用mail命令发送代附件的信向高人请教:怎么从大量的文件中grep
How to delete such file?group permission
HOw to find files hardlinked to a same inode?怎样用mail把某一文本文件发送给一个email地址?
vnc server in Sun Solaris, how to change wm?what is the problem? what can I do?
有关Unix shell script的问题how to contral tar-ed file size?
HELP: 怎样用SCRIPT实现如下功能?HELP.
bash script question: read in textHow FTP the whole Dir(include Subdir) in UNIX?
怎么替换一批文件里的某个字符?how to grep a string in all sub-dirs?
相关话题的讨论汇总
话题: dir话题: curdir话题: dirlist话题: opendir话题: dirname