Solved

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

Posted on 1998-09-05
5
760 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

No single Antivirus application (despite claims by manufacturers) will catch or protect you from all Virus / Malware or Spyware threats. That doesn't stop you from further protecting yourself however - and this article is to show you how.
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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.

752 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