如何在 Windows 中对文件夹中的所有文件使用 pandoc?

2024-01-21

pandoc.org 上的常见问题解答中有针对 Linux 和 Mac 用户的说明:

for f in *.txt; do pandoc "$f" -s -o "${f%.txt}.rtf"; done

但没有针对 Windows 用户的说明。


我对这个问题感到沮丧,所以我编写了一个批处理文件,您可以从 cmd 或 PowerShell 运行该文件,该文件对文件夹/目录和所有子目录中特定类型的所有文件调用 pandoc (即,它是递归的)。代码如下。将代码复制到记事本中并另存为pancompile.bat。从cmd运行是最简单的。从 PowerShell 中您可以将其调用为.\pancompile.bat。如果您运行不带任何参数的命令,它将输出示例用法,如下所示:

Usage: pancompile DIRECTORY FILENAME [filemask] ["options"]
Uses pandoc to compile all documents in specified directory and subdirectories to a single output document

DIRECTORY         the directory/folder to parse recursively (passed to pandoc -s);
                  use quotation marks if there are spaces in the directory name
FILENAME          the output file (passed to pandoc -o); use quotation marks if spaces
filemask          an optional file mask/filter, e.g. *.md; leave blank for all files
"options"         optional list of pandoc commands (must be in quotation marks)

Minimal example: pancompile docs complete_book.docx
Typical example: pancompile "My Documents" "Complete Book.docx" *.md "-f markdown -t docx --standalone --toc"

这是代码pancompile.bat。请注意,只有当所有目录路径和文件的字符总数小于 8092 时,它才会按预期工作:

@echo off
:: Check if user entered required options
if $%1$==$$ goto usage
if $%2$==$$ goto usage
setlocal disableDelayedExpansion
set "mask=%3"
if $%3$==$$ set "mask=*"
:: Remove quotation marks from pandoc options 
set options=%4
if not $%4$==$$ set options=%options:"=%
set "files="
:: This will only work if the total characters of all the paths and filenames together is less than 8192 characters
for /r %1 %%F in (%mask%) do call set files=%%files%% "%%F"
echo/
echo The following pandoc command will be executed:
echo/ 
echo pandoc -s %files% -o %2 %options%
echo/
:ask
echo Would you like to run pandoc on the files listed above? (Y/N)
set INPUT=
set /P INPUT=?: %=%
if /I "%INPUT%"=="y" goto yes 
if /I "%INPUT%"=="n" goto no
goto ask
:yes
pandoc -s %files% -o %2 --wrap=none %options%
echo Done
goto exit
:no
echo Command was cancelled
goto exit
:usage
echo/
if $%1$==$$ (
    echo This batch file needs to be run from the command line or from PowerShell
    echo/
) 
echo Usage: pancompile DIRECTORY FILENAME [filemask] ["options"]
echo Uses pandoc to compile all documents in specified directory and subdirectories to a single output document
echo/
echo DIRECTORY         the directory/folder to parse recursively (passed to pandoc -s);
echo                   use quotation marks if there are spaces in the directory name
echo FILENAME          the output file (passed to pandoc -o); use quotation marks if spaces
echo filemask          an optional file mask/filter, e.g. *.md; leave blank for all files 
echo "options"         optional list of pandoc commands (must be in quotation marks)
echo/
echo Minimal example: pancompile docs complete_book.docx
echo Typical example: pancompile "My Documents" "Complete Book.docx" *.md "-f markdown -t docx --standalone --toc"
:exit
:: End with a pause so user can read messages
echo/
echo Press any key to exit ...
pause>nul
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 Windows 中对文件夹中的所有文件使用 pandoc? 的相关文章

随机推荐

  • PHP next() 不工作

    我正在尝试使用 PHP 制作一个画廊 图像加载正确 但下一个和上一个按钮似乎不起作用 单击图片 1 下的 下一步 您将看到图片 3 但是单击 图片 3 将您带到图片 2 这是正确的 我应该如何更改我的代码以使两者都按顺序进行
  • 在 Play 2.4 with DI 中,如何在“Secured”特征中使用服务类?

    这是一个Play 文档中的授权示例 https www playframework com documentation 2 0 4 ScalaSecurity Authorization 版本 2 0 4 我试图找到此文档的更新版本 但找不
  • 在 IntelliJ 中使用 Scala 工作表很困难

    我正在学习 Scala 函数式编程原理课程 但我在 IntelliJ 中使用 Scala Worksheets 进行快速测试时遇到了很多问题 例如 我建立了一个新的 Scala 项目 在其中创建了一个名为的包对象lecture5 它在文件中
  • 在 R 中下载 Kaggle zip 文件

    我正在尝试直接从 R 代码本身的 Kaggle 空间下载 zip 文件 不幸的是 它的效果并不好 这是发生的事情 对于旧金山犯罪数据集 请访问https www kaggle com c sf crime data https www ka
  • Xcode pbxstrings 文件的用途是什么?

    我有一个 Xcode 项目 需要更改它构建的产品的名称 我仔细地浏览了项目文件 并认为我已经做出了所有可能的更改 最后一步是 grep 项目文件夹中的所有文件以查找旧名称的出现 结果很干净 但是在构建之后 grep 发现一个文件包含多次出现
  • 需要帮助为 SpreadsheetApp 创建 GMAIL Pub/Sub 通知服务(Google Apps 脚本)

    我希望我不必重新发布这个问题 但我的老板将这个问题推到了高优先级 我需要帮助来解决这个问题 我正在尝试使用 GAS 脚本从我的 GSuite 域上的地址提取发布 订阅通知 目前 我正在我的域上进行测试 基本上 我正在尝试完成所有这些材料中描
  • Windows 10、DPI 缩放和全屏

    我有一个应用程序 Windows 8 1 中的 PROCESS PER MONITOR DPI AWARE 和 Windows 10 v1703 中的 DPI AWARENESS CONTEXT PER MONITOR AWARE V2 我
  • 如何查找接口中方法的索引?

    如何找到接口中定义的过程 函数的索引 可以用RTTI来实现吗 首先我们需要枚举接口的方法 不幸的是这个程序 APPTYPE CONSOLE uses System SysUtils System Rtti type IMyIntf inte
  • Zend 框架窗体装饰器

    我正在尝试使用装饰器获得以下布局
  • 检查组合框值是否为空

    我创建了一个包含三个值的组合框 我希望在未选择任何项目时打开一个消息框 所以我尝试了以下操作 if comboBox1 SelectedItem null MessageBox Show Please select a value retu
  • asp网站项目中多目标框架的问题

    我开发了一个针对 NetStandard 和 NetFramework 的 C 库框架 这是通过编辑 csproj 文件 将 TargetFramework 更改为 TargetFramework 来完成的s并将它们都添加到标签中
  • 如何使 CSS3 悬停过渡仅运行一次而不是在用户“取消悬停”后“倒回”?

    我有一些 CSS 见下文 我想当用户将鼠标悬停在外部字段上时 使内部 div kitty 在屏幕上平移 这工作正常 但是 正如您所期望的 当用户将鼠标从外部字段移开时 动画会 倒带 然后 当然 如果用户再次悬停 动画就会重播 我试图弄清楚如
  • 错误的 UTF-8 无 BOM 编码

    我使用 Notepad 将所有文件转换为没有 BOM 编码的 UTF 8 我对 BOM 不再有任何问题 但是没有 BOM 编码的 UTF 根本不起作用 就好像我的网站是用 ANSI 编码的一样 所有特殊字符都显示为 或 造成这种情况的原因是
  • JSF 2.0 Facelets 嵌套模板继承

    是否可以定义从 Facelet 中的其他模板继承的模板 像这样的东西 GlobalTemplate xhtml users UsersTemplate xhtml template GlobalTemplate xhtml users vi
  • 超时超过 3 小时 Automation Runbook Azure

    大家好 我有一个运行手册要启动 但运行 分区过程 需要 3 个多小时 因此 它在完成之前停止了 我想知道是否有办法超过3小时的限制 我听说过混合运行手册 但我不确定它如何解决我的问题 您知道是否还有其他解决方案 多谢 如果您想坚持使用 Az
  • 是否可以通过包含在另一个数组中来过滤 angular.js?

    所以如果我有一个数组 scope letters id a id b id c 还有另一个数组 scope filterBy b c d 我想要一些 ng repeat 来仅通过 filterBy 中出现的项目来过滤 scope lette
  • 如何找到我的闪亮应用程序的现有 CSS?

    我对 css 很陌生 所以也许我问了错误的问题 但是当我使用 navbarPage 时 我是否将 css 添加到我的网络应用程序中 当我添加自己的 css 来添加一些文本和背景颜色时 它删除了导航栏 我的选项卡现在只是主标题下方的超链接 为
  • 从小程序调用 JS 在 Firefox 和 Chrome 中有效,但在 Safari 中无效

    我在小程序中有以下代码来调用一些 Javascript 这有点复杂 因为调用的 fn 从 divId 标识的 DOM 中获取一个对象 并在其上调用一个函数 Override public final void start System er
  • JavaScript 函数和对象

    我一直在读 Stoyan Stefanov 写的 面向对象的 Javascript 一书 我看到这句话 function 实际上是一个用 Function 构造函数 大写 F 构建的对象 作者用一些很好的例子证明了这一点 然而 基于这个陈述
  • 如何在 Windows 中对文件夹中的所有文件使用 pandoc?

    pandoc org 上的常见问题解答中有针对 Linux 和 Mac 用户的说明 for f in txt do pandoc f s o f txt rtf done 但没有针对 Windows 用户的说明 我对这个问题感到沮丧 所以我