file timestamps and removal [was Re: SPUG:DOS / BASIC Script]

Michael R. Wolf MichaelRunningWolf at
Fri Jan 17 18:07:19 CST 2003

Dan Ebert <mathin at> writes:

> Could you incoporate the date into the raw data filename?  That way you
> wouldn't have to worry about creating directory or moving a file.  A
> seperate script could then be written to look at the filenames and
> delete the old ones.

I've done a similar thing, using Unix dates (useful for scripts) and
also human readable dates encoded in the filename.

How 'bout something like this (no warranty, completly untested..):

# Name, create, use, close, and touch(1) a log file.

my $unix_now = time;
my $human_now = local_time($unix_now);

my $file_name = sprintf("DB_trailings.%d.%s.txt", $unix_now, $human_now);

open my $fh, $file_name or die "problem with trailings file $file_name: $!";
#use $fh...
close $fh;

utime ($unix_now)x2, $file_name;  # To make name consistant with timestamp.

#Then remove all old ones.

$now = time;
$threshhold = $now - 14*(24*60*60);

@too_old = grep { /^DB_trailings\.(\d+)\./ && $1 > $threshhold }

@unsucessful = unlink(@too_old);
warn "could not unlink @unsucessful: $!" if @unsucessful;

Michael R. Wolf
    All mammals learn by playing!
        MichaelRunningWolf at

More information about the spug-list mailing list