Dynamic Variable Creation

January 12, 2010 at 00:26:50
Specs: Windows Server 2003, N/A
I would like to know how to create a batch file variable that changes dynamically according to a directory listing.
ie: I have a list of folders that are updated on a daily basis. Every new folder needs to be processed and the folder name is determined by the date it is created, eg today's date is `2010-01-12` and the folder that needs to be processed is `20100111`. As you can see the folder name is arranged YMD and it is the previous day.

I have all the process commands but I do not know how to create a variable that can change dynamically and then to use it in my batch file.

See More: Dynamic Variable Creation

Report •

January 12, 2010 at 01:09:21
I'm not getting involved in any 'date math'; always a sad subjuct.

But for your purpose it would seem to meet the requirement to simply get the last created folder name.

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/ad/o-d/tc') do (
set latest=%%a
goto :done
echo !latest!

Helping others achieve escape felicity


Report •

January 12, 2010 at 06:10:44
I assume the " 'dir/b/ad/o-d/tc' " is the directory path?

Report •

January 12, 2010 at 13:01:04
no, the slashes are DIR option switches (at cmd prompt type:
dir /?
and you will see what each option switch does.)

(ps M2go: did you find/remove the dashes from my code?
i ran it and it bombed cause i forgot to take out those dashes
from between the 7th and 8th hex bytes, just wanted to warn you in advance)
i have picked up the gauntlet on this date thing:
to get the date, use the bios date as created by M2:
@echo off & setlocal
:: be sure to invoke BIOSD8 with %0 on cmdliine!
if "%2"=="" BIOSD8 %0
set yy=%1
set mm=%2
set dd=%3
:: here down does the subtraction
set /a dd-=1
if dd equ 0 (
set /a dd=31
set /a mm="(%dwMONTH%+10)%%12+1"
call %mm% 2>nul)
SET d8=%yy%%mm%%dd%
:... rest of your script here

set /a dd-=1
goto :eof
:12 set /a yy -=1
goto :eof
set /a dd=28
set /a leap="yy%%4"
if %leap% equ 0 set /a dd=29

here is BIOSD8, concieved by Mechanix2go.
it is a separately stored script:

@goto :AAA
e 100 8A 1E 82 00 80 CB 20 B4 2A CD 21 80 FB 77 74 10
e 110 88 C8 80 FB 79 74 09 88 F0 80 FB 6D 74 02 88 D0
e 120 B4 4C CD 21 03 B4 4C CD 21

@echo off
if not %OS%!==! setLocal enableDELAYedexpansion

if exist dmy.com goto :BBB
debug dmy.com < date1.bat >nul 2>nul

dmy d
set dd=%errorlevel%
if "%dd:~1%" equ "" set dd=0%dd%
:echo Day %DD%

dmy w
set days=Sunday Monday Tuesday WednesdayThursday Friday Saturday
set dofw=%errorlevel%
set /a ee=%dofw%*9
set day=!days:~%ee%,9!
:echo dofw: !day! !dofw!

dmy m
set mm=%errorlevel%
if "%mm:~1%" equ "" set mm=0%mm%
:echo month: !mm!

dmy y
set /a yyyy=%errorlevel%+1792
:echo Year %YYYY%

%1 %yyyy% %mm% %dd% %dofw% %day%
::// end of script

alternatively, instead of using the cmdline to pass the date, it could write to the external environment table:
set year=%yyyy%
set month=%month%
set day=%dd%
set dofw=%dofw"
set day=%day%

Report •

Related Solutions

January 12, 2010 at 21:56:05
I have no interest in messing with DATE substrings.

Helping others achieve escape felicity


Report •

January 12, 2010 at 23:05:04
hell, you wrote the darn solution, and you have "date phobia?"

Report •

Ask Question