Michael Edward Britt
Michael Edward Britt

Reputation: 11

I can't see why an "IF" won't work in my .BAT File

When the last command in this program:

If %V_EOM% EQU V_Day Set V_Type = M

Is executed, the the .BAT file run just goes away and the following pause is not executed. I just don't see the problem.

Rem XCopy C: Britt* Folders to Backup
Rem *************************************

Rem Set EOM/Daily Switch
Set V_Type = D

Rem Set /d Switch
Set V_DSwitch = /d

Set V_Output_Drive = G:\
Set V_File_Name_1 = XCopy
Set V_File_Name_2 = Backup
Set V_File_Name_3 = Daily

Date /t
Time /t

set V_Date = %date:~0,20%
set V_DOW = %date:~0,3%
set V_Mo= %date:~4,2%
set V_Day = %date:~7,2%
set V_Yr= %date:~10,4%

Rem EOM Check
If %V_Mo%  EQU 04 GoTo Mo30:
If %V_Mo%  EQU 06 GoTo Mo30:
If %V_Mo%  EQU 09 GoTo Mo30:
If %V_Mo% EQU 11 GoTo Mo30:
If %V_Mo% EQU 02 GoTo Mo28:
GoTo Mo31:

:Mo28
Set V_EOM = 28
GoTo CkEOM:

:Mo30
Set V_EOM =30

:Mo31
Set V_EOM = 31
GoTo CkEOM:

Rem Check to see if today is the End of Month
:CkEOM
pause
If %V_EOM% EQU V_Day Set V_Type = M
pause

Revised code transferred from "answer"

set V_Date = %date:~0,20%
set V_DOW = %date:~0,3%
set V_Mo = %date:~4,2%
set V_Day = %date:~7,2%
set V_Yr = %date:~10,4%
Set V_Out_Date = %V_Yr %%V_Mo %%V_Day %
Set V_File_Name_1=XCopy.Backup
Set V_File_Name_2=Daily
Set V_File_Name_3= %V_Out_Date %
Set V_Dir=Britt Michael

Gives me: XCopy.Backup Daily 2015 02 06 Question: How do I make the output = XCopy.Backup.Daily 2015-02-06

Upvotes: 1

Views: 70

Answers (1)

Jason Faulkner
Jason Faulkner

Reputation: 6568

The line:

If %V_EOM% EQU V_Day Set V_Type = M

Should probably be:

If %V_EOM% EQU %V_Day% Set V_Type=M

In general though, your script syntax is off. For example:

Set V_File_Name_1 = XCopy

Will create the variable %V_File_Name_1 % (space on the end) which means %V_File_Name_1% would be undefined. Additionally the value would be (space)XCopy (space in front) and not just XCopy.

Since you are using the syntax:

Set Var = Value

with spaces between the =, your logic is likely to fail on comparisons.

Update them to use the syntax:

Set Var=Value

or

Set "Var=Value"

Upvotes: 5

Related Questions