VOGONS

Common searches


First post, by Pragmasaurus

User metadata
Rank Newbie
Rank
Newbie

I'm making a game menu batch file for my son's first computer ( they just don't make edutainment like they used to) and I want to be able to access system date so I can have special games appear on special days. I tried to use the %date% environment variable, but it doesn't seem to exist. Is there a way to do this, or do I need to run it through actual DOS?

Sorry if this was already answered, I tried searching but these terms are all commonly used in other unrelated posts.

Reply 1 of 8, by cyclone3d

User metadata
Rank l33t++
Rank
l33t++

https://www.ihaveapc.com/2011/12/how-to-quick … command-prompt/

Use that and the set command to make your own date / time variable.

Yamaha modified setupds and drivers
Yamaha XG repository
YMF7x4 Guide
Aopen AW744L II SB-LINK

Reply 2 of 8, by RacoonRider

User metadata
Rank Oldbie
Rank
Oldbie

A long time ago I made a *.bat script that copies autoexec.bat and config.sys into a folder named after current date on startup. It should serve as a working example, but I don't really remember the contents anymore 😀

I'll drop it here once I get home in a few hours.

Reply 3 of 8, by RacoonRider

User metadata
Rank Oldbie
Rank
Oldbie

OK, here goes:

@echo off
VER|DATE>TEMP.BAT
ECHO SET DATE=%%4>CURRENT.BAT
CALL TEMP.BAT
DEL TEMP.BAT
DEL CURRENT.BAT

md C:\AUTOBACK\%DATE%
copy C:\AUTOEXEC.BAT C:\AUTOBACK\%DATE%
copy C:\CONFIG.SYS C:\AUTOBACK\%DATE%
ECHO Backup created on %DATE%

It has been quite a long time since I dived into this so I can no longer comment on the trick with two temp files in the first paragraph. However, I'm sure that this script works in DOS.

Reply 4 of 8, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Cute trick, but needs a few tweaks to work with the internal shell of DOSBox SVN:

@ECHO OFF
DATE>TEMP.BAT
ECHO SET DATE=%%3>CURRENT.BAT
CALL TEMP.BAT
DEL TEMP.BAT
DEL CURRENT.BAT
ECHO %DATE%
IF %DATE%==02/29/2020 ECHO Today is Leap Day

The VER| part is not needed because the DATE command in DOSBox SVN does not pause for input of the new date, and piping is not supported in any case.

Note that only SVN builds of DOSBox have the DATE command built into the internal shell. This alternate approach with the DIR command should work in 0.74(-3) or SVN, but you'll have to excuse the error message that is not easy to avoid:

@ECHO OFF
ECHO SET DATE=%%3>TEMP2.BAT
DIR TEMP2.BAT>TEMP1.BAT
CALL TEMP1.BAT
DEL TEMP1.BAT
DEL TEMP2.BAT
ECHO %DATE%
IF %DATE%==29-02-2020 ECHO Today is Leap Day

Reply 5 of 8, by Pragmasaurus

User metadata
Rank Newbie
Rank
Newbie

Thanks ripsaw, this works now that I have the SVN build. I'm eventually planning on running this batch file on this USB version of Dosbox, so hopefully I can just drop the SVN build in without messing anything up. (Edit: I just saw your edit and got it working on 0.74-3. The error message is not an issue since I'm clearing the screen immediately anyways.)

My next problem is that I need to isolate the day and month, since the year is not relevant for recurring holidays. As far as I can tell there are no string manipulation functions available.
I confess that I don't really understand how this trick works to begin with. It looks like we're storing the results of the "DATE" command in temp.bat (which should be "Current date: Wed 02/26/2020"), and then storing "SET DATE=%%3" in current.bat. I'm not sure why, since it doesn't look like current.bat is ever called. Can you explain what is happening?

Reply 6 of 8, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author
Pragmasaurus wrote on 2020-02-26, 17:06:

My next problem is that I need to isolate the day and month, since the year is not relevant for recurring holidays. As far as I can tell there are no string manipulation functions available.

Yeah, there is only so much one can do with old DOS batch files. You could write a simple DOS program that formats the date as you like, but if you can't or don't want to do that then perhaps a pre-made program will suit your needs. If interested, check out STRINGS, it can do a bunch of string manipulation stuff including substrings and working with environment variables.

Pragmasaurus wrote on 2020-02-26, 17:06:

It looks like we're storing the results of the "DATE" command in temp.bat (which should be "Current date: Wed 02/26/2020"), and then storing "SET DATE=%%3" in current.bat. I'm not sure why, since it doesn't look like current.bat is ever called. Can you explain what is happening?

"Current date: Wed 02/26/2020" is the command that is executed by TEMP.BAT, and the "Current" at the beginning runs CURRENT.BAT with the date as the 3rd parameter that is set into the environment variable. The approach with DIR does a similar thing; now see if you can figure out why the error message happens. 😀

Reply 7 of 8, by Pragmasaurus

User metadata
Rank Newbie
Rank
Newbie

Ah, I see it now. Reminds me of those obfuscated C programming competitions.

As for the strings, I'll probably just take the lazy way out and check the date for the next 20 years. If my kid is still using this batch file in 2040, he can write himself a new one 😁

Reply 8 of 8, by ripsaw8080

User metadata
Rank DOSBox Author
Rank
DOSBox Author
Pragmasaurus wrote on 2020-02-26, 19:45:

I'll probably just take the lazy way out and check the date for the next 20 years.

Ah, well, easy for events that fall on a specific month/day, but kind of a pain for the others. 😉