Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 1998-09-05
5
Medium Priority
?
763 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 200 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

Turn your laptop into a mobile console!

The CV211 Laptop USB Console Adapter provides a direct Laptop-to-Computer connection for fast and easy remote desktop access with no software to install.

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file back.
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…
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…

705 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