http://www.perlmonks.org?node_id=401451


in reply to Re^3: delete old files (windoze)
in thread delete old files (windoze)

I guess I should have been MORE informative about my OS. Here's what I have. I have windoze 2003 ent and the hard drive is partitioned C:\ and T:\temp. I run Perl on both a 32bit and 64bit windoze servers.

Now back to the problem at hand. Run this code if you have your hard drive partitioned and you will see it fail then get back with me with suggestions.
#!/usr/bin/perl -w use strict; use File::Find; use File::stat; my $path = "T:\\"; find (\&wanted, $path); sub wanted { my $days = 10; my $stat = stat($_); # Access and Modified dates older then X days and not root if (-A $_ > $days && -M $_ > $days && !(/^\./) ){ # With a temp partition T:\ there are system files that can't +be deleted if (!($_ =~ /^ntldr.*|nprotect.*|ntdetect.*|System.*|VIRTPART. +*|.ini/i)) { printf "access date %s modify date %s File is %s\n", scala +r localtime $stat->atime, scalar localtime $stat->mtime, $_; # unlink($_); } } }

Replies are listed 'Best First'.
Re^5: delete old files (windoze)
by kutsu (Priest) on Oct 22, 2004 at 13:44 UTC

    I don't have a windows machine available, but I doubt it's because of the network drive (having done some copying, renaming, and deleteing on windows network drives). I would suggest you use a debugger and print $_ at the start of the while loop to ensure that the files found by File::Find match the files actually in the directory.

    "Cogito cogito ergo cogito sum - I think that I think, therefore I think that I am." Ambrose Bierce