批处理文件不能仅在Windows XP上运行

时间:2012-08-07 19:46:08

标签: windows-7 batch-file windows-xp

我正在拔头发! 这个批处理文件在我的Windows 7笔记本电脑上运行得很好,但是当我尝试从Windows 2003服务器或xp计算机运行它时它的部分工作不起作用。脚本如下,在XP上不起作用的部分是:

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"
    )
)

我在这里完全失去了,这需要尽快修复,因为我的屁股就行了。 ħ

以下是完整代码:

@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

1 个答案:

答案 0 :(得分:1)

{7}命令可能在Windows 7与XP和Server 2003上使用不同的日期格式。这肯定会导致问题。只需在所有三台机器上运行该命令,看它们是否使用相同的格式。

解析DATE /TDATE /T总是有风险的,因为机器之间可能存在差异。

您已使用VBS。为什么不将整个项目转移到VBS?或者至少从VBS获取当前日期信息。