Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove hidden attribute of a folder in windows?

Tags:

powershell

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-----?

like image 467
Brain Stroke Patient Avatar asked Aug 31 '25 04:08

Brain Stroke Patient


1 Answers

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

like image 105
Mathias R. Jessen Avatar answered Sep 02 '25 22:09

Mathias R. Jessen