简体   繁体   中英

Batch file will not run on XP only Windows 7

I am pulling my hair out! This batch file runs just fine on my windows seven laptop but when i try to run it from a windows 2003 server or an xp computer parts of it don't work. The script is below, the part that does not work on XP is:

rem check if it's sunday or not
IF NOT %Sunday%==%TODAY% (

    chdir "C:\e-edition_upload\tecnavia-archives"
    setlocal EnableDelayedExpansion
    for %%f in (*%Sun_Find%*.pdf) do (
       set "filename=%%f"
       if "!filename:~4,4!" equ "%Sun_Find%" move "%%f" "C:\e-edition_upload\sunday"
    )
)
rem check if it's monday or not
IF NOT %Monday%==%TODAY% (
    chdir "C:\e-edition_upload\tecnavia-archives"
    setlocal EnableDelayedExpansion
    for %%f in (*%Mon_Find%*.pdf) do (
       set "filename=%%f"
       if "!filename:~4,4!" equ "%Mon_Find%" move "%%f" "C:\e-edition_upload\monday"
    )
)

I am at a total loss here and this needs to be fixed asap because my butt is on the line. H

Here is the full code:

@echo on
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set year=%year:~-2%
set TODAY=%month%%day%%year%

rem find the date of the next monday
>NextMon.vbs echo NextMonday=FormatDateTime(Date+(9-Weekday(Date)))
>>NextMon.vbs echo SY=Year(NextMonday)
>>NextMon.vbs echo SM=Month(NextMonday)
>>NextMon.vbs echo SD=Day(NextMonday)
>>NextMon.vbs echo wscript.echo SY ^& "," ^& SM ^& "," ^& SD
For /f "tokens=1-3 delims=," %%A in ('cscript //nologo NextMon.vbs') do (
    Set mon_yyyy=%%A
    Set mon_mm=%%B
    Set mon_dd=%%C
)
del NextMon.vbs
If %mon_mm% lss 10 Set mon_mm=0%mon_mm%
If %mon_dd% lss 10 Set mon_dd=0%mon_dd%
Set mon_Year=%mon_yyyy:~-2%
Set Monday=%mon_mm%%mon_dd%%mon_Year%

rem find the date of the next sunday
>NextSun.vbs echo NextSunday=FormatDateTime(Date+(8-Weekday(Date)))
>>NextSun.vbs echo SY=Year(NextSunday)
>>NextSun.vbs echo SM=Month(NextSunday)
>>NextSun.vbs echo SD=Day(NextSunday)
>>NextSun.vbs echo wscript.echo SY ^& "," ^& SM ^& "," ^& SD
For /f "tokens=1-3 delims=," %%A in ('cscript //nologo NextSun.vbs') do (
    Set sun_yyyy=%%A
    Set sun_mm=%%B
    Set sun_dd=%%C
)
del NextSun.vbs
If %sun_mm% lss 10 Set sun_mm=0%sun_mm%
If %sun_dd% lss 10 Set sun_dd=0%sun_dd%
Set Sun_Year=%sun_yyyy:~-2%
Set Sunday=%sun_mm%%sun_dd%%Sun_Year%
Set Sun_Find=%sun_mm%%sun_dd%
Set Mon_Find=%mon_mm%%mon_dd%

rem check if it's sunday or not
IF NOT %Sunday%==%TODAY% (

    chdir "C:\e-edition_upload\tecnavia-archives"
    setlocal EnableDelayedExpansion
    for %%f in (*%Sun_Find%*.pdf) do (
       set "filename=%%f"
       if "!filename:~4,4!" equ "%Sun_Find%" move "%%f" "C:\e-edition_upload\sunday"
    )
)
rem check if it's monday or not
IF NOT %Monday%==%TODAY% (
    chdir "C:\e-edition_upload\tecnavia-archives"
    setlocal EnableDelayedExpansion
    for %%f in (*%Mon_Find%*.pdf) do (
       set "filename=%%f"
       if "!filename:~4,4!" equ "%Mon_Find%" move "%%f" "C:\e-edition_upload\monday"
    )
)
md "C:\e-edition_upload\newsbank\%TODAY%"
xcopy /s "C:\e-edition_upload\tecnavia-archives" "C:\e-edition_upload\newsbank\%TODAY%"
pause

The DATE /T command may be using different date formats on your Windows 7 vs. your XP and Server 2003. That would certainly cause problems. Simply run the command on all three machines to see if they are using the same format.

Parsing DATE /T or %DATE% is always risky because there can be differences between machines.

You are already using VBS. Why not move the entire project into VBS? Or at least get the current date info from VBS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM