好的,这是another question I had earlier的后续行动。我的代码找到上一个工作日,然后遍历3到9之间的所有小时 - 分钟组合。
代码会将这个新变量提供给.msl(基本上是我们文档直接服务器的.txt文件)。
我需要代码将找到的变量写入.msl文件并运行该文件。
这是我到目前为止所做的:
@ECHO off
setlocal enabledelayedexpansion
echo wd = Weekday^(Date^(^), vbSunday^)>yesterday.vbs
echo if wd ^< 3 then dif = -1 - wd else dif = -1 >>yesterday.vbs
echo d = dateadd^("d", dif, Date^(^)^)>>yesterday.vbs
echo wscript.echo DatePart^("yyyy",d^) ^& " " ^& DatePart^("m", d^) ^& " " ^& DatePart^("d", d^) >>yesterday.vbs
for /f "tokens=1-3" %%I in ('cscript /nologo yesterday.vbs') do (
set year=%%I
if %%J leq 9 (set month=0%%J) else set month=%%J
if %%K leq 9 (set day=0%%K) else set day=%%K
)
del yesterday.vbs
set YYYY=%year:~-4%
set MM=%month:~-2%
set DD=%day:~-2%
set prevbusday=%YYYY%%MM%%DD%
echo %prevbusday%
pause
For /L %%G IN (3,1,9) DO (
For /L %%H IN (0,1,59) DO (
set "h=0%%H"
ECHO %prevbusday%0%%G!h:~-2!
set "id=%prevbusday%0%%G!h:~-2!"
break>test.msl
(echo OPENVIEW SERVERID 'Mobius Server ' REPORTID 'TrialReports ' VERSIONID ' **id** 'SECTIONID ' 0000-000 Name of Report' PAGE 1)> test.msl
(echo EXPORT ASCII FILE 'C:\New folder\check.rpt' CURSEC GROUP '') >> test.msl
(echo CLOSE) >> test.msl
rem **Here I will add the code to call the newly minted 'test.msl' - but
rem I'll get to that later**
)
)
pause
在哪里说VERSIONID ' id
我需要注入变量。
我试图用引号做这个,不能做什么,也不能弄清楚如何正确地注入它。
答案 0 :(得分:3)
Windows变量是内联计算的。您所要做的就是将**id**
替换为!id!
。
我觉得我已经做了一些有用的事情,我也会帮助你完成之前的工作日计算。您可以混合代码并使用JScript Date()
对象来消除回显到临时.vbs脚本的必要性。我还将重定向移动到test.msl
到括号代码块以稍微清理代码。如果您的MSL处理程序允许,您可以将所有OPENVIEW...EXPORT...CLOSE
行转储到文件中,并且只运行一次处理程序,这可能会提高效率。有关示例,请参阅revision 2 of this answer。
我认为这可以满足您的需求。用.bat扩展名保存。
@if (@CodeSection == @Batch) @then
@ECHO off
setlocal enabledelayedexpansion
for /f %%I in ('cscript /nologo /e:JScript "%~f0"') do set "prevbusday=%%I"
echo %prevbusday%
pause
For /L %%G IN (3,1,9) DO (
For /L %%H IN (0,1,59) DO (
set "h=0%%H"
set "id=%prevbusday%0%%G!h:~-2!"
echo !id!
>test.msl (
echo OPENVIEW SERVERID 'Mobius Server ' REPORTID 'TrialReports ' VERSIONID ' !id! ' SECTIONID ' 0000-000 Name of Report' PAGE 1
echo EXPORT ASCII FILE 'C:\New folder\check.rpt' CURSEC GROUP ''
echo CLOSE
)
rem **Here I will add the code to call the newly minted 'test.msl' - but
rem I'll get to that later**
)
)
pause
goto :EOF
@end // end batch / begin JScript chimera
var day = 1000 * 60 * 60 * 24,
yesterday = new Date().getDay() - 1,
prevbusday = new Date(!yesterday?new Date()-day*3:(yesterday<0?new Date()-day*2:new Date()-day)),
y = [
prevbusday.getFullYear(),
('0' + (prevbusday.getMonth() + 1)).match(/\d\d$/)[0],
('0' + prevbusday.getDate()).match(/\d\d$/)[0]
]
WSH.Echo(y.join(''));
答案 1 :(得分:2)
这是@ rojo编辑的最终代码库。
<Window.Resources>
<vm:MyTemplateSelector x:Key="MyTemplateSelector" />
</Window.Resources>
<TreeView ItemTemplateSelector={StaticResource MyTemplateSelector} />