how to delete files that create date <=20041210

S

sonet

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??
 
P

Paul Lalli

sonet said:
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
 
J

Joe Smith

sonet said:
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
 
M

Michele Dondi

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
 
B

Bo Lindbergh

Michael Vilain said:
Unix does not store the file's creation time.

So Mac OS X doesn't count as Unix? :p

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


/Bo Lindbergh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top