Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Need a script that will delete files??

  1. #1
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default Need a script that will delete files??

    Hey I have a folder on my site that will collect user created files.

    These files are a once use only file. What I was wondering is is there a script I can run with cron to once a day run through that folder only and delete any file of a certain extension (say .jpg)

    so like it would be run at 5 p.m. server time and delete any and all *.jpg files in this one folder?

    Does that make sense?
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  2. #2
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    nevermind. I got it. I was using unset() instead of unlink().

    For those after me, I am using this code and it has tested perfect with one file, and 40 files:

    PHP Code:
    <?php

    foreach (glob("*.jpg") as $filename) {
       echo 
    "$filename size " filesize($filename) . "\n";
       
    unlink($filename);
    }

    ?>
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Why use PHP for this task?
    Code:
    rm /home/blizzard/images/temporary/*.jpg
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Because I will be using cron so I don't have to go back to this folder ever again.

    It is just a catch all folder for the created files. Once they are made, they are viewed, and then no longer needed.

    So I make the php script, kick it off with cron, and poof, hassle free.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    But equally you could just execute the above command with cron and remove the need for the PHP script
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Yes, but then I wouldn't be learning PHP
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

  7. #7
    Join Date
    Sep 2005
    Posts
    882
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Default

    Quote Originally Posted by BLiZZaRD
    Yes, but then I wouldn't be learning PHP
    I think the hardest part of learning any language is knowing when it's not the right tool for the job.

  8. #8
    Join Date
    Aug 2006
    Posts
    239
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blm126
    I think the hardest part of learning any language is knowing when it's not the right tool for the job.
    That's called "beating the crap out of the man", but could actually agree more...

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Also you could just output the generated images directly from the PHP script that called them, and end the whole mess in the first place.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Aug 2005
    Location
    Other Side of My Monitor
    Posts
    3,494
    Thanks
    5
    Thanked 105 Times in 104 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Twey
    Also you could just output the generated images directly from the PHP script that called them, and end the whole mess in the first place.
    That is true too, but that would defeat the entire purpose of the whole thing. I did think of that though.

    I also found that command line code as well, but I still don't like those.

    If I have to drive a nail into a 2X4 I can use a hammer, or a mallet. Both will get the job done, one easier than the other, but in the end, if the nail is driven it doesn't matter the way I got it in.
    {CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
    Follow Me on Twitter: @InkingHubris
    PHP Code:
    $result mysql_query("SELECT finger FROM hand WHERE id=3");
    echo 
    $result

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •