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 "批量转换完成!"
相关推荐
修己xj2 天前
MarkText:一款被低估的开源 Markdown 编辑器
markdown
大家的林语冰5 天前
连 Markdown 都不放过,Rust 在前端基建杀疯了,万物皆可“锈化“!
前端·javascript·markdown
曲幽10 天前
别只盯着GitBook了!这个文档神器让你的笔记秒变网站
web·markdown·docsify·seo·gitbook·vuepress·document·index
一只fish13 天前
一文了解Markdown
html·markdown
vortex514 天前
CheatMD:让 Markdown 笔记变成可执行的交互式命令
笔记·网络安全·markdown
MIXLLRED15 天前
随笔——在 Ubuntu 22.04 中查看 Markdown (.md) 文件
linux·运维·ubuntu·markdown
不剪发的Tony老师17 天前
MarKing:一款现代化专业级Markdown编辑器
文本编辑器·markdown·知识管理
Soari17 天前
GitHub 开源项目解析:microsoft/markitdown —— 面向 LLM 的多格式文档转 Markdown 工具
microsoft·开源·github·markdown·rag
仿生狮子20 天前
🎼 从文本到交互界面——GenUI 的中庸之道
前端·vue.js·markdown
X档案库22 天前
告别臃肿与残缺!MarkShareX——AI原生+Rust轻量自托管Markdown博客,一站式建站首选
ai·博客·markdown