Powershell批量将doc转markdown

一、Powershell批量将doc转为docx

前提是已经安装office

复制代码
# 创建 Word 应用对象
$word = New-Object -ComObject Word.Application
$word.Visible = $false
# 遍历指定目录及子目录中的所有 .doc 文件
# Get-ChildItem -Path "C:\path\to\docs" -Recurse -Include *.doc | ForEach-Object {
# 我手动放到一个目录下,没有子目录
Get-ChildItem -Filter  *.doc | ForEach-Object {
   $doc = $word.Documents.Open($_.FullName)
   $newPath = $_.FullName -replace "\.doc$", ".docx"
   # 12 表示保存为 DOCX 格式
   $doc.SaveAs([ref] $newPath, [ref] 12)
   $doc.Close()
}
# 退出 Word 应用
$word.Quit()

二、Powershell批量将docx转markdown

前提是已经安装pandoc

复制代码
# 创建输出目录
New-Item -ItemType Directory -Force -Path output
#New-Item -ItemType Directory -Force -Path output/images

# 遍历所有 DOCX 文件
Get-ChildItem -Filter *.docx | ForEach-Object {
    $filename = $_.BaseName
    
    pandoc -s $_.FullName -t markdown -o "output/$filename.md" 
        
    Write-Host "已转换: $($_.Name) -> $filename.md"
}

Write-Host "批量转换完成!"
相关推荐
E_ICEBLUE2 天前
Python 实现 Excel 转 Markdown,支持工作表、单元格区域和批量处理
python·excel·markdown·格式转换
智码看视界6 天前
Day68-结构化Prompt设计:XML标签法/Markdown法/JSON Schema
prompt·markdown·json schema·spring ai·结构化prompt·xml标签
不想学算法了11 天前
markdown格式常用命令
markdown
E_ICEBLUE16 天前
Python 实现 Markdown 转 Word、PDF:从转换到页面设置
python·pdf·word·markdown·格式转换
G_G#19 天前
一款主打本地离线的Windows Markdown编辑器 MD.E,支持AI智能体与定时自动化
markdown·md格式·专用编辑器·免费markdown编辑工具
kisshyshy19 天前
掘金同款社区数据库设计:9张表带你吃透建表、索引与约束
后端·sql·markdown
用户2986985301419 天前
Markdown 转 PDF 免费在线攻略:简单几步轻松搞定
人工智能·后端·markdown
Simon_He20 天前
一个渲染内核,五个框架包:我的流式 Markdown 渲染库是怎么长成“全家桶”的
前端·vue.js·markdown
嘟嘟071720 天前
一个微信公众号 Markdown 渲染组件,如何用 SDD 把需求、架构、任务一次写清
react.js·markdown
北漂燕郊杨哥21 天前
DotMD:一款基于 Go + Wails 的轻量开源 Markdown 桌面编辑器
golang·开源·编辑器·markdown·md