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

Windows 7 批处理文件不会仅在XP Windows 7上运行,windows-7,batch-file,windows-xp,Windows 7,Batch File,Windows Xp,我在拔头发! 这个批处理文件在我的Windows7笔记本电脑上运行得很好,但当我试图从Windows2003服务器或xp计算机上运行它时,它的一部分无法工作。脚本如下所示,在XP上不起作用的部分是: rem check if it's sunday or not IF NOT %Sunday%==%TODAY% ( chdir "C:\e-edition_upload\tecnavia-archives" setlocal EnableDelayedExpansion

我在拔头发! 这个批处理文件在我的Windows7笔记本电脑上运行得很好,但当我试图从Windows2003服务器或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"
    )
)
我在这里完全不知所措,这需要尽快修复,因为我的屁股在线上。H

以下是完整的代码:

@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

DATE/T
命令可能在Windows 7和XP及Server 2003上使用了不同的日期格式。这肯定会引起问题。只需在所有三台机器上运行该命令,查看它们是否使用相同的格式

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


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

定义
它不起作用
。它是否提前终止,抛出错误,什么?您如何知道第一个代码块是它“不工作”的原因?它所做的是,如果今天的日期(%Sunday%)和设定的未来日期(%Monday%或%Sunday)不相同,它会用一个集合变量(%Sun_Find%或%Mon_Find%)复制所有PDF它不会抛出任何错误,但当我在windows y笔记本电脑上运行它时,它会移动文件,但当我在XP计算机或服务器上运行它时,文件不会移动。