mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-12-26 00:28:53 +01:00
85 lines
2.1 KiB
Markdown
85 lines
2.1 KiB
Markdown
The *convert-docx2md.ps1* Script
|
|
===========================
|
|
|
|
This PowerShell script converts .DOCX file(s) into Markdown.
|
|
|
|
Parameters
|
|
----------
|
|
```powershell
|
|
/home/markus/Repos/PowerShell/scripts/convert-docx2md.ps1 [[-FilePattern] <String>] [<CommonParameters>]
|
|
|
|
-FilePattern <String>
|
|
Specifies the file pattern to the .DOCX file(s)
|
|
|
|
Required? false
|
|
Position? 1
|
|
Default value
|
|
Accept pipeline input? false
|
|
Accept wildcard characters? false
|
|
|
|
[<CommonParameters>]
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
```
|
|
|
|
Example
|
|
-------
|
|
```powershell
|
|
PS> ./convert-docx2md *.docx
|
|
|
|
```
|
|
|
|
Notes
|
|
-----
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
Related Links
|
|
-------------
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
Script Content
|
|
--------------
|
|
```powershell
|
|
<#
|
|
.SYNOPSIS
|
|
Converts .DOCX file(s) into Markdown
|
|
.DESCRIPTION
|
|
This PowerShell script converts .DOCX file(s) into Markdown.
|
|
.PARAMETER FilePattern
|
|
Specifies the file pattern to the .DOCX file(s)
|
|
.EXAMPLE
|
|
PS> ./convert-docx2md *.docx
|
|
.LINK
|
|
https://github.com/fleschutz/PowerShell
|
|
.NOTES
|
|
Author: Markus Fleschutz | License: CC0
|
|
#>
|
|
|
|
param([string]$FilePattern = "")
|
|
|
|
try {
|
|
$StopWatch = [system.diagnostics.stopwatch]::startNew()
|
|
|
|
if ($FilePattern -eq "" ) { $FilePattern = Read-Host "Enter the file pattern to the .DOCX file(s)" }
|
|
|
|
Write-Host "⏳ Searching for pandoc..."
|
|
$null = (pandoc --version)
|
|
if ($lastExitCode -ne "0") { throw "Can't execute 'pandoc' - make sure it's installed and available" }
|
|
|
|
Write-Host "⏳ Converting..."
|
|
gci -r -i $FilePattern | foreach {
|
|
$TargetPath = $_.directoryname + "\" + $_.basename + ".md"
|
|
& pandoc -f docx -s $_.name -o $TargetPath
|
|
}
|
|
|
|
[int]$Elapsed = $StopWatch.Elapsed.TotalSeconds
|
|
"✅ converted in $Elapsed sec"
|
|
exit 0 # success
|
|
} catch {
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
exit 1
|
|
}
|
|
```
|
|
|
|
*(generated by convert-ps2md.ps1 as of 11/08/2024 12:40:16)*
|