Computing.Net > Forums > Disk Operating System > Batch: current date into variable?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch: current date into variable?

Reply to Message Icon

Name: Shmanda
Date: May 29, 2003 at 00:00:11 Pacific
OS: DOS 6.22 only!
CPU/Ram: P3 533Mhz, 128MB
Comment:

I'm trying to make a batch program which will copy (backup) only the current month's files. The files are stored by their dates, like this:

May 03 file: C:\history\03\MAY\backmeup.dat
Jan 02 file: C:\history\02\JAN\backmeup.dat

So far I've had to prompt the user for the current date and time, but that is causing confusion. I also tried saving the date in a temp.bat but all I get is the long format and there isn't a "substring" type command (that I know of).

Is there a way to get the current 2-digit year and the current 3-letter month (or even the 2 digit month which is easy to change) into variables?



Sponsored Link
Ads by Google

Response Number 1
Name: Shmanda
Date: May 29, 2003 at 04:07:08 Pacific
Reply:

Ah-Hah! I've found the solution at www.batch.hpg.ig.com.br
If anyone is interested, here is the relevant part of the finished file:

SET MON=FOO

if "%1"=="GoTo" goto %2
echo e180 BF 07 01 B4 04 CD 1A E8 02 00 89 CA E8 00 00> %temp%.\t1.src
echo e18F 86 D6 88 D0 D4 10 0D 30 30 86 C4 AB 47 C3>> %temp%.\t1.src
for %%? in (rip 180 g w q) do echo %%?>> %temp%.\t1.src
echo SET %%1=XX XX XX XX> %temp%.\t2.bat
DEBUG %temp%.\t2.bat nul
call %temp%.\t2.bat _
%0 GoTo parse %_% MM DD YC YY
:parse
set %7=%3
shift
if not "%7"=="" goto parse
for %%? in (t1.src t2.bat) do del %temp%.\%%?
set _=

IF "%MM%"=="01" SET MON=JAN
IF "%MM%"=="02" SET MON=FEB
IF "%MM%"=="03" SET MON=MAR
IF "%MM%"=="04" SET MON=APR
IF "%MM%"=="05" SET MON=MAY
IF "%MM%"=="06" SET MON=JUN
IF "%MM%"=="07" SET MON=JUL
IF "%MM%"=="08" SET MON=AUG
IF "%MM%"=="09" SET MON=SEP
IF "%MM%"=="10" SET MON=OCT
IF "%MM%"=="11" SET MON=NOV
IF "%MM%"=="12" SET MON=DEC
IF "%MON%"=="FOO" GOTO DATE_ERROR

COPY C:\HISTORY\%YY%\%MON%\BACKMEUP.DAT D:\BACKUPS\HISTORY\%YY%\%MON%\


0

Response Number 2
Name: Secret_Doom
Date: May 29, 2003 at 16:18:41 Pacific
Reply:

Ah-Hah! So it seems that my FAQ is actually contributing for the diminish of FAQ postings on the DOS/batch forums! =D

Just a note, Shmanda - the following line:

if "%1"=="GoTo" goto %2

Should appear before any code from the file, except for maybe a "@echo off" line and comment lines. The way you wrote it, the command "SET MON=FOO" will be executed everytime a subroutine is invoked. That means if you change the value of the variable MON before the :parse label, its value will be reset to FOO after it.

-- Leonardo Pignataro - Secret_Doom --

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







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: Batch: current date into variable?

Date into a variable, with 2 digit year! www.computing.net/answers/dos/date-into-a-variable-with-2-digit-year/11289.html

Renaming file to current date. www.computing.net/answers/dos/renaming-file-to-current-date/10321.html

Rename file with current date www.computing.net/answers/dos/rename-file-with-current-date/13069.html