Created
January 13, 2020 15:23
-
-
Save nicksspirit/5540760022a3f303194fa9d4a5146b0d to your computer and use it in GitHub Desktop.
Hide files with a dot infront of them on windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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