0

我有以下代码:

@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 文件时,它们没有产生任何结果。

4

1 回答 1

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
于 2012-12-10T21:18:54.753 回答