Windows 需要pandoc的批处理命令

Windows 需要pandoc的批处理命令,windows,batch-file,cmd,pandoc,Windows,Batch File,Cmd,Pandoc,我有一个包含子目录的目录,我正在尝试将docx转换为html。 到目前为止,我已找到以下命令: @ECHO off :selectfile :: Clear any preexisting filename variables SET filename= :: Ask which file we're converting. SET /p filename=Which file? (Don't include the .docx file extension): CALL pandoc -o -

我有一个包含子目录的目录,我正在尝试将docx转换为html。 到目前为止,我已找到以下命令:

@ECHO off
:selectfile
:: Clear any preexisting filename variables
SET filename=
:: Ask which file we're converting.
SET /p filename=Which file? (Don't include the .docx file extension):
CALL pandoc -o -s "%filename%".html --self-contained "%filename%".docx
GOTO selectfile
问题是它问我文件名,我必须把这个bat文件放在每个子文件夹中才能完成这项工作。 我想做一些更改,这样它将自动检测子文件夹,并将所有docx文件转换为同名的html文件。 这可能吗,伙计们? 有人可以修改这个脚本吗?
非常感谢。

以下注释代码片段可能会有所帮助:

@echo OFF
SETLOCAL EnableExtensions

rem iterate all *.docx recursively
for /f "delims=" %%G in ('dir /B /S *.docx  2^>NUL') do (

    rem check .html existence
    if not exist "%%~dpnG.html" (

        rem change the current directory and store the previous path for use by the POPD
        pushd "%%~dpG"

        rem `CALL pandoc` is merely displayed for debugging purposes
        rem               remove ECHO no sooner than debugged          
        ECHO CALL pandoc -o -s "%%~nG.html" --self-contained "%%~nxG"

        rem change directory back to the path most recently stored by the PUSHD command
        popd
    )
)
编辑

我想做一些更改,这样它将检测子文件夹 自动和将所有文件docx转换为
html
文件 同名的

您可以将上述代码段嵌入到脚本中,如下所示:

@echo OFF
SETLOCAL EnableExtensions
:selectfile
:: Clear any preexisting filename variables
SET filename=
:: Ask which file we're converting.
SET /p filename=Which file? (Don't include the .docx file extension):

if not defined filename GOTO selectfile

rem iterate all %filename%.docx recursively
for /f "delims=" %%G in ('dir /B /S "%filename%.docx" 2^>NUL') do (
    rem check .html existence
    if not exist "%%~dpnG.html" (
        rem change the current directory and store the previous path for use by the POPD
        pushd "%%~dpG"
        rem `CALL pandoc` is merely displayed for debugging purposes
        rem               remove ECHO no sooner than debugged          
        ECHO CALL pandoc -o -s "%%~nG.html" --self-contained "%%~nxG"
        rem change directory back to the path most recently stored by the PUSHD command
        popd
    )
)

GOTO selectfile
资源(必读):

  • (命令参考)
  • (其他特殊性)
  • %~G
    等特殊页面)
  • 2>NUL
    等特殊页面)

提示:请用双引号括起整个文件名,而不仅仅是其中的一部分,分别强制Windows命令解释器使用已启动应用程序的启动代码来修复参数字符串,即使用
%filename%.html“
%filename%.docx”
。设置文件名命令将搞乱这一点。这样做很好,但并不能解决我的问题。openFile:不存在(没有这样的文件或目录)获取此错误。它正在搜索所有子文件夹tho..@JosefZJust删除了-s并工作了。。非常感谢。男人真的很欣赏这个:D