0

All, need a hlep in scripting in with batch file. I am very much new to scripting.

I have an etl job which creates a file in a folder named as FINANCE20141011.txt. I need to create a batch file which will find current days file which is FINANCE20141011.txt (current date is 11/10/2014 and send the file to sftp server.

There would be multiple file in the folder such as, FINANCE20141009.txt, FINANCE20141008.txt. But the script should pull up the current days file. Any help.

Thanks.

user3657257
  • 37
  • 2
  • 9

1 Answers1

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
npocmaka
  • 55,367
  • 18
  • 148
  • 187