-1

我编写了这个脚本来组合更多的 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%变量...我尝试使用%%photoor%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

为什么?

4

2 回答 2

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
于 2013-04-23T16:44:44.887 回答
0

好的,现在它工作了!谢谢!!

@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 
)
)
于 2013-04-24T09:45:40.510 回答