57 lines
1.1 KiB
PowerShell
57 lines
1.1 KiB
PowerShell
|
function Test-FileTab {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Returns false if tab char is used in file.
|
||
|
|
||
|
.DESCRIPTION
|
||
|
Test the given file if tabs are used. Returns false if any tabs were found.
|
||
|
|
||
|
.PARAMETER Path
|
||
|
elative or full path to an existing file.
|
||
|
|
||
|
.INPUTS
|
||
|
[none]
|
||
|
|
||
|
.OUTPUTS
|
||
|
[bool]
|
||
|
|
||
|
.EXAMPLE
|
||
|
Test-FileTab -Path './testfile.txt'
|
||
|
|
||
|
.NOTES
|
||
|
#>
|
||
|
|
||
|
[CmdletBinding()]
|
||
|
[OutputType([bool])]
|
||
|
|
||
|
param (
|
||
|
[Parameter(Mandatory = $true)]
|
||
|
[ValidateScript(
|
||
|
{
|
||
|
Test-Path -Path $_
|
||
|
}
|
||
|
)]
|
||
|
[string]$Path
|
||
|
)
|
||
|
|
||
|
begin {
|
||
|
}
|
||
|
|
||
|
process {
|
||
|
$content = Get-Content -Path $Path -Raw -Encoding 'utf8'
|
||
|
$Tabs = ([regex]::Matches($content, "`t")).Count
|
||
|
|
||
|
if ($Tabs -ne 0 ) {
|
||
|
Write-Debug -Message ('Tabs: {0} -> false' -f $Tabs)
|
||
|
Write-Output $false
|
||
|
}
|
||
|
else {
|
||
|
Write-Debug -Message ('Tabs: {0} -> true' -f $Tabs)
|
||
|
Write-Output $true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
end {
|
||
|
}
|
||
|
}
|