Skip to content

Instantly share code, notes, and snippets.

@xbns
Created May 24, 2021 06:37
Show Gist options
  • Save xbns/d8f00c05c8e11de53367e7161bafc62b to your computer and use it in GitHub Desktop.
Save xbns/d8f00c05c8e11de53367e7161bafc62b to your computer and use it in GitHub Desktop.
#batch convert from docx to docx using pandoc
:: pandoc-docx-md.bat
::
:: Don't show these commands to the user
@ECHO off
:: Set the title of the window
TITLE Convert docx to markdown with Pandoc
:: Select file marker
: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):
:: Feedback
ECHO Running pandoc...
::TimeStamp
@ECHO OFF
@REM use FOR /F to 'break out' the componetns of %DATE% and %TIME%,assuming 'yyyy/mm/dd' format date i.e
for /F "tokens=1-6* delims=.:~/ " %%i IN ("%DATE% %TIME%") DO Set "YYYY=%%i" & Set "MM=%%j" & Set "DD=%%k" & Set "HH=%%l" & Set "MI=%%m" & Set "SS=%%n"
@REM switch the year and day if appropriate
IF NOT "X%DD:~2%" =="X" Set "YYYY=%DD%" & Set "DD=%YYYY%"
Set "TimeStamp=%YYYY%%MM%%DD%_%HH%%MI%%SS%"
:: Run pandoc
CALL pandoc -f docx -t docx --reference-doc="./custom_ref_docx.docx" "%filename%".docx --output="%filename%-%TimeStamp%".docx"
:: Feedback
ECHO Done. Ready for another file.
:: Let the user easily run that again
SET repeat=
SET /p repeat=Hit enter to convert another file, or any other key and enter to stop.
IF "%repeat%"=="" GOTO selectfile
:: Otherwise end
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment