请温柔......
我正在尝试使用第一个脚本中设置的变量创建一个.bat脚本来创建另一个.bat脚本。 我所有的其他人都回应着#39;已经以正确的格式输出到SS_Update.bat。但我正在努力解决几条无法正确复制的行。在"设置新的SS.bat"我有......(脱离背景)
echo for /r %Tempfolder% %%%a in (*.zip) do set sszip=%%%~nxa >> %USERPROFILE%\Documents\%Site%\SS_Update.bat
echo for /r %Tempfolder% %%%a in (*.zip) do set tempfile=%%%~dpnxa >> %USERPROFILE%\Documents\%Site%\SS_Update.bat
echo for /f %%%i in (%currentss%) do set date1=%%%~ti >> %USERPROFILE%\Documents\%Site%\SS_Update.bat
echo for /f %%%i in (%extractedss%) do set date2=%%%~ti >> %USERPROFILE%\Documents\%Site%\SS_Update.bat
echo for /f %%%i in ('DIR /B /O:D %currentss% %extractedss%') do echo Current SS is older than the Extracted SS or missing... >> %USERPROFILE%\Documents\%Site%\SS_Update.bat
结果" SS_Update.bat"是...
for /r C:\Users\Pelican\Documents\Temp %%~nxa
for /r C:\Users\Pelican\Documents\Temp %%~dpnxa
for /f %currentss%~ti
for /f %extractedss%~ti
for /f %D ') do echo Current SS is older than the Extracted SS or missing...
我明白我需要逃避一些特殊字符,即我想要%%所以我使用了%%%。我已经尝试了使用Escape Characters中的示例所能想到的所有组合,但我仍然远离我所追求的目标。
任何帮助将不胜感激!
答案 0 :(得分:0)
您可以通过在行前加上包含回显和重定向的var来简化任务,因此代码看起来正常,除了必要的加倍%和转义<>|&
。
Set _=^>^> "%USERPROFILE%\Documents\%Site%\SS_Update.bat" Echo
%_% for /r %Tempfolder% %%%%a in (*.zip) do set sszip=%%%%~nxa
%_% for /r %Tempfolder% %%%%a in (*.zip) do set tempfile=%%%%~dpnxa
%_% for /f %%%%i in (%currentss%) do set date1=%%%%~ti
%_% for /f %%%%i in (%extractedss%) do set date2=%%%%~ti
%_% for /f %%%%i in ('DIR /B /O:D %currentss% %extractedss%') do echo Current SS is older than the Extracted SS or missing...
答案 1 :(得分:0)
我更愿意将命令包含在单个重定向中。 (唯一的问题是使用标准的抑扬符号转义内部右括号)。要逃避单个百分比字符,您使用另一个百分比字符,因此要回显两个字符,您需要四个字符。
>>"%USERPROFILE%\Documents\%Site%\SS_Update.bat" (
ECHO FOR /R "%Tempfolder%" %%%%A IN (*.zip^) DO SET "sszip=%%%%~nxA"
ECHO FOR /R "%Tempfolder%" %%%%A IN (*.zip^) DO SET "tempfile=%%%%~dpnxA"
ECHO FOR /F %%%%I IN (%currentss%^) DO SET "date1=%%%%~tI"
ECHO FOR /F %%%%I IN (%extractedss%^) DO SET "date2=%%%%~tI"
ECHO FOR /F %%%%I IN ('DIR/B/OD %currentss% %extractedss%'^) DO (
ECHO ECHO Current SS is older than the Extracted SS or missing...^)
)