• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HELP! need assistance from batch file expert

Psyber

Senior member
Hi,
Hope I phrase this correctly. I wanted to create a batch file that does the following. I want it to run a program that takes in a variable that is dependant on the date. For example the original code (which doesn't work) is:

call rmagic.exe -statistics_File_In=C:\webStatistics\%yy%_%mm%_%dd%-MYwebsite_Stats.dat

I need the %yy%_%mm%_%dd% part of it to output the actual date separated by underscores. I am running Windows NT if that has anything to with what approach I should use. Any help would be appreciated.

Also, kinda off-topic, any suggestions on good forums to get answers for programming questions.

Mucho Thanks in Advance,
Psyber
 
I don't think there is a way to do this with a simple batch file. You might want to look into:

1. 4NT (which has a much expanded batch language)

2. writing a small C program to output a small batch file, e.g.:

set dd=05
set mm=09
set yy=02

That you could then CALL from your main batch file.

3. doing the whole thing in perl. 🙂
 
I find the Arstechnica "Programmer's Symposium" to be very good, lots of professional programmers there.
 
Use VBScript/WSH. As you've probably guessed, batch files were not designed to do anything complicated.
 
I've gotten some help on this. I would like to keep it a simple batch file if possible.


@echo off
for /f "tokens=2-4 delims=/ " %%a in (
'date /t'
) do set yy=%%c&set mm=%%a&set dd=%%b
set yy=%yy:~2%
set currentDate=%yy%_%mm%_%dd%


That is the part that does work. This is the part that doesn't:

call C:\webStatistics\ReportMagic\rmagic.exe -statistics_File_In=C:\webStatistics\%currentDate%-MYwebsite_Stats.dat

Anyone know how to piece together a executable with attributes that stem from a variable?

Thanks!
 
Edit: Brain kicked in and came up with a way that didn't use a temp file

Actually, that part you think works doesn't. This is the working version of that I came up with:

@echo off
for /f "tokens=2-4 delims=/ " %%a in ('cmd /c date /t') do set yy=%%c&set mm=%%a&set dd=%%b


Copy and paste the above since there's a very critical space in there you might miss if typing.

Now you can use your original call rmagic.exe -statistics_File_In=C:\webStatistics\%yy%_%mm%_%dd%-MYwebsite_Stats.dat
 
BitSpit, YOU ROCK!!!
Thanks, your code works with a slight change. Final code is as follows


@echo off
for /f "tokens=2-4 delims=/ " %%a in ('cmd /c date /t') do set yy=%yy:~2%&set mm=%%a&set dd=%%b
call rmagic.exe -statistics_File_In=C:\webStatistics\%yy%_%mm%_%dd%-MYwebsite_Stats.dat


You beat out 2 other forums I posted at. 😉
 
Back
Top