Skip to content

Instantly share code, notes, and snippets.

@nicksspirit
Created January 13, 2020 15:23
Show Gist options
  • Save nicksspirit/5540760022a3f303194fa9d4a5146b0d to your computer and use it in GitHub Desktop.
Save nicksspirit/5540760022a3f303194fa9d4a5146b0d to your computer and use it in GitHub Desktop.
Hide files with a dot infront of them on windows
function Hide-Dots {
Param(
[Parameter(Position=0)]
[ValidateScript({ Test-Path $_ })]
[string] $path="."
)
if ($path -eq ".") {
$cwd = (Get-Location).Path.Substring((Get-Location).Path.LastIndexOf("\") + 1)
echo "Searching for files in $($cwd) ..."
}
else {
echo "Searching for files in $($path) ..."
}
$Activity = "Hidding Dot Files."
$isDotFile = {$_.name -match "^\..*"}
$isNotHidden = {$_.attributes -match 'Hidden' -eq $false}
$dotFileCount = 0
$markedCount = 0
ll $path -Recurse -Force -ErrorAction SilentlyContinue |
where $isDotFile |
where $isNotHidden |
foreach {
$path = $_.FullName
$dotFileCount++
Write-Progress `
-Activity $Activity `
-Status "Found $($dotFileCount) dot files."
if (Test-Path $path) {
$_.Attributes = "Hidden"
$markedCount++
}
}
echo "Marked $($markedCount) dot file(s) as hidden."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment