Hi people, good day.
First of all, i apollogize for my English and i would like to congratulate you for this helpful space.
I am really newby, working with batch files, and i need to create one to do the following task.
I would like to place it on Startup windows section, so it will be checked everytime the computer starts.
I want that, after the next 01 of november 2008 (01-11-2008), it renames to files. One from System32 folder and another from System folder.
However, if i set the computer date to 01 of August 2008(01-08-2008) it restores the original file names.
The problem, that i am getting, is that i think it is only checking the day, and not checking the Month and the Year.
Thank you in advance for your cooperation. My Batch file is going under this message.
@echo off
IF %DATE% EQU 01-01-2008 GOTO NORMAL
if %date% GTR 23-09-2008 GOTO SIM
GOTO FIM
:SIM
IF EXIST C:\WINDOWS\SYSTEM32\SYSMLDB.DLL GOTO EXISTE1
ECHO SIM
GOTO FIM
:EXISTE1
REN C:\WINDOWS\SYSTEM32\SYSMLDB.DLL SYSMIDB.DLL
REN C:\WINDOWS\SYSTEM\SYSMLBD.DLL SYSMIBD.DLL
ECHO EXISTE1
GOTO FIM
:NORMAL
IF EXIST C:\WINDOWS\SYSTEM32\SYSMIDB.DLL GOTO EXISTE2
ECHO NORMAL
GOTO FIM
:EXISTE2
REN C:\WINDOWS\SYSTEM32\SYSMIDB.DLL SYSMLDB.DLL
REN C:\WINDOWS\SYSTEM\SYSMIBD.DLL SYSMLBD.DLL
ECHO EXISTE2
GOTO FIM
:FIM
ECHO FIM
REM EXIT
Handling Dates - Only checking Day and not all Date
Moderator: DosItHelp
-
- Posts: 36
- Joined: 17 Jul 2008 07:37
1. Check that you have the right date format - if you do echo %date% I assume you date format is dd-mm-yyyy
This can vary - mine is dd/mm/yyyy
2. You first section:
The first line is EQU so NORMAL is only used if date = 01-01-2008
Do you need LEQ instead?
3. I would use calls instead of GOTOs. At the moment, if you follow the SIM route, after EXISTE1 says goto FIM, SIM is not completed with that ECHO SIM. Try this instead:
This can vary - mine is dd/mm/yyyy
2. You first section:
Code: Select all
IF %DATE% EQU 01-01-2008 GOTO NORMAL
if %date% GTR 23-09-2008 GOTO SIM
The first line is EQU so NORMAL is only used if date = 01-01-2008
Do you need LEQ instead?
3. I would use calls instead of GOTOs. At the moment, if you follow the SIM route, after EXISTE1 says goto FIM, SIM is not completed with that ECHO SIM. Try this instead:
Code: Select all
@echo off
IF %DATE% LEQ 01-01-2008 CALL :NORMAL
if %date% GTR 23-09-2008 CALL :SIM
REM All the GOTO:EOFs below will lead back to here, once the CALLed subroutines end.
REM The next line jumps to the end, skipping the subroutines.
GOTO FIM
:SIM
IF EXIST C:\WINDOWS\SYSTEM32\SYSMLDB.DLL call :EXISTE1
ECHO SIM
GOTO:EOF
:EXISTE1
REN C:\WINDOWS\SYSTEM32\SYSMLDB.DLL SYSMIDB.DLL
REN C:\WINDOWS\SYSTEM\SYSMLBD.DLL SYSMIBD.DLL
ECHO EXISTE1
GOTO:EOF
:NORMAL
IF EXIST C:\WINDOWS\SYSTEM32\SYSMIDB.DLL CALL :EXISTE2
ECHO NORMAL
GOTO:EOF
:EXISTE2
REN C:\WINDOWS\SYSTEM32\SYSMIDB.DLL SYSMLDB.DLL
REN C:\WINDOWS\SYSTEM\SYSMIBD.DLL SYSMLBD.DLL
ECHO EXISTE2
GOTO:EOF
:FIM
ECHO FIM
REM EXIT
greenfinch wrote:1. Check that you have the right date format - if you do echo %date% I assume you date format is dd-mm-yyyy
This can vary - mine is dd/mm/yyyy
2. You first section:Code: Select all
IF %DATE% EQU 01-01-2008 GOTO NORMAL
if %date% GTR 23-09-2008 GOTO SIM
The first line is EQU so NORMAL is only used if date = 01-01-2008
Do you need LEQ instead?
3. I would use calls instead of GOTOs. At the moment, if you follow the SIM route, after EXISTE1 says goto FIM, SIM is not completed with that ECHO SIM. Try this instead:Code: Select all
@echo off
IF %DATE% LEQ 01-01-2008 CALL :NORMAL
if %date% GTR 23-09-2008 CALL :SIM
REM All the GOTO:EOFs below will lead back to here, once the CALLed subroutines end.
REM The next line jumps to the end, skipping the subroutines.
GOTO FIM
:SIM
IF EXIST C:\WINDOWS\SYSTEM32\SYSMLDB.DLL call :EXISTE1
ECHO SIM
GOTO:EOF
:EXISTE1
REN C:\WINDOWS\SYSTEM32\SYSMLDB.DLL SYSMIDB.DLL
REN C:\WINDOWS\SYSTEM\SYSMLBD.DLL SYSMIBD.DLL
ECHO EXISTE1
GOTO:EOF
:NORMAL
IF EXIST C:\WINDOWS\SYSTEM32\SYSMIDB.DLL CALL :EXISTE2
ECHO NORMAL
GOTO:EOF
:EXISTE2
REN C:\WINDOWS\SYSTEM32\SYSMIDB.DLL SYSMLDB.DLL
REN C:\WINDOWS\SYSTEM\SYSMIBD.DLL SYSMLBD.DLL
ECHO EXISTE2
GOTO:EOF
:FIM
ECHO FIM
REM EXIT
Hi greenfinch,
first of all thank you very much for your quick answer.
I understand your point of view, but my problem is not focus in that issue.
My problem regards the Date problem. For example is these lines:
IF %DATE% LEQ 01-01-2008 CALL :NORMAL
if %date% GTR 23-09-2008 CALL :SIM
It is comparing two date values, in each line.
In the first one it is comparing "%date%" with 01-01-2008,
in the second line it is comparing "%Date%" with 23-09-2008. In this line, it's only comparing the first two numbers (Day), it ignores Month and Year. For this reason, 22-08-2008 is Greater than 20-09-2008, and it is not true.
Why is it not comparing the all date, and only the Day number ?
My Date format is DD-MM-YYYY
Thank you once more
Regards
-
- Posts: 36
- Joined: 17 Jul 2008 07:37
Ah, sorry, I assumed like you that date comparisons worked regardless of format.
But from messing around with this, IF just treats the whole string as a number, not a date, ignoring / or - separators.
So you need to parse the date into a simple number, and your logic will still work:
Regards,
GF
But from messing around with this, IF just treats the whole string as a number, not a date, ignoring / or - separators.
So you need to parse the date into a simple number, and your logic will still work:
Code: Select all
FOR /F "usebackq tokens=1,2,3,* delims=/-" %%a IN ('%date%') DO (set datestring=%%c%%b%%a)
IF %date% LEQ 20080101 CALL :NORMAL
IF %date% GTR 20080923 CALL :SIM
Regards,
GF
greenfinch wrote:Ah, sorry, I assumed like you that date comparisons worked regardless of format.
But from messing around with this, IF just treats the whole string as a number, not a date, ignoring / or - separators.
So you need to parse the date into a simple number, and your logic will still work:Code: Select all
FOR /F "usebackq tokens=1,2,3,* delims=/-" %%a IN ('%date%') DO (set datestring=%%c%%b%%a)
IF %date% LEQ 20080101 CALL :NORMAL
IF %date% GTR 20080923 CALL :SIM
Regards,
GF
Thank you greenfinch, once more for your fast cooperation.
Your opinion was helpful, although i needed to change a little bit. This was the syntax i used.
FOR /F "usebackq tokens=1,2,3,* delims=/-" %%a IN ('%date%') DO (set datestring=%%c%%b%%a)
IF %datestring% EQU 20080101 goto NORMAL
IF %datestring% GTR 20080923 goto SIM
GOTO FIM
Can you please explain me the first line "FOR /F "usebackq tokens=1,2,3,* delims=/-" %%a IN ('%date%') DO (set datestring=%%c%%b%%a)
Whats the difference between using GOTO and CALL ?
Is there any link where i can fing examples of batch files. Just for learning and training proposes ?
Thank you again[/i]
-
- Posts: 36
- Joined: 17 Jul 2008 07:37
This very site is as good as any for learning:
http://www.dostips.com/
FOR help:
http://www.dostips.com/forum/viewtopic.php?t=292
GOTO will go to wherever you point, then continue 'down the page'. Only usable within a file.
CALL can be used within a file, but can also call other batch files:
CALL :subroutine
or
CALL anotherbatch.cmd
If used in to call a subroutine (CALL :thismarker) command processing will continue until the end of the file, or until it hits a GOTO:EOF, but then jumps back to the line after the CALL.
You can see this in the way I redid your script.
HTH,
GF
http://www.dostips.com/
FOR help:
http://www.dostips.com/forum/viewtopic.php?t=292
GOTO will go to wherever you point, then continue 'down the page'. Only usable within a file.
CALL can be used within a file, but can also call other batch files:
CALL :subroutine
or
CALL anotherbatch.cmd
If used in to call a subroutine (CALL :thismarker) command processing will continue until the end of the file, or until it hits a GOTO:EOF, but then jumps back to the line after the CALL.
You can see this in the way I redid your script.
Code: Select all
:subroutine-marker
REM some commands here
GOTO:EOF
HTH,
GF