Skip to content

Commit 652fd1f

Browse files
author
Markus Fleschutz
committed
Update check-xml-file.ps1 and check-xml-files.ps1
1 parent 203c9a8 commit 652fd1f

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

scripts/check-xml-file.ps1

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<#
22
.SYNOPSIS
3-
Verifies the given XML file
3+
Verifies an XML file
44
.DESCRIPTION
55
This PowerShell script checks the given XML file for validity.
66
.PARAMETER path
7-
Specifies the path to the XML file to check
7+
Specifies the path to the XML file
88
.EXAMPLE
99
PS> ./check-xml-file.ps1 myfile.xml
10-
✔️ Valid XML in 'myfile.xml'
10+
✔️ Valid XML in 📄myfile.xml
1111
.LINK
1212
https://github.com/fleschutz/PowerShell
1313
.NOTES
@@ -31,13 +31,11 @@ try {
3131
while ($Reader.Read()) { }
3232
$Reader.Close()
3333

34-
if ($script:ErrorCount -gt 0) {
35-
throw "Invalid XML in '$path'"
36-
}
34+
if ($script:ErrorCount -gt 0) { throw "Invalid XML" }
3735

38-
"✔️ Valid XML in '$path'"
36+
"✔️ Valid XML in 📄$path"
3937
exit 0 # success
4038
} catch {
41-
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
39+
"⚠️ $($Error[0]) in 📄$path"
4240
exit 1
4341
}

scripts/check-xml-files.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<#
22
.SYNOPSIS
3-
Checks XML files in a directory tree
3+
Checks all XML files in a directory tree
44
.DESCRIPTION
5-
This PowerShell script verifies each XML file in the given directory tree for validity.
5+
This PowerShell script verifies each XML file (with suffix .xml) in the given directory tree for validity.
66
.PARAMETER path
77
Specifies the path to the directory tree (current working dir by default)
88
.EXAMPLE
99
PS> ./check-xml-files.ps1 C:\Windows
1010
...
11-
✔️ Checked 3607 XML files within C:\Windows in 174 sec
11+
✔️ Checked 3387 XML files within 📂C:\Windows in 174 sec
1212
.LINK
1313
https://github.com/fleschutz/PowerShell
1414
.NOTES
@@ -21,17 +21,17 @@ try {
2121
$stopWatch = [system.diagnostics.stopwatch]::startNew()
2222

2323
$path = Resolve-Path "$path"
24-
[int]$count = 0
24+
[int]$numXmlFiles = 0
2525

26-
Write-Progress "Checking all *.xml files under $path..."
27-
Get-ChildItem -path "$path" -attributes !Directory -recurse -force | Where-Object { $_.Name -like "*.xml*" } | Foreach-Object {
26+
Write-Progress "Scanning all XML files within $path..."
27+
Get-ChildItem -path "$path" -attributes !Directory -recurse -force | Where-Object { $_.Name -like "*.xml" } | Foreach-Object {
2828
& $PSScriptRoot/check-xml-file.ps1 "$($_.FullName)"
29-
$count++
29+
$numXmlFiles++
3030
}
3131
Write-Progress -completed "Done."
3232

3333
[int]$elapsed = $stopWatch.Elapsed.TotalSeconds
34-
"✔️ Checked $count XML files within $path in $elapsed sec"
34+
"✔️ Checked $numXmlFiles XML files within 📂$path in $elapsed sec"
3535
exit 0 # success
3636
} catch {
3737
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

0 commit comments

Comments
 (0)