Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to delete files that create date <=20041210

Reply
Thread Tools

how to delete files that create date <=20041210

 
 
sonet
Guest
Posts: n/a
 
      12-27-2004
I can scan the dir and get all file create date.
if create date<=20041210 to delete this file.

EX:
#!/usr/bin/perl
$a='file';
($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks)
= stat("$a");
print $ctime;


But have any other good method to do this job??


 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      12-27-2004
"sonet" <(E-Mail Removed)> wrote in message
news:cqpbk9$f00$(E-Mail Removed)...
> I can scan the dir and get all file create date.
> if create date<=20041210 to delete this file.
>
> EX:
> #!/usr/bin/perl

use strict;
use warnings;
> $a='file';
> ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
> $atime,$mtime,$ctime,$blksize,$blocks)
> = stat("$a");

^^^^
Please read:
perldoc -q quoting

No reason to make assignments to all those variables if you're not going
to use them:
my $ctime = (stat($a))[10];

> print $ctime;
>
> But have any other good method to do this job??


What do you mean by 'other'? You haven't shown what code you're
currently using to delete all files with a certain creation date.

What part of this do you need help with? What have you done so far?
Reading a list of all files in a directory:
perldoc -f opendir
perldoc -f readdir
Deleting a certain file:
perldoc -f unlink

Paul Lalli
>
>


 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      12-28-2004
sonet wrote:
> I can scan the dir and get all file create date.
> if create date<=20041210 to delete this file.


1) Convert "20041210" to seconds-past-the-epoch by using
timelocal or other module.

2) Check if the file's mtime is less than this value.
(That's assuming that you really meant to use the file's
modification time instead of creation date.)

Or use
-M $_ > 17.0 and unlink $_ || warn "unlink($_):$!" foreach <*>;

-Joe
 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      12-28-2004
On Mon, 27 Dec 2004 16:16:53 GMT, "Paul Lalli" <(E-Mail Removed)>
wrote:

>use strict;
>use warnings;

[snip]
>Please read:
>perldoc -q quoting
>
>No reason to make assignments to all those variables if you're not going
>to use them:
>my $ctime = (stat($a))[10];


Oh, and while we're there let's remind him that it's better to avoid
using $a and $b as general purpose variables. (To the OP: see 'perldoc
perlvar'.)


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
Bo Lindbergh
Guest
Posts: n/a
 
      12-29-2004
In article <(E-Mail Removed)>,
Michael Vilain <(E-Mail Removed)> wrote:

> Unix does not store the file's creation time.


So Mac OS X doesn't count as Unix?

More accurately, traditional Unix filesystems don't store it, and thus
the stat system call doesn't return it.


/Bo Lindbergh
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments