Reputation: 169
I mistakenly turned C:\Users\User into a hidden folder. Now, a lot of my programs aren't running. I can't even open file explorer. I managed to open powershell in admin mode, but am able to see the hidden folders using ls - Force. However, I don't know how to unhide them. How to I remove the the hidden attribute so that the mode of the folders change from d--h-- to d-----?
Upvotes: 4
Views: 9787
Reputation: 437513
Mathias R. Jessen's helpful answer shows how to use PowerShell-native commands to solve your problem, but on occasion it is easier to call an external program to do a simple job, which is the standard attrib.exe
utility in this case:
# Remove (-) the hidden (h) attribute from the specified dir.
attrib -h C:\Users\User
Note: Hypothetically speaking, if the target file or directory also has the system (s
) attribute set - which you shouldn't modify yourself, and it is similarly ill-advised to change the hidden status of true system files - you would need attrib -s -h ...
in order to turn off the hidden attribute (you could then restore the system attribute with attrib +s ...
).
Upvotes: 5
Reputation: 174485
As Lee_Dailey points out, you can edit the Attributes
property value on the corresponding DirectoryInfo
object.
Since Attributes
is a Flags
enum (or a bit field if you will), the easiest way to remove a flag is to use bitwise operators:
$folder = Get-Item C:\Users\User -Force
$folder.Attributes = $folder.Attributes -band -bnot [System.IO.FileAttributes]::Hidden
This will set the value of Attributes
to whatever it already is, but excluding the Hidden
flag regardless of whether it was set or not
Upvotes: 9