In Windows, files/folders have a special attribute called hidden attribute. By setting this attribute, we can hide files from being displayed in explorer or command prompt. This articles explains how to list this hidden files in windows command line and it also discusses how to delete the hidden files.
To get the list of hidden files from a directory you can run the below command.
dir directory_path /A:H /B
Get the list of hidden files from C:\Windows\system32 folder.
C:\>dir c:\WINDOWS\system32 /A:H /B cdplayer.exe.manifest dllcache GroupPolicy logonui.exe.manifest ncpa.cpl.manifest nwc.cpl.manifest sapi.cpl.manifest WindowsLogon.manifest wuaucpl.cpl.manifest
To get the list of hidden files from all sub directories we need to add /S switch to the command.
dir directory_path /A:H /S /B
To get the list of hidden files from the folder c:\windows\system32 and from all its subfolders we need to run the below command.
dir c:\WINDOWS\system32 /A:H /B /S
List all hidden folders:
If you want to get the list of all hidden subfolders in a folder, you can run the below command.
dir /s /b /A:DH
Hidden files deletion
To delete hidden files from command prompt we can use Del command. For example to delete a hidden file named example.doc we need to run the below command.
del /A:H example.doc
Note that /A:H is necessary otherwise you will get ‘file not found’ error like below.
C:\>del example.doc Could Not Find C:\example.doc
To delete all hidden files from a given directory we can run the below command.
del directory_path /A:H
Alternatively you can cd to that directory and then run the below command.
del * /A:H
To delete hidden files from subfolders also you can do that by adding /S switch
del * /A:H /S