forked from daveshap/Document_Scraping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_docx.ps1
26 lines (22 loc) · 863 Bytes
/
convert_docx.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$word = new-object -ComObject word.application
$word.Visible = $false
$source_dir = 'C:/Document_Scraping/Docx/'
$dest_dir = 'C:/Document_Scraping/converted/'
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
$files = Get-ChildItem -Path $source_dir | Where-Object {$_.Name -like "*.docx"}
foreach ($file in $files)
{
Write-Host $file
# accept all
$doc = $word.Documents.Open($file.FullName)
#$doc.Revisions.AcceptAll()
$newname = $file.Name.Replace(".docx",".txt")
$doc.SaveAs([ref]($dest_dir + $newname), [ref]$saveFormat)
$doc.Close()
# reject all
#$doc = $word.Documents.Open($file.FullName)
#$doc.Revisions.RejectAll()
#$newname = $file.Name.Replace(".docx","_rejected.txt")
#$doc.SaveAs([ref]($dest_dir + $newname), [ref]$saveFormat)
#$doc.Close()
}