0

我正在拔头发!这个批处理文件在我的 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"
    )
)

我在这里完全不知所措,这需要尽快修复,因为我的屁股在线。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
4

1 回答 1

1

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

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

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

于 2012-08-08T03:41:31.817 回答