How to write a batch script to delete files older than 24 hours
Results 1 to 7 of 7

Thread: How to write a batch script to delete files older than 24 hours

  1. #1
    Join Date
    Jan 1999

    How to write a batch script to delete files older than 24 hours


    I need help on how to delete files from a particular directory which are older than 24 hours.

    please help

  2. #2
    Join Date
    Jan 1999
    Dont know how to get it to run at a perticular time but this will do it for you every time you reboot.

    1)add this line to your autoexec.bat neer the end
    dump.bat (call it whatever.bat its gonna call the batch file you are gonna write.)

    2)At the command prompt type "edit dump.bat"
    this should give you a blank edit screen.
    now add the 2 following lines
    deltree /y path eg..(c:\windows\temp)
    mkdir path eg..(c:\windows\temp)
    **note** where I put path you put the path of the files you want to delete.
    **Also note** that this is going to erase any subdirectory`s in the path so be carefull.
    Save and exit, and the next time you reboot presto it completely wipes the directory and writes a new one with the same name over it. Works good for my old dos box.
    Good Luck!!

  3. #3
    Join Date
    Jan 1999
    I need to only delete files which are older than 24 hours, not all the files in the directory!!

  4. #4
    Join Date
    Dec 1999
    Rostov-on-Don, Russia

    I don't know how to do this directly, but some archive utilities (ARJ for example) can add files to archive which are created before today or before number of days specified. For example, you can move files created before today to some temporary archive and then delete the archive.

    Good luck, Igor M
    Good luck, Igor

  5. #5
    Join Date
    Feb 1999
    Just as a though.

    The Problem. Clean files in temp dir older than 24 hours.

    Solution: Create a batch file that gets the systems date and creates a dir based on that information.
    Example Today is 1-8-1999
    In dos the dir will appear 1-8-19~
    In explorer it will appear 1-8-1999

    Next. After the dir is created all files in the targeted dir (temp) are moved to the dated dir. If you reboot the dir already exist so it will not be recreated. The only effect any files still there are moved to todays dir.

    You may then add to the bat an if exist *-1-* rd *-1-* statement. Continueing on up to 30.

    Well these thoughts are written on the fly and only intended to be some thoughts for considering.

    If you wish to create the program and need some help on the dir/date code just email me.

    I am not an expert so any advice by me should be weighed.

    All spelling and grammitical errors in the above message are to considered (Copyright of World Library).


    World Library

  6. #6
    Join Date
    May 2009

    biterscripting find command to find and delete files that are older than given date

    Original poster says:

    I need help on how to delete files from a particular directory which are older than 24 hours.
    Here is a little script. I will assume folder is C:\folder. When you say 'older' than a certain time, I will assume you mean created before that certain time. I will assume that time is 20090522000000 (May 22, 2009, 00:00:00).

    # Collect a list of files created before 20090522000000.
    var str list ; find -rn "*" "C:\folder" ( 9$ftype=="f") AND ($fctime < "20090522000000") )
    # Delete files in list one by one.
    while ($list <> "")
        var str file ; lex "1" $list > $file ; system delete ("\""+$file+"\"")

    Script is in biterscripting ( Translate it to any batch or scripting langugage of your choice.


  7. #7
    Join Date
    Mar 2002
    At my computer, cruising VDR and watching your back
    Patrick, you did check the date on this thread, right. It's ten years old. Please don't resurrect any more older threads. I'm going to leave it open because it could help someone else.......if the script is true to course.
    New 8 core
    Gigabyte GA-970 Gaming Full ATX Motherboard;AMD FX 8350 4Ghz; Corsair Vengeance 16GB Memory; Kingston 240GB SSD; WD 320GB SATA; Geforce 710 GT 2GB Vid card; Windows 7 Professional 64 bit; Antec Nine Hundred Mid tower; HP 25" LED/LCD IPS monitor

    Built by Me, in 2017!!

    UBCD How to Burn an ISO Image to a Disc
    My photos

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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