Hide dotfiles in Windows
Solution 1
After some problems (the attrib command doesn't allow some wildcards) I came up with this line:
@for %%X in (.*.*) do attrib +h %%X
Just put it a Batch File (.bat) and it does the trick (for that directory).
If you want this for a few directies, just set it to run once a day on that directories.
Hope this is what you need.
Solution 2
Using Powershell save the following in a script file (e.g. hidedotfiles.ps1) and run it whenever you wan't to hide dot files.
Of course the following one-liner can be simplified by using aliases and "-f for "-force" and "-r" for "-recurse" but to be instructive I have written it out in full form:
Get-ChildItem "C:\" -recurse -force | Where-Object {$_.name -like ".*" -and $_.attributes -match 'Hidden' -eq $false} | Set-ItemProperty -name Attributes -value ([System.IO.FileAttributes]::Hidden)
Basically Get-ChildItem -recurse -force gets all the items and searches recursevly in all folders forcing hidden items to show up. Then we search for files and folders that start with the dot and select only the files that have a hidden attribute. After we have listed all the files we set their attributes to hidden by using Set-ItemProperty.
Solution 3
To hide all dot file/directories on a disk (rather than in a single directory), I find this answer works best:
ATTRIB +H /s /d C:\.*
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on September 17, 2022Comments
-
Admin almost 2 years
Is there a way to have Windows automatically hide any file that is dot prefixed (e.g. ".svn"), as it's done in Linux?
-
Brian B almost 12 yearsIf you want to do directories, add a second line
@for /d %%X in (.*.*) do attrib +h %%X
-
Sergio Abreu over 7 yearsYou can run that directly from cmd, just cd to parent folder you want and then run without double percents, just one: >@for /D %X in (.*) do attrib +h %X
-
roberto tomás about 7 yearsbest answer I've found
-
emptyother over 4 yearsBoth
Where-Object
andSet-ItemProperty
is unecessary. It can just as well be done likeGet-ChildItem ".*" -Recurse -Force | ForEach-Object { $_.Attributes += "Hidden" }
.