1

我正在 Windows 7 中编写命令行批处理脚本来上传多个图像以进行托管,将 url(使用此程序)和文件名粘贴到一行文本中,然后将文本附加到文件中。

以下代码给了我一个错误,因为命令“cmd /c”太长了。

@echo on
set DIR1="C:\Users\My\Desktop\temp"
set DIR2="C:\Misc\Programs\EasyImgur"
set DIR3="C:\Users\My\Desktop"

set DIR2=%DIR2:"=%
set DIR3=%DIR3:"=%

forfiles /m *.png /p %DIR1% /c "cmd /c %DIR2%\EasyImgur.exe /anonymous @path && timeout /t 2 /nobreak > NUL && paste > %DIR3%\temp.txt && set /p URL= < %DIR3%\temp.txt && echo if(G9="@fname",IMAGE(%URL%,3), >> %DIR3%\test.txt"

del %DIR3%\temp.txt

pause
exit

有没有办法解决?有什么方法可以在“cmd /c”之后调用所有文本而不打破字符限制?我需要为目录中的每个文件完成所有这些工作。

提前致谢。

4

2 回答 2

1

感谢 Harry Johnston 的帮助,我明白了!一探究竟。

代码是:

@echo off

setlocal EnableDelayedExpansion

set "DIR1=C:\Users\RyzaJr\Desktop\temp"
set "DIR2=C:\Misc\Programs\EasyImgur"

for %%a in (%DIR1%\*.png) do (

    "%DIR2%\EasyImgur.exe" /anonymous "%%a"
    timeout /t 4 /nobreak > NUL
    paste > temp.txt
    set /p URL= < temp.txt
    echo if(G11="%%~na",IMAGE(!URL!,3^), >> "output.txt"

)

del temp.txt
exit
于 2015-09-02T05:41:50.610 回答
0

这可能对您有用 - 您在文件中回显的术语的括号不匹配。

@echo on
set "DIR1=C:\Users\My\Desktop\temp"
set "DIR2=C:\Misc\Programs\EasyImgur"
set "DIR3=C:\Users\My\Desktop"

for %%a in ("%DIR1%\*.png") do (
  start "" /w /b "%DIR2%\EasyImgur.exe" /anonymous "%%a"
  set "flag="
   for /f "delims=" %%b in ('paste') do (
     if not defined flag >>"%DIR3%\test.txt" echo if(G9="%%~na",IMAGE(%%b,3^),
     set flag=1
   )
)
pause
于 2015-09-02T05:02:00.847 回答