List or delete hidden files from command prompt(CMD)

by admin on September 2, 2010

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

Example:

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

Example:
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

{ 12 comments… read them below or add one }

diego December 30, 2011 at 10:21 am

is it possible to remove a list of hidden folders? for example, i want to remove all hidden folders and their content..

Reply

admin December 30, 2011 at 11:47 am

If you have the list of hidden folders, then you can delete them all by the following command.
rmdir /s /q hiddenfolder1 hiddenfolder2 hiddenfolder3 .....

If you want to delete all hidden subfolders from a drive/folder then you first need to generate the list of folders and then delete them. This can be done with the below command.
for /F %i in ('dir /s /b /A:DH') do rmdir /s /q %i

Run the above command from the drive or top folder.
Disclaimer: Be cautious while using these commands, as any mistake would lead to data loss. Test and use them at your own risk.

tayyab hafeez February 21, 2012 at 2:19 pm

i wish to show all hidden files on GUI .. i get my hidden files on command prompt … tell me how these files show on GUI(my computer) … tools —- folder option—- view — show hidden file but its not working :(

Reply

Jithin February 23, 2012 at 5:03 pm

to show the hidden files at GUI follow this code in cmd
attrib -s -h path to the file
press enter
its done lol

junaid April 4, 2012 at 8:24 am

thank u.. it was helpfull..

Reply

amit kulat January 16, 2013 at 5:53 pm

you should add more to your blog..ex: how to hide using cmd,how to unlock..etc…by the way your blog is cool keep updating

Reply

tt March 7, 2013 at 7:36 am

how to show hidden files /corrupted files using windows commands

Reply

John December 31, 2013 at 3:04 pm

Is it possible to delete list of hidden folders with wildcards?

Reply

admin January 1, 2014 at 2:11 pm

You can using for and dir commands. Use dir command to generate the hidden folders and then for to iterate over the list and then delete. You can refer my answer to Diego above. The only change you would need is to specify the wild card in the dir command. For example, to delete the folders starting with letter ‘a’ then the command would be :
for /F %i in ('dir /s /b /A:DH a*') do rmdir /s /q %i

Rahul September 9, 2014 at 7:04 am

How to delete read only ,system and hidden files in a go using del command.

I know it is possible using batch script , but I would like to do it using single command by combining the attributes like /A:HSR.

Reply

admin February 24, 2012 at 6:25 am

But this command would make the files unhidden. Tayyab’s question was to keep the files marked as hidden but show them in GUI.

Reply

admin February 24, 2012 at 6:27 am

Also if you don’t know what hidden files you have in a folder, then also this command does not help.

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: