Solved

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

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

Wish Marketing would stop bothering you?

Is your marketing department constantly asking for new email signature updates? Are they requesting a different design for every department? Do they need yet another banner added? Don’t let it get you down! There is an easy way to manage all of these requests...

Join & Write a Comment

If you Lost your Administrator password for Windows XP, Vista, or 7 this CD will help you reset the password to blank so you can log in. Once in you should change that blank password to something!! Download the ISO on this page http://www.spl…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
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.

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now