Articles

bat for comparing date

January 26, 2005 at 21:11:16
Specs: XP, 2.8/512

Hi,

I want to write a small bat file to read the current date of the computer and compare it with a preset date I put at the beginning of the bat file (for exampel: set mydate="wed 10/10/2005") and if these two dates are the same then delete a target file in c:\windows\system32\drivers\ directory.
I want to put this bat file in xp startup folder and every time computer boots up I want it to do this comparison. To protect the source bat file I need to do of the followings:

1. If date is the same as my preset date then after deleting target file in windows directory I want bat file also to be removed from startup folder of XP (probably need an expression to be loaded to registry).

2. convert bat to com or exe and put it in startup and in this case in case of two dates being same target file will be deleted and there is no need com/exe converted of bat file to be removed from startup since bat commands are not accessible.

I tried this for several days but couldn't do it. Could someone expert in bat writing please help me in writing a proper program and help finding procedure for one of the above options? Using bat2exec is not easy since all the time I get errores like "out of environmental space" or "can not load VDM IPX/SPX support".

Thanks
Steve



See More: bat for comparing date

Report •


#1
January 26, 2005 at 21:22:31

Have a look here - but also be advised that XP is not DOS based, and this is not really the best forum for your question


I'm not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself?


Report •

#2
January 26, 2005 at 22:04:41

Hi Steve,

I'm not clear on what your trying to accomplish, beyong deleting a file based on a date comparison.

But first, you can cut your losses with bat2exe.

I've been messing with it on and off for years and it's useless for all but the most trivial of batch files.

And that's with "REAL" DOS. Which NT DOS-like services AIN'T.

Second, I don't know that it's such a great idea to automate the deletion of a file in in the system32 directory; or anywhere else in windows. But it's your computer.

If you're using a batch in XP/NT you can you the additonal power of NT. In this case:

%~tI - expands %I to date/time of file

With that, it's pretty straightforward to script a deletion based on date.

HTH

M2


Report •

#3
January 27, 2005 at 00:42:26

Thanks. I found ftp://garbo.uwasa.fi/pc/batchutil/pwrbt14j.zip which looks great. It has extra commands and accept dos bat commands too and has its own comiler (powermak) and makes exe file from bat like a dream. After spending about an hour reading it's documents and fixing syntax errors my exe now is ready and working fine. I recommend this program to whoever works with bat files very often and wants to make exe from them.

Steve


Report •

Related Solutions

#4
January 27, 2005 at 00:49:20

Thanks for the response but it is still not
the correct forum for NT Command Prompt
Questions, this is after all a DOS forum!



Report •

#5
January 27, 2005 at 01:16:01

Hi Steve,

That pwrbat compiler sounds goo. I'm trying to get it now.

As ever the challenge for a script wrietr is to get the thing done with no 3rd party utils, if making it available to others is a factor.

FWIW, in that same vein, I spent years in real DOS trying to get the date and time into environment varibles without using any external commands.

I never did figure it out, but discovered the trick by reading somebody else's cade.


M2


Report •


Ask Question