Link to home
Start Free TrialLog in
Avatar of xzay1967
xzay1967

asked on

please explain script and how to change

Hello all, I need some help with a script. Please explain this line of code and how to get it to pull the correct date
or /f "tokens=2" %%d in ('date /t') do set dte=%%d
for /f "delims=/ tokens=1-3" %%a in ('echo %dte%') do set ymd=%%c%%a%%b
set DATESTAMP=%ymd: =%
set hhmmss=%time:~0,2%%time:~3,2%%time:~6,2%
set DATESTAMP=20130516
****************************
This is for an FTP job that is supposed to perform GET %DATESTAMP%dep_0501.txt. The job failed cause it looked for  a file with a date of 20130516. As shown in the log entry: Failure in command [GET 20130516dep_0501.txt]
There is however a file called 20130517dep_0501.txt on the ftp site. I am assuming that te date syntax is not calculating the date correctly so it appended the wrong file name, hence the failure. Am I correct in my assumption about the date calculation? if so, what change do I need to make so the job looks for the correct file name. This is a scheduled job so I don't want to have to manually move the file every time. Thanks in advance.
Avatar of Qlemo
Qlemo
Flag of Germany image

Though that is pretty much overcomplicated code, it should work if you remove the last line (set DATESTAMP), which overrides the datestamp calculated based on the current date.

If you are just after todays date in yyyymmdd format, this should do:
set DATESTAMP=%date:~-4%%date:~-10,2%%date:~-7,2%

Open in new window

Avatar of xzay1967
xzay1967

ASKER

for /f "tokens=2" %%d in ('date /t') do set dte=%%d
for /f "delims=/ tokens=1-3" %%a in ('echo %dte%') do set ymd=%%c%%a%%b
set DATESTAMP=%ymd: =%
set hhmmss=%time:~0,2%%time:~3,2%%time:~6,2%
set DATESTAMP=20130516

Thanks for the response, I am not sure what the code is supposed to look or what file name is expected. Please break down the code above for me line by line so I have an understanding what it conveys. Knowing that might give me a better idea if I need to change to what is suggested. Thing is, this code worked for years, so not sure why now all of a sudden it failed. Another assumption is that person putting the file in the source destination may have named the file in error not mindful of the date.
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@xzay1967

(1) If you do DATE /T at a command prompt, what does it display?

(2) Is the following line really in the script as you show it?  If so then this will be always override the other lines and set the date to 20130516.

set DATESTAMP=20130516

~bp
@BP, yes it actually is.
@Qlemo thanks for the input, I gather what you are saying, it makes perfect sense. I will consult with my supervisor to see if he wants to make that change you suggested.