Einzelnen Beitrag anzeigen
Alt 24.10.2008, 21:47   #1 (permalink)
bigfoot996
Hardware Freak
 
Benutzerbild von bigfoot996
 

Registriert seit: 14.02.2005
Beiträge: 5.160

bigfoot996 ist jedem bekanntbigfoot996 ist jedem bekanntbigfoot996 ist jedem bekanntbigfoot996 ist jedem bekanntbigfoot996 ist jedem bekanntbigfoot996 ist jedem bekannt

Standard [PERL/PowerShell] Dateien die alter als 30 Tage sind zippen...

Guten Abend,

ich bräuchte mal etwas Beistand bei Perl pls *g*

Und zwar bräuchte ich etwas hilfe bei einem script, was automatisch alle Dateien im vorgegebenen Ordner die älter als 30 Tage sind zippt und dabei alle älter als 60 löscht.

soweit so gut, folgendes hab ich schon:

Code:
#!c:/perl/bin/perl 
use strict; 

use warnings; 

use constant LOESCHEN => 0; 

use constant BEHALTEN => 1; 

use constant DELETED => -1; 

my $dir = \"C:/POWERSHELL/TESTSCRIPTS/\"; 

my $logFile = \"$dir/log.txt\";

my @allFiles; 

my %allFiles; 

my $lastMod; 

my $back30days = (time()-(86400*30)); 

&cd($dir);

foreach(@allFiles) { 

    $lastMod = (stat($_))[9]; 

    $allFiles{$_} = BEHALTEN if(($lastMod - $back30days) > 0 && -f $_); 

    $allFiles{$_} = LOESCHEN if(($lastMod - $back30days) < 0 && -f $_); 


    $allFiles{$_} = LOESCHEN if -d $_; 

} 

foreach(keys(%allFiles)) { 


    if ($allFiles{$_} == LOESCHEN && -f $_) { 


        $allFiles{$_} = DELETED if unlink($_); 


    } 


} 


foreach(keys(%allFiles)) { 


    if ($allFiles{$_} == LOESCHEN && -d $_) { 


        $allFiles{$_} = DELETED if rmdir($_); 


    } 

} 

&loggen(); 

sub loggen { 


    open(LOGFILE,\">$logFile\") or die $!; 


    foreach(keys(%allFiles)) { 


        print LOGFILE $_,\" --> \"; 


        print LOGFILE \"File/Directory wurde geloescht...\n\n\" if $allFiles{$_} == DELETED; 


        print LOGFILE \"File/Directory ist aktuell...\n\n\" if $allFiles{$_} == BEHALTEN; 

        print LOGFILE \"File/Directory wurde nicht geloescht...\n\n\" if $allFiles{$_} == LOESCHEN; 

    } 

    close(LOGFILE); 
} 

sub cd { 

    my $dir = shift; 

    my $base = $dir.\"/\"; 

    my @currDir;

    opendir(DIR,$dir) or die $!;

    @currDir=readdir(DIR); 

    close(DIR); 

    foreach(@currDir) { 

        next if $_ eq '.' or $_ eq '..'; 

        &cd($base.$_) if(-d $base.$_); 

        push(@allFiles,$base.$_);

    } 
}
So, jetzt raff ichs aber nich wie ich alle älter als 30 jünger als 60 zippen lassen kann und alle über 60 löschen? Vllt. kann mir da kurz einer unter die Arme greifen pls, wäre nett.

Danke und Gruß
Biggi

Geändert von bigfoot996 (05.11.2008 um 14:13 Uhr)
bigfoot996 ist offline   Mit Zitat antworten