in reply to Delete old files

The second paragraph of readdir deals with your problem. In short, you need to prepend "old" to $file. Also see File::Find and/or glob.

Replies are listed 'Best First'.
Re^2: Delete old files
by Anonymous Monk on Mar 17, 2014 at 19:21 UTC
    Looked at this and it still gives me any files in the directory:
    ... my @file_list; while (my $file = readdir DIR) { next if $file=~/^\./; push @file_list, $file; } closedir DIR; for my $files (@file_list) { my @stats = stat($files); if ($now-$stats[9] > $age) { # files older than 7 days print "$files\n"; } } ...

      How did you change the construction of the entries in @file_list after reading the second paragraph of readdir?

      Also, why not use the following instead of the loop?

      my @file_list= glob("$old/*");
        Sure it can still be like that:
        ... # get all ttct files from here my @file_list= glob("old/*.txt"); for my $files (@file_list) { if ($now-(stat $files)[9] > $age) { # file older than 7 days print "$files\n"; } }

        Still doesnt work.