Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how i can delete old files ?  (Read 18975 times)

0 Members and 1 Guest are viewing this topic.

TosunPASA

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 8
    how i can delete old files ?
    « on: May 31, 2021, 11:36:46 AM »
    hello
    i have backup directory  (d:\SQL-Backup\.)

    and i wanna delete 7-15-30-60 days ago "rar" files  (base is file created day.. because.... sql backup starting everyday 22pm and backup working everyday)

    why different time ? have multi diffrent program backup directory and this batch will work different time line

    could you help me ?

    thx

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: how i can delete old files ?
    « Reply #1 on: June 01, 2021, 07:52:30 AM »
    I think the easiest way would be to use forfiles.

    Code: [Select]
    set agefactor=7

    forfiles /p d:\SQL-Backup /s /d -%agefactor% /m *.rar ^
    /c "cmd /c echo @PATH older than %agefactor% days"

    I prefer not to write destructive code, so as written the snippet will just list the files. You can change the echo command to a del command once you are satisfied with the results. Also change the value of agefactor in the first line as needed. Note: Enter the agefactor as a positive number, it will be converted to a negative number in the code.

    Good luck  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein