-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathgenerate_html.ps1
66 lines (51 loc) · 2.47 KB
/
generate_html.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
$ext = ".html"
$extno = 8
$Directory = Resolve-Path $Args[0]
$LineEnding = 1 # WdLineEndingType 1 = CROnly
$Encoding = 65001 # Codepage for UTF8
$testFileDepth = 2
$AbsPath = @(Get-ChildItem -path $Directory -Recurse -Exclude *.txt, *.skip, "*.html", "*.rtf","*.odt","*.doc")
:htmlMain for ($i = 0; $i -lt $AbsPath.length; $i++) {
$AbsPathI = Resolve-Path $AbsPath[$i] | Select-Object -ExpandProperty Path
if (Test-Path ($AbsPathI + $ext) -PathType Leaf ) { continue htmlMain }
if (Test-Path ($AbsPathI + ".skip")) { continue htmlMain }
$Word = New-Object -ComObject Word.Application
try {
$Doc = $Word.Documents.Open($AbsPathI, $False, $True, $False, "WordJS", "WordJS")
$Doc.SaveAs(($AbsPathI + $ext), $extno, $False, "", $False, "", $False, $False, $False, $False, $False, $Encoding, $False, $False, $LineEnding)
$Doc.Close()
Remove-Item -Force -Recurse ($AbsPathI + "_files")
$list = $AbsPathI -split '\\'
$index = $list.IndexOf('test_files')
$secondHalf = ($list | Select-Object -last ($list.Length - $index - $testFileDepth)) -join '\'
$leaf = $secondHalf | Split-Path -Leaf
$secondHalf = ($secondHalf | Split-Path -Parent) + "\" + $leaf + $ext
$fileName = $leaf + $ext
$htmlPath = Join-Path -Path "./test_files/html" $secondHalf;
$current = (Split-Path $AbsPathI -Parent) + "\" + $fileName
Write-Output $current
New-Item -ItemType File -Path $htmlPath -Force
Move-Item -Path $current -Destination $htmlPath -Force
}
catch {
Write-Output "Skipping (has pwd)"
}
Stop-Process -Name "winword"
}
$AbsPath = @(Get-ChildItem -path $Directory -Recurse -Exclude *.txt, *.skip, *.docx, "*.rtf","*.odt","*.doc")
:txtMain for ($i = 0; $i -lt $AbsPath.length; $i++) {
$AbsPathI = Resolve-Path $AbsPath[$i] | Select-Object -ExpandProperty Path
Write-Output $AbsPathI
if (Test-Path ($AbsPathI + ".txt") -PathType Leaf ) { continue txtMain }
if (Test-Path ($AbsPathI + ".skip")) { continue txtMain }
$Word = New-Object -ComObject Word.Application
try {
$Doc = $Word.Documents.Open($AbsPathI, $False, $True, $False, "WordJS", "WordJS")
$Doc.SaveAs(($AbsPathI + ".txt"), 7, $False, "", $False, "", $False, $False, $False, $False, $False, $Encoding, $False, $False, $LineEnding)
$Doc.Close()
}
catch {
Write-Output "Skipping (has pwd): $AbsPathI"
}
Stop-Process -Name "winword"
}