Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to open a .vcf file 11 53
adobe premier render 10 39
Bios question 14 33
Wants to Upgrade fro Vista to Windows 10 9 35
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…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

920 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

16 Experts available now in Live!

Get 1:1 Help Now