Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.datSo 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?

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_ERRORCOPY C:\HISTORY\%YY%\%MON%\BACKMEUP.DAT D:\BACKUPS\HISTORY\%YY%\%MON%\

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

![]() |
![]() |
![]() |

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