好像这段代码没改对。。。复制代码
- (for /f "usebackq tokens=1-9 delims= " %%a in ("%temp%\FileDate.txt") do (
- setlocal enabledelayedexpansion
- if "%%f" equ "Jan" (
- set FileM=01
- ) else if "%%f" equ "Feb" (
- set FileM=02
- ) else if "%%f" equ "Mar" (
- set FileM=03
- ) else if "%%f" equ "Apr" (
- set FileM=04
- ) else if "%%f" equ "May" (
- set FileM=05
- ) else if "%%f" equ "Jun" (
- set FileM=06
- ) else if "%%f" equ "Jul" (
- set FileM=07
- ) else if "%%f" equ "Aug" (
- set FileM=08
- ) else if "%%f" equ "Sep" (
- set FileM=09
- ) else if "%%f" equ "Oct" (
- set FileM=10
- ) else if "%%f" equ "Nov" (
- set FileM=11
- ) else if "%%f" equ "Dec" (
- set FileM=12
- )
- set FileD=10%%g
- set FileD=!FileD:~-2!
- if "!FileM!" equ "%DstMonth%" (
- if "!FileD!" equ "%DstDay%" (
- echo get "%%i" "%DownFolder%\%%i"
- )
- )
- endlocal
- ))>>"%ftpDown%"
复制代码
- echo %date%
- echo %time%
还有如下部分怎么修改?复制代码
- set FileY=%date:~0,4%
- call :DateToMins %date:~0,4% %date:~5,2% %date:~8,2% %time:~11,2% %time:~14,2% Mins
你能不能帮我改下,我比较一下看看是否正确?复制代码
- (for /f "usebackq tokens=1-9 delims= " %%a in ("%temp%\FileDate.txt") do (
- setlocal enabledelayedexpansion
- if "%%f" equ "Jan" (
- set FileM=01
- ) else if "%%f" equ "Feb" (
- set FileM=02
- ) else if "%%f" equ "Mar" (
- set FileM=03
- ) else if "%%f" equ "Apr" (
- set FileM=04
- ) else if "%%f" equ "May" (
- set FileM=05
- ) else if "%%f" equ "Jun" (
- set FileM=06
- ) else if "%%f" equ "Jul" (
- set FileM=07
- ) else if "%%f" equ "Aug" (
- set FileM=08
- ) else if "%%f" equ "Sep" (
- set FileM=09
- ) else if "%%f" equ "Oct" (
- set FileM=10
- ) else if "%%f" equ "Nov" (
- set FileM=11
- ) else if "%%f" equ "Dec" (
- set FileM=12
- )
- set FileD=10%%g
- set FileD=!FileD:~-2!
- if "!FileM!" equ "%DstMonth%" (
- if "!FileD!" equ "%DstDay%" (
- echo get "%%i" "%DownFolder%\%%i"
- )
- )
- endlocal
- ))>>"%ftpDown%"
原帖由 Batcher 于 2009-8-14 22:32 发表
%time:~11,2% %time:~14,2%这里对时间的截取是错的,如果你还没有搞清楚字符串截取的方法,可以参考以下几个帖子:
set截取字符详解
http://bbs.bathome.net/viewthread.php?tid=996
set变量字符截取点点通
h ...
复制代码
- set FileY=%date:~0,4%
- set FileN=%time:~0,2%
- call :DateToMins %date:~0,4% %date:~5,2% %date:~8,2% %time:~0,2% %time:~3,2% %time:~6,2% Mins
复制代码
- C:\Documents and Settings\usr>echo %date:~0,4% %date:~5,2% %date:~8,2% %time:~0,
- 2%:%time:~3,2%
- 2009 08 16 9:20
为什么问了问题不回答呢?不能理解。我觉得既然你回答了我的问题,就应该负责到底啊!一起探讨问题才能共同提高。
:: %4 待转换的小时,范围是 1/01 到 12 (12小时制,分钟数以“a”或者
:: “p”结尾)或者 0/00 到 23 (24小时制)(传值调用)
:: %5 待转换的分钟,范围是 00-59 (12小时制需加 a/p 后缀)(传值调用)
复制代码
- call :DateToMins %date:~0,4% %date:~5,2% %date:~8,2% %time:~0,2% %time:~3,2% //这个传参怎么补零?
复制代码
- C:\Documents and Settings\Admin\My Documents>(
- setlocal enabledelayedexpansion
- if "Jun" EQU "Jan" (set FileM=01 ) else if "Jun" EQU "Feb" (set FileM=02 ) else if "Jun" EQU "Mar" (set FileM=03 ) else if "Jun" EQU "Apr" (set FileM=04 ) else if "Jun" EQU "May" (set FileM=05 ) else if "Jun" EQU "Jun" (set FileM=06 ) else if "Jun" EQU "Jul" (set FileM=07 ) else if "Jun" EQU "Aug" (set FileM=08 ) else if "Jun" EQU "Sep" (set FileM=09 ) else if "Jun" EQU "Oct" (set FileM=10 ) else if "Jun" EQU "Nov" (set FileM=11 ) else if "Jun" EQU "Dec" (set FileM=12 )
- set FileH=101 //不对,没有补0
- set FileH=!FileH:~-2!
- if "!FileM!" EQU "01" (if "!FileH!" EQU "00"/×应该是08,我怎么得到的是00?×/ (echo get "F20090532F.SWM" "E:\\F20090532F.SWM" ) )
- endlocal
- )
但是有处不懂,if 1%%a lss 20 (set var0=!var0!,0%%a) else set var0=!var0!,%%a复制代码
- @echo off & setlocal enabledelayedexpansion
- set var=2,15,20,33,56,1,07,54,89,66,23,25,27,28,29,55,56,57,5,59,6,78,74,66,08,28,9,30,52,14,15,16,2,8,4,6,15,16,13,5,9
- for %%a in (%var%) do (
- if 1%%a lss 20 (set var0=!var0!,0%%a) else set var0=!var0!,%%a
- )
- set var0=%var0:~1%
- echo %var0%
- pause
复制代码
- rem 假设本机日期格式为yyyy-mm-dd-hh-nn
- set FileY=%date:~0,4%
- call :DateToMins %date:~0,4% %date:~5,2% %date:~8,2% %time:~0,2% %time:~3,2% Mins
- set /a Mins-=MinsAgo
- call :MinsToDate %Mins% DstYear DstMonth DstDay DstHour DstMin
call ateToMins %date:~0,4% %date:~5,2% %date:~8,2% %time:~0,2% %time:~3,2% Mins
我用echo命令查了下,纠正下batcher的错误。小时需要补零,分钟不需要补零,系统会自动补零。复制代码
- if %time:~1,1% lss 10 (set hh=0%time:~1,1%) else (set hh=%time:~0,2%)
- echo %hh%
- pause
这是运行结果。复制代码
- C:\Documents and Settings\Admin\桌面>if 10 LSS 10 (set hh=00 ) else (set hh=10)
- C:\Documents and Settings\Admin\桌面>echo 10
- 10
C:\Test>type test.bat if %time:~1,1% lss 10 (set hh=0%time:~1,1%) else (set hh=%time:~0,2%) echo %hh% C:\Test>test.bat C:\Test>if 0 LSS 10 (set hh=00 ) else (set hh=10 ) C:\Test>echo 00 00 |
复制代码
- if %time:~0,2% lss 10 (set hh=0%time:~1,1%) else (set hh=%time:~0,2%)
- echo %hh%
- pause
主要是以上2点疑问,希望batcher解答一下。复制代码
- (for /f "usebackq tokens=1-9 delims=:, " %%a in ("%temp%\FileDate2.txt") do (
- setlocal enabledelayedexpansion /*获取14:28中14的信息*/
- if "%%f" equ "Jan" (
- set FileM=01
- ) else if "%%f" equ "Feb" (
- set FileM=02
- ) else if "%%f" equ "Mar" (
- set FileM=03
- ) else if "%%f" equ "Apr" (
- set FileM=04
- ) else if "%%f" equ "May" (
- set FileM=05
- ) else if "%%f" equ "Jun" (
- set FileM=06
- ) else if "%%f" equ "Jul" (
- set FileM=07
- ) else if "%%f" equ "Aug" (
- set FileM=08
- ) else if "%%f" equ "Sep" (
- set FileM=09
- ) else if "%%f" equ "Oct" (
- set FileM=10
- ) else if "%%f" equ "Nov" (
- set FileM=11
- ) else if "%%f" equ "Dec" (
- set FileM=12
- )
- set FileD=10%%g
- set FileD=!FileD:~-3!
- set FileH=10%%g
- set FileH=!FileH:~-2!
- if "!FileM!" equ "%DstMonth%" (
- if "!FileD!" equ "%DstDay%" ( /*判断条件是不是还要加上日期的信息?*/
- if "!FileH!" equ "%DstHour%" (
- echo get "%%i" "%DownFolder%\%%i"
- )
- )
- )
- endlocal
- ))>>"%ftpDown%"
正确的结果内容应该是以下格式:复制代码
- C:\Documents and Settings\Admin\桌面>(
- setlocal enabledelayedexpansion
- if "Jun" EQU "Jan" (set FileM=01 ) else if "Jun" EQU "Feb" (set FileM=02 ) else if "Jun" EQU "Mar" (set FileM=03 ) else if "Jun" EQU "Apr" (set FileM=04 ) else if "Jun" EQU "May" (set FileM=05 ) else if "Jun" EQU "Jun" (set FileM=06 ) else if "Jun" EQU "Jul" (set FileM=07 ) else if "Jun" EQU "Aug" (set FileM=08 ) else if "Jun" EQU "Sep" (set FileM=09 ) else if "Jun" EQU "Oct" (set FileM=10 ) else if "Jun" EQU "Nov" (set FileM=11 ) else if "Jun" EQU "Dec" (set FileM=12 )
- set FileD=105
- set FileD!FileD:~-3!
- set FileH=105
- set FileH=!FileH:~-2!
- if "!FileM!" EQU "08" (if "!FileD!" EQU "21" (if "!FileH!" EQU "13" (echo get "59" "E:\\59" ) ) )
- endlocal
- )
复制代码
- D:\batch>(
- setlocal enabledelayedexpansion
- if "Jun" EQU "Jan" (set FileM=01 ) else if "Jun" EQU "Feb" (set FileM=02 ) else if "Jun" EQU "Mar" (set FileM=03 ) else if "Jun" EQU "Apr" (set FileM=04 ) else if "Jun" EQU "May" (set FileM=05 ) else if "Jun" EQU "Jun" (set FileM=06 ) else if "Jun" EQU "Jul" (set FileM=07 ) else if "Jun" EQU "Aug" (set FileM=08 ) else if "Jun" EQU "Sep" (set FileM=09 ) else if "Jun" EQU "Oct" (set FileM=10 ) else if "Jun" EQU "Nov" (set FileM=11 ) else if "Jun" EQU "Dec" (set FileM=12 )
- set FileD=105
- set FileD=!FileD:~-2!
- if "!FileM!" EQU "08" (if "!FileD!" EQU "20" (if "!FileH!" EQU "hours"(echo get "F12345678K.SWM" "F:\\F12345678K.SWM" ) ) )
- endlocal
- )
(for /f "usebackq tokens=1-9 delims=:, " %%a in ("FileDate2.txt") do (
set FileD=10%%g
set FileD=!FileD:~-3!
set FileH=10%%g
set FileH=!FileH:~-2!
复制代码
- (for /f "usebackq tokens=1-10 delims=: " %%a in ("%temp%\FileDate2.txt") do (
- setlocal enabledelayedexpansion
- if "%%f" equ "Jan" (
- set FileM=01
- ) else if "%%f" equ "Feb" (
- set FileM=02
- ) else if "%%f" equ "Mar" (
- set FileM=03
- ) else if "%%f" equ "Apr" (
- set FileM=04
- ) else if "%%f" equ "May" (
- set FileM=05
- ) else if "%%f" equ "Jun" (
- set FileM=06
- ) else if "%%f" equ "Jul" (
- set FileM=07
- ) else if "%%f" equ "Aug" (
- set FileM=08
- ) else if "%%f" equ "Sep" (
- set FileM=09
- ) else if "%%f" equ "Oct" (
- set FileM=10
- ) else if "%%f" equ "Nov" (
- set FileM=11
- ) else if "%%f" equ "Dec" (
- set FileM=12
- )
- set FileD=10%%g
- set FileD=!FileD:~-2!
- set FileH=10%%h
- set FileH=!FileH:~-2!
- if "!FileM!" equ "%DstMonth%" (
- if "!FileD!" equ "%DstDay%" (
- if "!FileH!" equ "%DstHour%" (
- echo get "%%j" "%DownFolder%\%%j"
- )
- )
- )
- endlocal
- ))>>"%ftpDown%"
复制代码
- @echo off
- rem 指定FTP用户名
- set ftpUser=xxx
- rem 指定FTP密码
- set ftpPass=xxxxxxx
- rem 指定FTP服务器地址
- set ftpIP=xxx.xxx.xxx.xx
- rem 指定待下载的文件位于FTP服务器的什么位置
- set ftpFolder=/export/home/PROD/ntcdata
- rem 指定从FTP下载下来的文件存放到什么地方
- set DownFolder=E:\
- rem 指定下载几小时前的文件
- set MinsAgo=60
- set ftpDir=%temp%\TempDir2.txt
- set ftpDown=%temp%\TempDown2.txt
- rem 假设本机日期格式为yyyy-mm-dd-hh-nn /*本段为时间问题的重点*/
- set FileY=%date:~0,4%
- if %time:~0,2% lss 10 (set hh=0%time:~1,1%) else (set hh=%time:~0,2%)
- call :DateToMins %date:~0,4% %date:~5,2% %date:~8,2% %hh% %time:~3,2% Mins
- set /a Mins-=MinsAgo
- call :MinsToDate %Mins% DstYear DstMonth DstDay DstHour DstMin
- >"%ftpDir%" echo.%ftpUser%
- >>"%ftpDir%" echo.%ftpPass%
- >>"%ftpDir%" echo bin
- >>"%ftpDir%" echo cd "%ftpFolder%"
- >>"%ftpDir%" echo dir * "%temp%\FileList2.txt"
- >>"%ftpDir%" echo bye
- start ftp -v -i -s:"%ftpDir%" %ftpIP%
- rem 根据实际情况自行调节延迟时间
- ping -n 350 127.1 >nul
- findstr /i ":*\.SWM$" "%temp%\FileList2.txt">"%temp%\FileDate2.txt"
- findstr /i ":*\.TWM$" "%temp%\FileList2.txt">>"%temp%\FileDate2.txt"
- findstr /i ":*\.OWM$" "%temp%\FileList2.txt">>"%temp%\FileDate2.txt"
- >"%ftpDown%" echo.%ftpUser%
- >>"%ftpDown%" echo.%ftpPass%
- >>"%ftpDown%" echo bin
- >>"%ftpDown%" echo cd "%ftpFolder%"
- (for /f "usebackq tokens=1-10 delims=: " %%a in ("%temp%\FileDate2.txt") do ( /*从filedate2.txt中获得包含时间信息的文件*/
- setlocal enabledelayedexpansion
- if "%%f" equ "Jan" (
- set FileM=01
- ) else if "%%f" equ "Feb" (
- set FileM=02
- ) else if "%%f" equ "Mar" (
- set FileM=03
- ) else if "%%f" equ "Apr" (
- set FileM=04
- ) else if "%%f" equ "May" (
- set FileM=05
- ) else if "%%f" equ "Jun" (
- set FileM=06
- ) else if "%%f" equ "Jul" (
- set FileM=07
- ) else if "%%f" equ "Aug" (
- set FileM=08
- ) else if "%%f" equ "Sep" (
- set FileM=09
- ) else if "%%f" equ "Oct" (
- set FileM=10
- ) else if "%%f" equ "Nov" (
- set FileM=11
- ) else if "%%f" equ "Dec" (
- set FileM=12
- )
- set FileD=10%%g
- set FileD=!FileD:~-2!
- set FileH=10%%h
- set FileH=!FileH:~-2!
- if "!FileM!" equ "%DstMonth%" (
- if "!FileD!" equ "%DstDay%" (
- if "!FileH!" equ "%DstHour%" (
- echo get "%%j" "%DownFolder%\%%j"
- )
- )
- )
- endlocal
- ))>>"%ftpDown%"
- >>"%ftpDown%" echo bye
- start ftp -v -i -s:"%ftpDown%" %ftpIP%
- rem 根据实际情况自行调节延迟时间
- rem ping -n 700 127.1 >nul
- goto :eof
- :DateToMins %yy% %mm% %dd% %hh% %mm% /*这两段为调用时间函数 日期转分钟和分钟转日期*/
- setlocal ENABLEEXTENSIONS
- set yy=%1&set mm=%2&set dd=%3&set hh=%4&set nn=%5
- if 1%yy% LSS 200 if 1%yy% LSS 170 (set yy=20%yy%) else (set yy=19%yy%)
- set /a dd=100%dd%%%100,mm=100%mm%%%100
- set /a z=14-mm,z/=12,y=yy+4800-z,m=mm+12*z-3,j=153*m+2
- set /a j=j/5+dd+y*365+y/4-y/100+y/400-2472633
- if 1%hh% LSS 20 set hh=0%hh%
- if {%nn:~2,1%} EQU {p} if "%hh%" NEQ "12" set hh=1%hh%&set/a hh-=88
- if {%nn:~2,1%} EQU {a} if "%hh%" EQU "12" set hh=00
- if {%nn:~2,1%} GEQ {a} set nn=%nn:~0,2%
- set /a hh=100%hh%%%100,nn=100%nn%%%100,j=j*1440+hh*60+nn
- endlocal&set %6=%j%&goto :EOF
- :MinsToDate %mins% yy mm dd hh nn
- setlocal ENABLEEXTENSIONS
- set /a i=%1,nn=i%%60,i/=60,hh=i%%24,dd=i/24,i/=24
- set /a a=i+2472632,b=4*a+3,b/=146097,c=-b*146097,c/=4,c+=a
- set /a d=4*c+3,d/=1461,e=-1461*d,e/=4,e+=c,m=5*e+2,m/=153,dd=153*m+2,dd/=5
- set /a dd=-dd+e+1,mm=-m/10,mm*=12,mm+=m+3,yy=b*100+d-4800+m/10
- (if %mm% LSS 10 set mm=0%mm%)&(if %dd% LSS 10 set dd=0%dd%)
- (if %hh% LSS 10 set hh=0%hh%)&(if %nn% LSS 10 set nn=0%nn%)
- endlocal&set %6=%nn%&set %5=%hh%&set %4=%dd%&^
- set %3=%mm%&set %2=%yy%&goto :EOF
欢迎光临 批处理之家 (http://www.bathome.net/) | Powered by Discuz! 7.2 |