Create a file with a batch

Hi, I need to create a batch that creates a txt file, here is the fun part the batch will run every 1 to 5 minutes (the time is not impotant)  and a new file will be created with a new name, this name has to be in sequence to the last one created or we can have the time it was created (HH:MM:SS)

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

you did not mention the language, so i suppose you need win* batch :-)
the problem is how to create next file name in the sequence, where
win* batch language lacks basic arithmetics and string functions.

so, here is a batch file to create a new file name in the sequence.
the file name will be <directory>\<prefix><number>.<extension>
the output is put in the NEWNAME shell variable, so you can use it
in another batch. It will generate sequences of up to 10000 file names,
but it can be easily extended.

this batch will run on (almost) every version of win* (and DOS).
It can be simplified a bit if you're using only XP...
With WinXP, it can be extended to add current date to the file name
or create a directory with current date as the name,
and so to create up to 10000 file name daily. Ask if you need that.

----8<---- newname.bat ----8<----
@echo off

rem ---- configuration ----
set DDIR=c:\destination\directory
set PREFIX=f_
set EXT=txt
rem --- end of config ----

set A=0
set B=0
set C=0
set D=0
if not exist %NEWNAME% goto end
if %A%==9 goto 20
set V=A
set X=%A%
goto inc
if %B%==9 goto 30
set V=B
set X=%B%
set A=0
goto inc
if %C%==9 goto 40
set V=C
set X=%C%
set B=0
set A=0
goto inc
if %D%==9 goto fail
set V=D
set X=%D%
set C=0
set B=0
set A=0
goto inc

if %X%==0 goto 1
if %X%==1 goto 2
if %X%==2 goto 3
if %X%==3 goto 4
if %X%==4 goto 5
if %X%==5 goto 6
if %X%==6 goto 7
if %X%==7 goto 8
set %V%=9
goto try
set %V%=1
goto try
set %V%=2
goto try
set %V%=3
goto try
set %V%=4
goto try
set %V%=5
goto try
set %V%=6
goto try
set %V%=7
goto try
set %V%=8
goto try


set A=
set B=
set C=
set D=
set X=
set V=
----8<---- end of newname.bat ----8<----

----8<---- usage example ----8<----
@echo off

rem this example runs on XP, where date /T is available

call newname.bat
if %NEWNAME%a==a goto full_house
echo first line in the new file >%NEWNAME%
date /T>>%NEWNAME%
time /T>>%NEWNAME%
goto end

echo all file names are used!

----8<---- end of usage example ----8<----

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Hi guys,

Not shooting for points here but I came up against a similar issue with trying to date stamp a file and found this script which is quite cool. It puts all the different date/time parts into environment variables which can then be referenced using %DD%/%MM%/%YY% %HH%:%MIN%:%SS% or any other combo of these variables.

REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
      For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
            set dow=%%i
            set %%a=%%j
            set %%b=%%k
            set %%c=%%l
            set hh=%%m
            set min=%%n
            set ss=%%o
if %HH%==10 goto end
if %HH%==11 goto end
if %HH%==12 goto end
set HH=0%HH%

REM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.