批量文件与当前日期

时间:2014-11-18 06:01:53

标签: batch-file command-line scripting

全部,需要在批处理文件的脚本中使用hlep。我对脚本非常陌生。

我有一个etl作业,它在名为FINANCE20141011.txt的文件夹中创建一个文件。我需要创建一个批处理文件,找到当前日期的文件,即FINANCE20141011.txt(当前日期是2014年10月11日,并将文件发送到sftp服务器。

文件夹中会有多个文件,例如FINANCE20141009.txt,FINANCE20141008.txt。但是脚本应该提取当前天文件。任何帮助。

感谢。

1 个答案:

答案 0 :(得分:1)

@Echo Off


Call :GetDate.Init
Rem :GetDate.Init should be called one time in the code before call to :Getdate
Call :GetDate


set finance=FINANCE%year%%month%%day%.txt
echo %finance%
Goto :EOF

:GetDate.Init
Set /A "jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7,aug=8,sep=9,oct=10,nov=11,dec=12"
Set /A "mon=1,tue=2,wed=3,thu=4,fri=5,sat=6,sun=7"
(
Echo .Set InfHeader=""
Echo .Set InfSectionOrder=""
Echo .Set InfFooter="%%2"
Echo .Set InfFooter1=""
Echo .Set InfFooter2=""
Echo .Set InfFooter3=""
Echo .Set InfFooter4=""
Echo .Set Cabinet="OFF"
Echo .Set Compress="OFF"
Echo .Set DoNotCopyFiles="ON"
Echo .Set RptFileName="NUL"
) >"%Temp%\~foo.ddf"
Goto :Eof

:GetDate
Set "tf=%Temp%\~%random%"
Makecab /D InfFileName="%tf%" /F "%Temp%\~foo.ddf" >NUL
For /F "usebackq tokens=1-7 delims=: " %%a In ("%tf%") Do (
Set /A "year=%%g,month=%%b,day=1%%c-100,weekday=%%a"
Set /A "hour=1%%d-100,minute=1%%e-100,second=1%%f-100")
Del "%tf%" >NUL 2>&1
Goto :Eof
相关问题