我写了这个脚本来组合更多的html文件。我使用随机函数作为其中的一部分。我看到一件奇怪的事......
@echo on
pause
CD "C:\Documents and Settings\Mauro\Documenti\Firme\ProvaMerge\"
pause
for %%i in (Pasqualino,Mauro) DO (
pause
ECHO %%i
pause
type Parti_Standard\StrutturaTabella_1parte.txt > %%i.html
pause
type utenti\%%i.html >> %%i.html
pause
type Parti_Standard\StrutturaTabella_2parte.txt >>%%i.html
:loop
set /a photo=%random% %% 3 + 1
ECHO RANDOM
ECHO %random% %%PHOTO
TYPE Immagini\%photo%.txt >> %%i.html
pause
type Parti_Standard\StrutturaTabella_3parte.txt >> %%i.html
type Firme_Standard\"Firma Inox Pack.html" >> %%i.html
)
pause
一切正常,但我没有看到%photo%
变量...我尝试使用%%photo
或%photo%
,但我只获得了一个空变量。相反,首先是为了提高该脚本的复杂性,我在没有for循环的情况下使用它...而且它运行正常。
@echo on
CD "C:\Documents and Settings\Mauro\Documenti\Firme\ProvaMerge\"
type Parti_Standard\StrutturaTabella_1parte.txt >new.html
type mauro.html >> new.html
type Parti_Standard\StrutturaTabella_2parte.txt >>new.html
:loop
set /a photo=%random% %% 3 + 1
echo %%photo
pause
TYPE Immagini\%photo%.txt >> new.html
type Parti_Standard\StrutturaTabella_3parte.txt >> new.html
type Firme_Standard\"Firma Inox Pack.html" >>new.html
pause
为什么?
答案 0 :(得分:0)
在代码块内(例如for循环),您需要delayed expansion
。例如,这不起作用:
@echo off&setlocal
(
set /a photo=%random% %% 3 + 1
echo %photo%
)
..这有效:
@echo off&setlocal enabledelayedexpansion
(
set /a photo=!random! %% 3 + 1
echo !photo!
)
这也必须用于写入文件:
TYPE Immagini\!photo!.txt >> %%i.html
答案 1 :(得分:0)
oK现在可以了!谢谢!!
@echooff
pause
CD "C:\Documents and Settings\Mauro\Documenti\Firme\ProvaMerge\"
for %%i in (Pasqualino,Mauro) DO (
for %%g in ("Firma Inox Pack","Firma Mail Arca Cucine") Do (
pause
ECHO "%%i %%g".html
type Parti_Standard\StrutturaTabella_1parte.txt > Firme_Composte\%%i\"%%i %%g".html
type utenti\%%i.html >> Firme_Composte\%%i\"%%i %%g".html
type Parti_Standard\StrutturaTabella_2parte.txt >> Firme_Composte\%%i\"%%i %%g".html
pause
setlocal enabledelayedexpansion
(
set /a n=!random! %% 3 + 1
echo !n!
)
TYPE Immagini\!n!.txt >> Firme_Composte\%%i\"%%i %%g".html
pause
type Parti_Standard\StrutturaTabella_3parte.txt >> Firme_Composte\%%i\"%%i %%g".html
type Firme_Standard\%%g.html >> Firme_Composte\%%i\"%%i %%g".html
)
)