You can pick out what you need...
# ********************************* # Call Modules # ********************************* use File::Find; use File::Copy; use Getopt::Std; getopts('d:h'); # ********************************* # Initialize variables # ********************************* $server='server104'; $dir1='\\\\'."$server".'\\d$'; $agedays=60; #defaults agedays to 60 # ********************************* # Process arguments ([h]elp,[d]ays) # ********************************* if ($opt_h){ die "\agecmd.pl -d[days to age]\n"; } if ($opt_d){ if ($opt_d gt 9){ #tests for strings die "Error: days option must be a number. Use agecmd.pl -d[da +ys to age]\n"; }else{ $agedays=$opt_d; } } # ********************************* # Do date calculations # ********************************* @xtime=localtime(time); $day=$xtime[3]+1; $month=$xtime[4]+1; $year=$xtime[5]+1900; $hours=$xtime[2]; $mins=$xtime[1]; $secs=$xtime[0]; $logname='//server1/d$/'."ftp$month$day$year$hours$mins$secs".'.log'; $agesecs=60*60*24*$agedays; #converts $agedays to seconds $daysago=time-$agesecs; #the time stamp of $agedays ago in seco +nds $daysago2=localtime($daysago); #the time stamp of $agedays ago in w +ords - mainly for printing # ********************************* # Find the files (no dir) on the server # ********************************* print "finding files to be aged\.\.\.\n"; find(\&wanted, $dir1); sub wanted { $filesecs = (stat("$File::Find::dir/$_"))[9]; #GETS THE 9TH ELEMEN +T OF file STAT - THE MODIFIED TIME $filesecs2=localtime($filesecs); if ($filesecs<$daysago && -f){ #-f=regular files, eliminates DIR p +.367 push (@files,"$File::Find::dir/$_"); push (@files,"$filesecs2"); } print'.'; } # ********************************* # replace '/' with '\' in file names # ********************************* foreach (@files){ s/\//\\/g; } # ********************************* # Write to Log # ********************************* %filehash=@files; #puts the array into a hash for easy printing. Key= +file, Value=date open OUT, ">$logname" or die "Cannot open $out for write :$!"; print OUT "FTP server aging log generated by PERL script\n"; print OUT "Script written by Ozzy on 4/18/00\n"; print OUT "Files deleted from \\\\$server on ".localtime(time)."\n"; print OUT "Files deleted before $daysago2\n"; print OUT "Files were aged $agedays days\n\n"; print OUT "File Listing:\n\n"; foreach $filename (sort keys %filehash){ print OUT "$filename $filehash{$filename}\n"; } close OUT; # ********************************* # Delete files # ********************************* print "\nDeleting all files before $daysago2"; #unlink %filehash; print "\nScript complete.";

-OzzyOsbourne


In reply to Re: Recursive Directory Tree Deletion in Windows by OzzyOsbourne
in thread Recursive Directory Tree Deletion in Windows by gaggio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.