Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 760169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:41:06+00:00 2026-05-14T15:41:06+00:00

(Using Windows 2000 and 2003 Server) We use forfiles.exe to delete backup .zip files

  • 0

(Using Windows 2000 and 2003 Server)

We use forfiles.exe to delete backup .zip files older than n days, and it works great (command is a bit like below)

forfiles -p"C:\Backup" -m"*.zip" -c"cmd /c if @ISDIR==FALSE del \"@PATH\@FILE\"" -d-5

If a .zip file fails to be created, I’d like to ensure that we don’t end up with 0 .zip files in the backup after 5 days. Therefore, the command needs to be:

“delete anything older than 5 days, but ALWAYS keep the most recent 5 files, EVEN if they themselves are older than 5 days”

We can use forfiles.exe or another solution (although anything that is a slick one-liner is ALWAYS preferable to a script file).

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:41:06+00:00Added an answer on May 14, 2026 at 3:41 pm
    FOR /F "skip=5 delims=" %%G IN ('dir /b /O-D /A-D') DO del "%%G"
    

    Will delete all files except the 5 newest ones. I couldn’t find a one-liner to keep all files newer than 5 days so for that you might have to use some more complicated logic.

    /b
    

    Lists only file names without extra info

    /O-D
    

    Sorts list by reverse date order.

    /A-D
    

    Filters to only show non-directory files

    skip=5
    

    skips the 5 first lines (5 newest ones).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server 2000 on Windows Server 2003. I am trying to run a backup,
I am using windows 2000 server. I want to know top 5 processes that
How to get process Commandline Parameters at Windows 2000 using C#? I'm use WMI
I'm using ColdFusion 7 on a Windows 2003 server to talk to a default
I am using py2exe to compiling python scripts in executable files on Windows Xp/7/2000.
SQL Server 2000 Standard, Windows 2003 My coworker removed 'BUILTIN\Administrators' group from SQL Server
Using windows server, I have a path to a file that, when you click
Using an arbitrary Windows machine (2000/XP or later), I can install Eclipse CDT to
I am trying to use this code on Windows 2000: foreach (Process p in
I'm using a virtualized web server and I don't remember whether it's running Windows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.