ms dos, bat file

  • Hello everyone,

    i am trying to create a batch file that will delete files that are older that 24 hours

    what would be the dos command that i can put in that .bat file

    thanks

  • I don't think a batch file can do that. I could be wrong, but del doesn't seem to have a property that will read file date, just name and extension. There are other solutions, depending on what type of files you are trying to get rid of. If it's backup files, a maintenance plan with a cleanup action can do it, for example.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • There are some really useful examples of Batch files on this site;

    http://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv.html">

    http://www.chebucto.ns.ca/~ak621/DOS/Bat-Adv.html

    They should have what you are after or something close that you can modify.

    As this is a SQL forum, why don't you use a maintenance plan to do the delete?

  • GSquared (6/24/2008)


    I don't think a batch file can do that. I could be wrong, but del doesn't seem to have a property that will read file date, just name and extension. There are other solutions, depending on what type of files you are trying to get rid of. If it's backup files, a maintenance plan with a cleanup action can do it, for example.

    It can be done, but involves looping through the file names based upon the create/modify date and deleting based upon that.

    Much easier to use a maintenance plan though.

  • here is the story:

    i am doing full backup to disk, daily

    then Data Guard backup software does the backup to tape for those .bak files

    it has an option, on success start the .bat or .exe file

    this where i want this .bat file to delete all backups that older then 24 hours

    but the whole purpose is to make sure that archiving to tape had ran successfully

  • Well, you could install Powershell, write a Powershell script to do it (which I am told is comparatively easy), then call the Powershell script from your .BAT file.

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • thanks !!!!!!!!

  • Let us know how it works out. 🙂

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply