Computing.Net > Forums > Programming > generate filename in batch file?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

generate filename in batch file?

Reply to Message Icon

Name: lbf864
Date: February 20, 2008 at 09:41:33 Pacific
OS: W2K
CPU/Ram: Penitum D
Product: IBM
Comment:

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.txt

Any help would be greatly appreciated...thx.




Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: February 20, 2008 at 10:09:57 Pacific
Reply:

Here are some clues.

echo %date%
20/02/2008

Try the above command. Your date may be printed in a different format.

echo %date:~3,2%
02

The 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.


0

Response Number 2
Name: lbf864
Date: February 20, 2008 at 11:13:54 Pacific
Reply:

echo %date%

gives me: Wed 02/20/2008

echo %date:~3,2%

returns: 0

Any other thoughts?


0

Response Number 3
Name: Mechanix2Go
Date: February 20, 2008 at 11:37:57 Pacific
Reply:


@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



0

Response Number 4
Name: lbf864
Date: February 20, 2008 at 11:50:10 Pacific
Reply:

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.


0

Response Number 5
Name: Mechanix2Go
Date: February 20, 2008 at 11:58:43 Pacific
Reply:

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



0

Related Posts

See More



Response Number 6
Name: lbf864
Date: February 20, 2008 at 12:03:25 Pacific
Reply:

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.


0

Response Number 7
Name: Mechanix2Go
Date: February 20, 2008 at 12:59:38 Pacific
Reply:

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



0

Response Number 8
Name: ghostdog
Date: February 22, 2008 at 21:12:41 Pacific
Reply:

@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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: generate filename in batch file?

Date Routines in Batch Files www.computing.net/answers/programming/date-routines-in-batch-files/15590.html

%DATE% in batch files with win98 www.computing.net/answers/programming/date-in-batch-files-with-win98/4007.html

Progress bar in batch file www.computing.net/answers/programming/progress-bar-in-batch-file/14919.html