大概像這樣,假設可以用find但不支援全部的參數。
<pre class="c" name="code">
#!/usr/bin/perl -w
my $target="./";
my @lines=`find $target`;
my $now=time();
foreach my $line(@lines){
chomp($line);
my @infos = stat "$line"; #get file info include last update with UNIX-time
print "$line\n";
print "\tLast touch at $infos[8]\n";
print "\tInterval ".($now-$infos[8])." seconds\n";
if(($now-$infos[8]) >= (10*24*60*60)){
print "\t\tOver 10 days\n";
#do your want
}else{
print "\t\tNot over 10 days\n";
}
}
神仙出現了,趕快拜! 肛溫阿!
另外請教一下
如果資料夾是過期且夾子內沒有檔案即刪除,要如何改?因為發現過期檔案是殺掉了,不過留下一堆空的資料夾
引用:
http://digitalpbk.com/2009/11/perl-script-remove-directory-and-contents-recursively
做一點小修改即可只刪除空白資料夾,請自行組合上面程式改成你的需求。
<pre class="c" name="code">
#!/usr/bin/perl -w
deldir("a"); # or deldir($ARGV[0]) to make it commandline
sub deldir {
my $dirtodel = pop;
my $sep = '/';
opendir(DIR, $dirtodel) or die "Open dir fail!\n$!\n";
my @files = readdir(DIR);
closedir(DIR);
@files = grep { !/^\.{1,2}/ } @files;
@files = map { $_ = "$dirtodel$sep$_"} @files;
@files = map { (-d $_)?deldir($_):return} @files;
rmdir($dirtodel);
}