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 9103249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:35:32+00:00 2026-06-17T01:35:32+00:00

I have written a batch file that does the following: REM @ECHO OFF rem

  • 0

I have written a batch file that does the following:

REM @ECHO OFF
rem %1 = coid
rem %2 = rpg location with ending /

rem get the path of this cmd script
SET SUBDIR=%~dp0

SET BKUPDIR=%SUBDIR%BACKUPS\
SET LOGFILE=%BKUPDIR%backup.log

ECHO ************************************************* >>%LOGFILE%
ECHO STARTING BACKUP FOR %1 AT %2 >>%LOGFILE%

FOR /f "skip=1" %%x in ('wmic os get localdatetime') DO IF NOT defined mydate SET mydate=%%x
SET filedate=%mydate:~0,14%
SET fullname=%BKUPDIR%%1_%FILEDATE%.ZIP

ECHO BKUPDIR: %BKUPDIR% >>%LOGFILE%
ECHO mydate: %mydate% >>%LOGFILE%
ECHO filedate: %filedate% >>%LOGFILE%
ECHO fullname: %fullname% >>%LOGFILE%
ECHO SUBDIR: %SUBDIR% >>%LOGFILE%

rem lets make sure the backup directory exists before starting
IF NOT EXIST %BKUPDIR% MD %BKUPDIR% >>%LOGFILE%

%SUBDIR%7z a -tzip %fullname%  %2%1*.d
IF ERRORLEVEL 255 ECHO user_stopped_the_process >>%LOGFILE%
IF ERRORLEVEL 8 ECHO not_enough_memory >>%LOGFILE%
IF ERRORLEVEL 7 ECHO command_line_error >>%LOGFILE%
IF ERRORLEVEL 2 ECHO fatal_error >>%LOGFILE%
IF ERRORLEVEL 1 ECHO ok_warnings >>%LOGFILE%

IF ERRORLEVEL 0 GOTO END
IF EXIST %fullname% DEL %fullname%

:END
ECHO FINISHING BACKUP FOR %1 >>%LOGFILE%
ECHO ************************************************* >>%LOGFILE%
set mydate=

I am saving the files as the %1 and the date/time the file was created:

SSS_20130110133304.ZIP 
SSS_20130110133336.ZIP

I am running this in the task scheduler to run every night.

I want to keep from having too many zip files in the directory so I’d like to keep the last 30 zip files that exist.

I’m stuck at this point. How do I keep the most RECENT 30 zip files so that I don’t end up with a crap load of zip files?

  • 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-06-17T01:35:33+00:00Added an answer on June 17, 2026 at 1:35 am

    This will list the .zip files from newest to oldest (by creation date), skipping the first 30 files.

    for /f "skip=30 delims=" %%A in ('dir /a:-d /b /o:-d /t:c *.zip ^2^>nul') do if exist "%%~fA" echo "%%~fA"
    

    Just change the echo to del when you want to actually delete the files. :)

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

Sidebar

Related Questions

I have written a rather small batch file that does some date calculations for
I have written a small batch file that copies an exe from solution to
i have a batch(backup.bat)file.in that i have written a command to create a backup
I have written the batch file below, in order to automate the process of
i have written the batch file as follows v: cd view/vob/component set /p comment=enter
I have a file that contains the output of a file compare thats written
@echo off start /wait notepad start worpad This is the code i have written
I have written nsis script for java project.I have Batch file in my project.I
I have written huge MS DOS Batch file. To test this batch file I
I have written a class to load an XML file but I always get

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.