Computing.Net > Forums > Disk Operating System > creating file names with the date in DOS

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

creating file names with the date in DOS

Reply to Message Icon

Name: Andy
Date: February 2, 2002 at 10:48:49 Pacific
Comment:

Hi

How do I name a file with the current date in DOS? E.g. 20020202.txt

Thanks



Sponsored Link
Ads by Google

Response Number 1
Name: chris
Date: February 2, 2002 at 11:28:12 Pacific
Reply:

I don't think this can be done using batch commands/variables. Please see my post on the previous thread "reading text from a file" about the use of Qbasic to do this kind of thing. It would take, literally, just a few lines of Basic to do exactly what you want.

I've left Qbasic behind about 10 years ago, but I can tell you for a fact that what you want to do can be done in just 3 short lines of code.


0

Response Number 2
Name: Secret_Doom
Date: February 2, 2002 at 18:12:51 Pacific
Reply:

WHAT? What did you said? Of course it's possible! It seems that some people are underestimating batch language these days...


@echo off
if "%3"=="" if not "%2"=="" if exist %1.%2 goto start
echo ERROR: invalid parameters, parameter missing or excess of parameters.
echo SINTAX: %0 filename fileextention
echo.
goto eof
:start
echo @PROMPT SET DATE=$D$_> %temp%.\$$tmp.bat
%comspec% /c %temp%.\$$tmp.bat > %temp%.\$$tmp2.bat
echo e111';'> %temp%.\$$tmp.bat
echo e114';'>> %temp%.\$$tmp.bat
echo w>> %temp%.\$$tmp.bat
echo q>> %temp%.\$$tmp.bat
debug.exe %temp%.\$$tmp2.bat < %temp%.\$$tmp.bat > nul
call %temp%.\$$tmp2.bat
echo SET DATE=%%2%%3%%4> %temp%.\$$tmp.bat
call %temp%.\$$tmp.bat;%date%
for %%d in (tmp.bat tmp2.bat) do if exist %temp%.\$$%%d del %temp%.\$$%%d
REN %1.%2 %DATE%.%2
:eof


Be aware of line wrapping (cut-paste this text and I think it will be alright)

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 3
Name: Secret_Doom
Date: February 2, 2002 at 18:17:25 Pacific
Reply:

Oh, I forgot saying:

CUT-PASTE that text and save it with a .bat extention. It will become a batch file (executable)

The sintax is:

batchname filename fileextention

Let's say you save it with the name COPYDATE.BAT, and you want to rename the file DATA.TXT to 02032002.TXT:

copydate data txt

Got it?

-- Secret_Doom - Leonardo Pignataro --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Response Number 4
Name: chris
Date: February 3, 2002 at 02:10:44 Pacific
Reply:

Mr Doom. Wonderful! :):):)#

You've proved my point brilliantly. But why on earth go to all that palaver?


0

Response Number 5
Name: Andy
Date: February 3, 2002 at 09:56:41 Pacific
Reply:

Thanks Guys

You've helped me to solve my original problem.

Cheers

Andy


0

Related Posts

See More


Reply to Message Icon

Reading text from a file running old DOS on new ha...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: creating file names with the date in DOS

File names www.computing.net/answers/dos/file-names/4730.html

Chek the date in batfile... www.computing.net/answers/dos/chek-the-date-in-batfile/12933.html

resetting the date in dos www.computing.net/answers/dos/resetting-the-date-in-dos/13998.html