[Dos] 检查文件是否存在并进行压缩,以及过期删除

来源:互联网 发布:淘宝手机怎么换购 编辑:程序博客网 时间:2024/06/08 08:01

检查服务器Server01上面某个目录中, 是否存在 OFD_99_NN_yyyymmdd_53.txt, 存在则压缩。  如果是21点以前YYYYMMDD为昨天的日期

 

@echo off
cd /d "C:\Unionstars.FileMonitor\sendfile"

rem 21点之后是检查当天的OFD_99_NN_yyyymmdd_53.zip
if "%time:~0,2%" GEQ "21" (goto today0) else goto yest0
:today0
@set ref=%date:~0,4%%date:~5,2%%date:~8,2%
if exist "OFD_99_NN_%ref%_53.zip" (goto exit0) else goto txt53

rem 21点之前检查是否存在昨天的OFD_99_NN_yyyymmdd_53.zip
:yest0
echo du=date()-1>%temp%\tmp0002.vbs
echo s=right(year(du),4) ^& right("0" ^& month(du),2) ^&   right("0" ^& day(du),2)>>%temp%\tmp0002.vbs
echo wscript.echo s>>%temp%\tmp0002.vbs
for /f "delims=x" %%o in ('cscript /nologo %temp%\tmp0002.vbs') do @set ref=%%o
if exist "OFD_99_NN_%ref%_53.zip" (goto exit0) else goto txt53

rem 检查是否存在昨天的FD_99_NN_yyyymmdd_53.txt
:txt53
if exist "\\server01\tads\zhongdeng\recv\OFD_99_NN_%ref%_53.TXT" (goto zip0) else goto exit0

:zip0
rem 压缩文件到当前目录
cd /d "C:\Unionstars.FileMonitor\sendfile"
Rar.exe a -ep OFD_99_NN_%ref%_53.zip \\server01\tads\zhongdeng\recv\OFD_99_NN_%ref%_53.TXT
echo %date% %time% Rar.exe a -ep OFD_99_NN_%ref%_53.zip \\server01\tads\zhongdeng\recv\OFD_99_NN_%ref%_53.TXT >> log.txt

rem "删除10前的文件zip"
echo dt=date()-10>%temp%\tmp0001.vbs
echo s=right(year(dt),4) ^& right("0" ^& month(dt),2) ^&   right("0" ^& day(dt),2)>>%temp%\tmp0001.vbs
echo wscript.echo s>>%temp%\tmp0001.vbs
for /f "delims=x" %%i in ('cscript /nologo %temp%\tmp0001.vbs') do @set ref=%%i
cd /d "C:\Unionstars.FileMonitor\sendfile"
for /f "tokens=1,*" %%i in ('dir /b  *.zip') do (
if %%i LSS OFD_99_NN_%ref%_53.zip del /S /Q %%i
)

:exit0
exit

0 0