联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!
@echo on ::============================================================= :: Parameter definition ::------------------------------------------------------------- rem Path set ::------------------------------------------------------------- set ProgPath=%CD% set DataPath=e:\localpath set BackPath=e:\backup1 set TempPath=%DataPath%\temp set MputPath=%DataPath%\mput set LogPath=%ProgPath%\log ::------------------------------------------------------------- rem Data FTP server information set ::------------------------------------------------------------- set DFtpserv=127.0.0.1 set DFtpuser=EPROPRG set DFtppwd=eproprg set DFtppath=\ ::------------------------------------------------------------- rem Log FTP server information set ::------------------------------------------------------------- set LFtpserv=172.16.15.170 set LFtpuser=xiewf set LFtppwd=a154122529 set LFtppath=\LOG ::============================================================= :: FTP information generated ::------------------------------------------------------------- rem Datalog FTP information generated ::------------------------------------------------------------- >dftp.ini echo open %DFtpserv% >>dftp.ini echo %DFtpuser% >>dftp.ini echo %DFtppwd% >>dftp.ini echo cd "%DFtppath%" >>dftp.ini echo lcd "%MputPath%" >>dftp.ini echo mput *.* >>dftp.ini echo bye ::------------------------------------------------------------- rem Log FTP information generated ::------------------------------------------------------------- >lftp.ini echo open %LFtpserv% >>lftp.ini echo %LFtpuser% >>lftp.ini echo %LFtppwd% >>lftp.ini echo cd "%LFtppath%" >>lftp.ini echo lcd "%LogPath%" >>lftp.ini echo mput *.log >>lftp.ini echo bye ::============================================================= :: Main script ::------------------------------------------------------------- rem Check directory ::------------------------------------------------------------- if not exist "%DataPath%" md "%DataPath%" if not exist "%BackPath%" md "%BackPath%" if not exist "%TempPath%" md "%TempPath%" if not exist "%MputPath%" md "%MputPath%" if not exist "%LogPath%" md "%LogPath%" ::------------------------------------------------------------- rem Datalog dump ::------------------------------------------------------------- >>"%LogPath%\dataput.log" echo. >>"%LogPath%\dataput.log" echo -==-%date% %time%, Script running!!!-==- >>"%LogPath%\dataput.log" echo *************DataLog began to dump************* >>"%LogPath%\dataput.log" move "%DataPath%\*.*" "%TempPath%" >>"%LogPath%\dataput.log" echo ************DataLog began to upload************ :Begin ::------------------------------------------------------------- rem Check net ::------------------------------------------------------------- ping -n 1 -w 1000 %DFtpserv%>nul if "%errorlevel%"=="1" ( echo Error!!! %date% %time%,FTP server connection failure!>>"%LogPath%\dataput.log" goto Error ) else ( echo.&& goto Next0 ) :Next0 ::------------------------------------------------------------- rem Access to upload file name,and check the results of upload ::------------------------------------------------------------- >"%LogPath%\filelist.txt" dir /b "%TempPath%" >>"%LogPath%\filelist.txt" echo nofile set /p file=<"%LogPath%\filelist.txt" if "%file%"=="nofile" ( echo.&& goto End ) else ( echo.&& goto Next1 ) :Next1 >>"%LogPath%\dataput.log" echo Start upload [%file%] move "%TempPath%\%file%" "%MputPath%" >ftpres.txt call ftp -i -s:dftp.ini ::------------------------------------------------------------- rem Check the datalog has been upload,and backup it ::------------------------------------------------------------- findstr /C:"%file%" ftpres.txt if "%errorlevel%"=="1" ( echo Error!!! %date% %time%,[%file%] upload failure!>>"%LogPath%\dataput.log" goto Error ) else ( echo.&& goto Next2 ) :Next2 ping -n 1 -w 1000 000>nul if "%errorlevel%"=="1" ( echo %date% %time%,FTP server connection failure!Stop backup [%file%]>>"%LogPath%\dataput.log" goto Error ) else ( echo.&& goto Next3 ) :Next3 echo %date% %time%,[%file%] Upload successful!!!>>"%LogPath%\dataput.log" echo Backup [%file%] now!>>"%LogPath%\dataput.log" move "%MputPath%\*.*" "%BackPath%" goto Begin :Error >>"%LogPath%\dataput.log" echo -==-%date% %time%, Script ending!!-==- del ftpres.txt del dftp.ini del lftp.ini exit :End >>"%LogPath%\dataput.log" echo -==-%date% %time%, Script ending!!-==- del ftpres.txt del dftp.ini del lftp.ini exit
set file= for /f "delims=" %%i in ("%LogPath%\filelist.txt") do set file=%%i&goto :nnext :nnext if "%file%"=="" echo 没有file
for /f "tokens=1* delims=:" %%i in ('findstr /n . "%LogPath%\filelist.txt"') do set _%%i=%%j&if "%%i"=="1" goto nnext :nnext set file=%_1%
Originally posted by jipinkuang at 2009-3-7 01:22 AM: main这段代码,在XP下运行是无错的,但是在Windows NT下, set /p file=<"%LogPath%\filelist.txt" 这里是不能获得 filelist.txt 里的第一行 并赋值给%fi ...
set file= for /f "delims=" %%i in (‘type "%LogPath%\filelist.txt"') do set file=%%i&goto :nnext :nnext if "%file%"=="" echo 没有file