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

creating file names with the date in DOS

Reply to Message Icon

Original Message
Name: Andy
Date: February 2, 2002 at 10:48:49 Pacific
Subject: creating file names with the date in DOS
Comment:

Hi

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

Thanks


Report Offensive Message For Removal


Response Number 1
Name: chris
Date: February 2, 2002 at 11:28:12 Pacific
Subject: creating file names with the date in DOS
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 2
Name: Secret_Doom
Date: February 2, 2002 at 18:12:51 Pacific
Subject: creating file names with the date in DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 3
Name: Secret_Doom
Date: February 2, 2002 at 18:17:25 Pacific
Subject: creating file names with the date in DOS
Reply: (edit)

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


Report Offensive Follow Up For Removal

Response Number 4
Name: chris
Date: February 3, 2002 at 02:10:44 Pacific
Subject: creating file names with the date in DOS
Reply: (edit)

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

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


Report Offensive Follow Up For Removal

Response Number 5
Name: Andy
Date: February 3, 2002 at 09:56:41 Pacific
Subject: creating file names with the date in DOS
Reply: (edit)

Thanks Guys

You've helped me to solve my original problem.

Cheers

Andy


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: creating file names with the date in DOS

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 2 Days.
Discuss in The Lounge