我有一个包含子目录的目录,我正在尝试将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文件。 这可能吗? 有人可以修改这个脚本吗? 非常感谢。
答案 0 :(得分:1)
以下评论的代码段可以提供帮助:
@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
等特殊页面)Command Line arguments (Parameters) 2>NUL
等特殊页面)Redirection