Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am writing a batch file that uses wget.exe to go download a text file everyday.
I know exactly what the filename will be everyday, but how do I automatically populate the "wget" line with the filename?
The only change is the date; the format is something like:
wget hxxp://www.website.com/reports/repYYYYMMDD.txtAny help would be greatly appreciated...thx.

Here are some clues.
echo %date%
20/02/2008Try the above command. Your date may be printed in a different format.
echo %date:~3,2%
02The above command gets a substring, in my case one containing the month.
Do a similar thing for the day and year parts, and you can build the YYYYMMDD string that you need.

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=2-4 delims=/ " %%a in ('echo %date%') do (
set YYYYMMDD=%%c%%a%%b
)echo wget hxxp://www.website.com/reports/rep!YYYYMMDD!.txt
=====================================
If at first you don't succeed, you're about average.M2

HOLY cow that somehow insanely worked Mechanix!!! Thank you thank you thank you.
One more question....what if I wanted to download today -1 (yesterday)? Is that possible?
Thanks again! J.

We go through this 'date math' a few times a month. It's not worth it.
A workaround is to get a list of files. But that will only fly if you have access to the server via ftp/rlogin etc.
=====================================
If at first you don't succeed, you're about average.M2

Mechanix -- I do not have ftp access...
I found a "calendar" of sorts that gets me to yesterday....
http://www.computing.net/programming/wwwboard/forum/9077.html
Totally works now....thank you so much for your help. J.

I don't think this math wiill work.
::==
set Lday=%Day%
set /A Lday -= 1
=====================================
If at first you don't succeed, you're about average.M2

@OP, if you want to do date arithmetic, get something better. like vbscript, or other more advanced languages that can do it easily. Not batch.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |