delete files between 2 dates

Discussion in 'PHP' started by Bahaa Ajbaa, Jan 4, 2008.

  1. #1
    hi

    i have about 10.000 files in my hard drive

    i want to delete the files e.g. from 1 jan 2007 to 1 mar 2007

    i dont have a mysql database for these files all files in a folder

    how i can do that?
     
    Bahaa Ajbaa, Jan 4, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    You actually want this to do with PHP?

    "On your harddrive" sounds more like you have the files on your computer. Use the advanced Windows search function. It'll do the job.
     
    nico_swd, Jan 4, 2008 IP
  3. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i meand on my site ----> the site on hard drive looool

    :)
     
    Bahaa Ajbaa, Jan 4, 2008 IP
  4. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    no one ?!?!
     
    Bahaa Ajbaa, Jan 4, 2008 IP
  5. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #5
    you need to write a php program which can easily do

    but before you even try that you should have a proper bckup of site.

    it will be only 25-30 line php program i guess

    Regards

    Alex
     
    kmap, Jan 5, 2008 IP
  6. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    yeah i want it with php

    but i dont know how to write i dont have enough experince

    :) so if you can help me its ok :)
     
    Bahaa Ajbaa, Jan 5, 2008 IP
  7. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    any one help please :(
     
    Bahaa Ajbaa, Jan 5, 2008 IP
  8. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #8
    
    $get_list = mysql_query("SELECT * FROM `files` WHERE `datefield` > '01-01-2007 00:00:00' AND `datefield` < '03-01-2007 00:00:00'");
    
    while($each = mysql_fetch_assoc($get_list){
    	unlink($each['filelocationfield']);
    	$remove_file = mysql_query("DELETE FROM `files` WHERE `fileidfield` = '$each[fileidfield]'");
    }
    
    
    PHP:
    Test before using (not tested).

    Peace,
     
    Barti1987, Jan 5, 2008 IP
  9. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #9
    this would be for data in the database and not files on hard drive

     
    commandos, Jan 5, 2008 IP
  10. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #10
    Barti1987, Jan 5, 2008 IP
  11. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    hi azizny

    i dont a mysql database :) the files in folder :)
     
    Bahaa Ajbaa, Jan 5, 2008 IP
  12. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #12
    Bahaa just use ur OS , if you have windows or Linux there is ways to display files and then just delete them ..
     
    commandos, Jan 5, 2008 IP
  13. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    hallo commandos

    iam using linux but i dont know how to do that

    azizny

    thanx 4 help
     
    Bahaa Ajbaa, Jan 5, 2008 IP
  14. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #14
    do you have access to a command line ?
     
    commandos, Jan 5, 2008 IP
  15. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    yes i have

    can you help please
     
    Bahaa Ajbaa, Jan 5, 2008 IP
  16. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #16
    If So use those functions :

    ls -lrt // List files by date.

    find /path/to/files* -mtime +365 -exec rm {} \; // removes files older than 365 days

    i dont take any responsability for testing those lol , test at your own risk

    found this also

    find /path/to/files* -mtime +365 -exec ls -a {} \; // you can test this to see the files that will get deleted .


    just search google for : delete files based on date + linux
     
    commandos, Jan 5, 2008 IP
  17. Bahaa Ajbaa

    Bahaa Ajbaa Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    i cant get that ( removes files older than 365 days )

    give me an example for this please
     
    Bahaa Ajbaa, Jan 5, 2008 IP
  18. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #18
    Check out these results.

    Peace,
     
    Barti1987, Jan 5, 2008 IP
  19. Marty_

    Marty_ Banned

    Messages:
    1,031
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #19
    You can do this very easily through most ftp programs, for example I use cuteFtp, connect to your server, open the folder you want to delete the old files from, select from the listing tabs "Modified" this will place your 10'000 list of files in order of date. Then all you have to do is select a starting point(date), hold the SHIFT button on your key, use the scroll bar and drag that down to the last date you want to delete, click that date, all above files will be highlighted, then simple right click and Delete.
     
    Marty_, Jan 6, 2008 IP