how to delete files that create date <=20041210

Discussion in 'Perl Misc' started by sonet, Dec 27, 2004.

  1. sonet

    sonet Guest

    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??
     
    sonet, Dec 27, 2004
    #1
    1. Advertising

  2. sonet

    Paul Lalli Guest

    "sonet" <> wrote in message
    news:cqpbk9$f00$...
    > 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
    >
    >
     
    Paul Lalli, Dec 27, 2004
    #2
    1. Advertising

  3. sonet

    Joe Smith Guest

    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
     
    Joe Smith, Dec 28, 2004
    #3
  4. On Mon, 27 Dec 2004 16:16:53 GMT, "Paul Lalli" <>
    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,
     
    Michele Dondi, Dec 28, 2004
    #4
  5. sonet

    Bo Lindbergh Guest

    In article <>,
    Michael Vilain <> wrote:

    > 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
     
    Bo Lindbergh, Dec 29, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    631
    Matthew Speed
    Nov 8, 2003
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,333
    Michael Borgwardt
    May 30, 2004
  3. Matt
    Replies:
    2
    Views:
    551
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    747
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    419
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page