Windows Batch File and an FTP Datestamp -


i struggling grasp concept of writing batch files. hoping schedule .bat file download file timestamp on daily basis. setting scheduled task etc. straight forward, problem arises when try execute code take fixed part of filename , append datestamp identify appropiate file.

from research have done still cannot code pick yesterday date in yyyymmdd format. eg. today 15th of august, batch identify file 20130814. exisitng (static) ftp batch code

option confirm off option batch abort open ftp_name lcd "u:\xxxx\yyyy\zzzz"  "loansummary__daily.xlsx" 

whereas batch consider..

get "loansummary__daily_" & yyyymmdd & ".xlsx" 

thanks.

i don't think can dynamically build file names within ftp script. can dynamically build ftp script batch file prior invoking it.

the simplest way create ftp script template has variable portion(s) represented environment variable delayed expansion. example !yesterday! refer environment variable gets expanded yesterday's date. simple /f loop reads template, , writes each line new ftp script file. variables automatically expanded in process long delayed expansion enabled.

getting yesterday's date in windows batch file non-trivial excercise. there have been many methods posted on other sites. methods have various limitations, common of susceptability problems due differences in locale date formatting. use hybrid batch/jscript utility called gettimestamp.bat work on windows platform xp onward, regardless of locale. pure script, no .exe download needed. gettimestamp.bat avaiable here.

assuming gettimestamp.bat in current directory, or better yet, somewhere within path, following should work.

getyesterday.ftp.template

option confirm off option batch abort open ftp_name lcd "u:\xxxx\yyyy\zzzz"  "loansummary__daily_!yesterday!.xlsx" 

getyesterday.bat

@echo off setlocal enabledelayedexpansion  :: yesterday's date in yyyymmdd format call gettimestamp -od -1 -f {yyyy}{mm}{dd} -r yesterday  :: create temporary ftp script uses "yesterday" date >temp.ftp (for /f "delims=" %%l in (getyesterday.ftp.template) echo %%l)  :: invoke ftp client using temp script, ftp -s:temp.ftp ...  :: delete temporary ftp script del temp.ftp 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -