批处理文件添加今天的日期,昨天的日期,previous当天的日期作为扩展文件名 [英] Batch file to add today's date, yesterday's date, previous day's date as extension to file name

查看:180
本文介绍了批处理文件添加今天的日期,昨天的日期,previous当天的日期作为扩展文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面以一个文件,MB5L.txt和COM presses它与日期的zip文件作为文件名的一部分:

The following takes a file, MB5L.txt and compresses it into a zip file with the date as part of the file name:

@For /F "tokens=1,2,3,4 delims=/ " %%A in ('Date /t') do @(
    Set DayW=%%A
    Set Day=%%B
    Set Month=%%C
    Set Year=%%D
    Set All=%%D%%B%%C
)

"C:\Windows\CWBZIP.EXE" "c:\transfer\ziptest%All%.zip" "C:\transfer\MB5L.txt"

今天,它会采取MB5L.txt和COM preSS它ziptest20120204.zip。

Today, it will take MB5L.txt and compress it to ziptest20120204.zip.

我想带一个名为MB5L201202.txt文件和COM preSS它MB5L20120202.zip这里的20120202是一个变量,从而使管理员能够在周一上午运行的批处理文件,从存档文件周末。

I want to take a file named MB5L201202.txt and compress it to MB5L20120202.zip where the "20120202" is a variable, thus allowing an administrator to run a batch file on Monday morning to archive files from the weekend.

任何建议,大大AP preciated。

Any suggestions greatly appreciated.

推荐答案

所以你要今天的日期或昨天在输出名称包括哪些内容?
如果昨天我已经做了一个..这可以与大家分享!

so you want today date or yesterday to include in the output name? If yesterday i have done one.. which can share with you!

 set yyyy=

set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do (
for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (
set %%x=%%u
set %%y=%%v
set %%z=%%w
set $d1=
set $tok=))

if "%yyyy%"=="" set yyyy=%yy%
if /I %yyyy% LSS 100 set /A yyyy=2000 + 1%yyyy% - 100

set CurDate=%mm%/%dd%/%yyyy%
set dayCnt=%1

if "%dayCnt%"=="" set dayCnt=1

REM Substract your days here
set /A dd=1%dd% - 100 - %dayCnt%
set /A mm=1%mm% - 100

:CHKDAY
if /I %dd% GTR 0 goto DONE
set /A mm=%mm% - 1
if /I %mm% GTR 0 goto ADJUSTDAY
set /A mm=12
set /A yyyy=%yyyy% - 1

:ADJUSTDAY
if %mm%==1 goto SET31
if %mm%==2 goto LEAPCHK
if %mm%==3 goto SET31
if %mm%==4 goto SET30
if %mm%==5 goto SET31
if %mm%==6 goto SET30
if %mm%==7 goto SET31
if %mm%==8 goto SET31
if %mm%==9 goto SET30
if %mm%==10 goto SET31
if %mm%==11 goto SET30
REM ** Month 12 falls through

:SET31
set /A dd=31 + %dd%
goto CHKDAY

:SET30
set /A dd=30 + %dd%
goto CHKDAY

:LEAPCHK
set /A tt=%yyyy% %% 4
if not %tt%==0 goto SET28
set /A tt=%yyyy% %% 100
if not %tt%==0 goto SET29
set /A tt=%yyyy% %% 400
if %tt%==0 goto SET29

:SET28
set /A dd=28 + %dd%
goto CHKDAY

:SET29
set /A dd=29 + %dd%
goto CHKDAY

:DONE
if /I %mm% LSS 10 set mm=0%mm%
if /I %dd% LSS 10 set dd=0%dd%

REM Set IIS and AWS date variables
set IISDT=%yyyy:~2,2%%mm%%dd%
set AWSDT=%yyyy%-%mm%-%dd%

C:\\ WINDOWS \\ CWBZIP.EXEC:\\传输\\ ziptest%DD% - %毫米% - %YYYY%的.zip,C:\\传输\\ MB5L.txt

"C:\Windows\CWBZIP.EXE" "c:\transfer\ziptest%dd%-%mm%-%yyyy%.zip" "C:\transfer\MB5L.txt"

这篇关于批处理文件添加今天的日期,昨天的日期,previous当天的日期作为扩展文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆