Created
May 22, 2017 08:45
-
-
Save jostmart/f44d592a893df27c9ff4ebbe21a1058a to your computer and use it in GitHub Desktop.
slette.pl (jonas skript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# Takk Jonas :) | |
# | |
use strict; | |
use File::Path; | |
my $folder=$ARGV[0]; | |
my $antall = 1; | |
opendir (DIR,$folder); | |
my @dirs = readdir(DIR); | |
my %re_hash; | |
foreach my $ret_re (@dirs){ | |
if (-f $folder . "/" . $ret_re && $ret_re =~ m/^[^\.]/){ | |
$re_hash{$ret_re} = (stat($folder . "/" . $ret_re ))[9]; | |
} | |
} | |
closedir(DIR); | |
foreach my $fil ( sort { $re_hash{$b} <=> $re_hash{$a} } keys %re_hash) { | |
if ($antall-- < 0){ | |
unlink $folder . "/" . $fil; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
13:53 jeg forstår ikk hva den koden der gjer
13:53 va?
13:53 slette.pl ?
13:53 ahh
13:53 ja
13:53 joda
13:54 først lager man seg en hash av filnavn og timestamps
13:54 så looper man gjennom de $antall filer som skal beholdes
13:54 og sletter resten