我有以下代码:
@ECHO OFF
IF EXIST comandosAEjecutar.tpl (DEL comandosAEjecutar.tpl)
ECHO Procesando archivos a subir...
FOR /f "tokens=1 delims=," %%g IN (config.tpl) DO ECHO open %%g>> comandosAEjecutar.tpl
FOR /f "tokens=2 delims=," %%g IN (config.tpl) DO ECHO %%g>> comandosAEjecutar.tpl
FOR /f "tokens=3 delims=," %%g IN (config.tpl) DO ECHO %%g>> comandosAEjecutar.tpl
ECHO binary>> comandosAEjecutar.tpl
FOR /f "tokens=4 delims=," %%g IN (config.tpl) DO ECHO cd %%g>> comandosAEjecutar.tpl
FOR /f "tokens=5 delims=," %%p IN (config.tpl) DO @SET pathLocal=%%p
FOR /r . %%g IN (%pathLocal%\*.txt %pathLocal%\*.zip) DO ECHO delete %%~nxg>> comandosAEjecutar.tpl
FOR /r . %%g IN (%pathLocal%\*.txt %pathLocal%\*.zip) DO ECHO put %%~nxg>> comandosAEjecutar.tpl
ECHO bye>> comandosAEjecutar.tpl
ECHO Comienzo de la sesion FTP...
FTP -i -s:"comandosAEjecutar.tpl"
ECHO Finalizado.
PAUSE
EXIT
实际问题如下:
FOR /f "tokens=5 delims=," %%p IN (config.tpl) DO @SET pathLocal=%%p
FOR /r . %%g IN (%pathLocal%\*.txt %pathLocal%\*.zip) DO ECHO delete %%~nxg>> comandosAEjecutar.tpl
FOR /r . %%g IN (%pathLocal%\*.txt %pathLocal%\*.zip) DO ECHO put %%~nxg>> comandosAEjecutar.tpl
我知道变量“pathLocal”正在设置正确,因为我做了一个ECHO,它显示了正确的路径,如:\\ red \ C \ pc \ pc.com \ serv \ down \ bol
问题是,当我在该目录上有.txt和.zip文件时,以下两行不会将变量解释为路径,因为它们不会产生任何结果。
答案 0 :(得分:2)
我相信你的问题是在括号中的pathlocal变量,尝试在/ r之后移动它
FOR /r %pathLocal% %%g IN (*.txt *.zip) DO ECHO delete %%~nxg>> comandosAEjecutar.tpl
FOR /r %pathLocal% %%g IN (*.txt *.zip) DO ECHO put %%~nxg>> comandosAEjecutar.tpl