2017-03-06 3 views
0

サブディレクトリのあるディレクトリがあり、docxをhtmlに変換しようとしています。 は、これまでのところ、私は、このコマンドを発見した:pandocのバッチコマンドが必要

@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ファイルに変換するようにいくつかの変更を加えたいと思います。 これは可能ですか? 誰でもこのスクリプトを変更できますか? 本当に感謝しています。

次のコメントのコードスニペットは、助けることができる
+3

ヒント:https://stackoverflow.com/documentation/batch-file/3695/for-loops-in-batch -files#t = 201703061006249850917 – DavidPostill

+1

ファイル名全体を二重引用符で囲んでください。Windowsコマンドインタープリタを強制的に起動する部分だけではなく、起動したアプリケーションの起動コードがパラメータ文字列を修正するために使用してください。 ''%filename%.html ' 'と' '%filename%.docx" 'となります。 – Mofi

+0

set filenameコマンドを実行すると、これが失われます。そのような罰金と働くが、私の問題を解決することはできません。 – user3551620

答えて

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 

資源(必読):

Windows CMD Shell Command Line Syntax

  • %~Gなど特別ページ)Command Line arguments (Parameters)
  • 2>NULなど特別ページ)Redirection
  • +0

    openFile:存在しません(このようなファイルやディレクトリはありません)。 – user3551620

    +0

    そのすべてのサブフォルダを検索tho .. @ JosefZ – user3551620

    +0

    ちょうど削除された - と働いた..ありがとう。男は本当にこれを感謝します:D – user3551620

    関連する問題