2012-08-07 112 views
0

我正在拉我的頭髮! 這個批處理文件在我的windows 7筆記本電腦上運行得很好,但是當我嘗試從Windows 2003服務器或XP計算機上運行它時,它不起作用。該腳本如下,這並不在XP的工作部分是:批處理文件不能在XP上運行Windows 7

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 
+0

定義「它不工作」。它提前終止,拋出錯誤,什麼? – LittleBobbyTables 2012-08-07 19:48:28

+1

你怎麼知道第一個代碼塊是什麼讓它「不工作」? – indiv 2012-08-07 19:49:25

+0

如果今天的日期(%Sunday%)和設定的未來日期(%Monday%或%Sunday)不相同,它會在其中複製所有PDF的設置變量(%Sun_Find%或%Mon_Find%)命名另一個文件夾。 – jardane 2012-08-07 19:54:22

回答

1

DATE /T命令可以使用不同的日期格式您的Windows 7與您的XP和Server 2003中,肯定會導致問題。只需在所有三臺機器上運行命令,看看它們是否使用相同的格式。

解析DATE /T%DATE%總是有風險,因爲機器之間可能存在差異。

您已經在使用VBS。爲什麼不把整個項目移到VBS?或者至少從VBS獲取當前的日期信息。