由买买提看人间百态

topics

全部话题 - 话题: curdir
(共0页)
t**c
发帖数: 97
1
来自主题: 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
a**n
发帖数: 313
2
来自主题: 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
l********a
发帖数: 1154
3
弄个python2.7装上,把下面的代码保存为一个.py文件,放在那个文件夹运行一下就行了
#! /usr/bin/env python
import os
for fin in os.listdir(os.curdir):
if fin.endswith('.drw.5'):
prefix = fin[:fin.index('.')]
prtpath = prefix+'.prt.8'
if not (os.path.isfile(prtpath) and os.path.exists(prtpath)):
os.remove(fin)
print fin+' has been removed'
print 'DONE'
(共0页)