Solved

.BAT File  -is DOS Smart enough to  INCREMENT Filenames?!?

Posted on 1998-09-05
5
759 Views
Last Modified: 2013-12-29
I would like to create a bat file that would look inside a directory and pkzip all *.txt files into a zip file called file1.zip.  
However if a pkzip file with that name already exists i want the pkzip file name to increment by 1; so in this case it would be file2.zip.

Is DOS smart enough to know how to do this?
0
Comment
Question by:aniston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1722205
I wouldn't count on it :-)  Perhaps you could do it in QBasic?
0
 

Author Comment

by:aniston
ID: 1722206
I remember doing QBasic some 15 years ago so i have no idea how to even begin.
If it is possible in Qbasic could you provide the code on how it can seamlessly work with DOS through a bat file (or any file that dos can run -- like a bat file or exe).

Thanks
0
 
LVL 1

Expert Comment

by:semontgomery
ID: 1722207
Aniston,

The following is crude, but it works.

@echo off
c:
cd\
dir *.txt /s/v/b/on > list
if not exist file1.zip goto noone
for %%c in (1 2 3 4 5 6) do if exist file%%c.zip goto %%c
rem if not exist file2.zip goto 2
rem if not exist file3.zip goto 3
rem if not exist file4.zip goto 4
rem if not exist file5.zip goto 5
:noone
d:pkzip -p file1.zip @list
goto end
:1
d:pkzip -p file2.zip @list
goto end
:2
d:pkzip -p file3.zip @list
goto end
:3
d:pkzip -p file4.zip @list
goto end
:4
d:pkzip -p file5.zip @list
goto end
:5
d:pkzip -p file6.zip @list
goto end
:6
d:pkzip -p file7.zip @list
goto end
:end
del list

I use this to backup all the txt files on my harddrive.  I generally only keep three of the previous zip files, but I took it to 6 just in case I forgot to delete them for a while.  I had to use this method because MS-DOS cannot do a concatenated math function within an IF statement.
0
 
LVL 12

Accepted Solution

by:
mark2150 earned 50 total points
ID: 1722208
Shorter version: You can also do it where the most current file is always FILE1.

@ECHO OFF
IF EXIST FILE5.ZIP DEL FILE5.ZIP
IF EXIST FILE4.ZIP RENAME FILE4.ZIP FILE5.*
IF EXIST FILE3.ZIP RENAME FILE3.ZIP FILE4.*
IF EXIST FILE2.ZIP RENAME FILE2.ZIP FILE3.*
IF EXIST FILE1.ZIP RENAME FILE1.ZIP FILE2.*
PKZIP -r -P FILE1 *.TXT

This will keep the most recent five files on hand and the latest is always FILE1 You can easily expand this logic to however many files you want.

semontgomery is correct, DOS can't do math w/o help.

0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1722209
Either of those batch files look good to me, as long as you don't need unlimited levels of files.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes drives fill up and we don't know why.  If you don't understand the best way to use the tools available, you may end up being stumped as to why your drive says it's not full when you have no space left!  Here's how you can find out...
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question