Discussion Locked

Sequential Filenames in DOS

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a need to be able to determine if a file exists in a specific location and if it does, do create a new file, with the next sequential number. Ie if we find HED000003.xls, I want to be able to create HED000004.xls etc. Is there a way to automate this within a DOS batch file?

5 replies

by rob wolfe

I cannot imagine a way to do this from a real "honest-to-God" DOS .BAT file. If you are really doing this from within a DOS box on any kind of Windows box i would suggest that you take a look and see if you have the Windows Scripting Host installed (98, NT4 and 2000 come with it installed and it is available as a download from MS for 95). This will let you write a nifty little VBscript (or javascript) program to do it.

The string and number handling capabilities of these are a little (ok a lot) more robust than plain old vanilla .BAT files.

This should be a pretty trivial little program to write if you know either of the "Xscripts" at all.

Hope this points you part way there. I would write up the script but real work is rearing its ugly head.

by achp

domake.bat:
===========

@echo off
call makenext %1 %2 %3 %4 %5 %6 %7
if %found%==1 echo > %thename%
set found=
set thename=

makenext.bat:
=============

set found=0

if "%2"=="" goto finalname

for %%1 in (0 1 2 3 4 5 6 7 8 9) do call recurse %1%%1 %3 %4 %5 %6 %7 %8

goto quit

:finalname

if exist %1 goto quit

set found=1
set thename=%1

:quit

recurse.bat:
============

if %found%==0 call makenext %1 %2 %3 %4 %5 %6 %7

This discussion is closed to new replies.