Skip to content

Commit 2a90820

Browse files
committed
Diff-Word: resolve file paths on start
This should fix the issues with relative and PowerShell-only file paths (e.g. ~/file.docx).
1 parent 78e7b61 commit 2a90820

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

Diff-Word.ps1

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
param(
2-
$BaseFileName,
3-
$ChangedFileName
2+
[string] $BaseFileName,
3+
[string] $ChangedFileName
44
)
55

66
$ErrorActionPreference = 'Stop'
77

8+
function resolve($relativePath) {
9+
(Resolve-Path $relativePath).Path
10+
}
11+
12+
$BaseFileName = resolve $BaseFileName
13+
$ChangedFileName = resolve $ChangedFileName
14+
815
# Remove the readonly attribute because Word is unable to compare readonly
916
# files:
1017
$baseFile = Get-ChildItem $BaseFileName
@@ -17,16 +24,16 @@ $wdDoNotSaveChanges = 0
1724
$wdCompareTargetNew = 2
1825

1926
try {
20-
$word = New-Object -ComObject Word.Application
21-
$word.Visible = $true
22-
$document = $word.Documents.Open($BaseFileName, $false, $false)
23-
$document.Compare($ChangedFileName, [ref]"Comparison", [ref]$wdCompareTargetNew, [ref]$true, [ref]$true)
27+
$word = New-Object -ComObject Word.Application
28+
$word.Visible = $true
29+
$document = $word.Documents.Open($BaseFileName, $false, $false)
30+
$document.Compare($ChangedFileName, [ref]"Comparison", [ref]$wdCompareTargetNew, [ref]$true, [ref]$true)
2431

25-
$word.ActiveDocument.Saved = 1
32+
$word.ActiveDocument.Saved = 1
2633

27-
# Now close the document so only compare results window persists:
28-
$document.Close([ref]$wdDoNotSaveChanges)
34+
# Now close the document so only compare results window persists:
35+
$document.Close([ref]$wdDoNotSaveChanges)
2936
} catch {
30-
Add-Type -AssemblyName System.Windows.Forms
31-
[System.Windows.Forms.MessageBox]::Show($_.Exception)
37+
Add-Type -AssemblyName System.Windows.Forms
38+
[System.Windows.Forms.MessageBox]::Show($_.Exception)
3239
}

License.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
The MIT License (MIT)
22
=====================
33

4-
Copyright (C) 2013–2016 by F. von Never
4+
Copyright (C) 2013–2017 by F. von Never
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy of
77
this software and associated documentation files (the "Software"), to deal in

0 commit comments

Comments
 (0)