1.

Solve : BATCH - DATE /t combining with IF?

Answer»

With all the tools AVAILABLE on WINDOWS machines, I'm surprised to see batch code still in use.

Code: [Select]@echo off
set today=%date:~4,10%
for /f %%X in (date.txt) do (
if %today%==%%x goto play
)
goto forbidden

:play
start notepad.exe
echo Able to play
pause
exit

:forbidden
echo Unable to play
pause
exit

Date.txt: one date per line in your regional format. Based on your console output, mm/dd/yyyy

If you were planning on getting the date data from the web, there are techniques available in VBScript (free & installed on your machine already) or any of the other Windows Script languages.



PS. Actually I meant Powershell not the Windows Shell. Powershell is the cmd prompt on steroids. It is an optional download for XP. I was just curious if it came installed with Vista.Sorry, but that code doesn't work. He does FIND the file because when i put an invalid filename it says "Can't find X-file".
When i put one date in the date.txt, it doesn't work
When i put multiple dates in the date.txt, it (ofcourse) doesn't work either.

But a friend of mine got a solution for this, at least, he said that so the real question of this topic is answered. A lot of thanks for your quick and solid help.

The final solution to use dates in an if-statement in a batch-script:
Code: [Select]@echo off
REM sets the input-date to mm/dd/yyyy
set today=%date:~4,10%
REM put below the dates
if "%today%"=="01/09/2008" set td=g
if "%today%"=="09/01/2008" set td=g
if "%td%"=="g" (Goto play) ELSE (Goto forbidden)

REM matched date will start this
:play
start notepad.exe
echo Able to play
pause
exit

REM unmatched date will start this
:forbidden
echo Unable to play
pause
exit

PS. Well, as far as i know or searched, it isn't included with Vista.



Discussion

No Comment Found