search
top

How To Manage Hidden files and Directories from the command line in Windows

How To Manage Hidden files and Directories from the command line in Windows

Introduction

Managing Windows hidden files and directories from the GUI is easy, managing from the command line is a bit more challenging, but not difficult. in this post we will cover the different ways to handle many different tasks using the command line.

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 post explains how to list this hidden files in windows command line and it also discusses how to delete the hidden files.

command_prompt

Example 1 – Get a List of Hidden Files

To get the list of hidden files from a directory you can run the below command.

C:\>dir directory_path /A:H /B

The switch /A:H tells the dir command to show the hidden attributes and /B Uses bare format (no heading information or summary).

Example:

Get the list of hidden files from C:\Windows\system32 folder.

C:\>dir c:\WINDOWS\system32 /A:H /B
7B296FB0-376B-497e-B012-9C450E1B7327-5P-0.C7483456-A289-439d-8115-601632D005A0
7B296FB0-376B-497e-B012-9C450E1B7327-5P-1.C7483456-A289-439d-8115-601632D005A0
api-ms-win-core-console-l1-1-0.dll
api-ms-win-core-datetime-l1-1-0.dll
api-ms-win-core-debug-l1-1-0.dll
api-ms-win-core-delayload-l1-1-0.dll
api-ms-win-core-errorhandling-l1-1-0.dll
api-ms-win-core-fibers-l1-1-0.dll
api-ms-win-core-file-l1-1-0.dll
api-ms-win-core-handle-l1-1-0.dll
api-ms-win-core-heap-l1-1-0.dll
api-ms-win-core-interlocked-l1-1-0.dll
api-ms-win-core-io-l1-1-0.dll
api-ms-win-core-libraryloader-l1-1-0.dll
api-ms-win-core-localization-l1-1-0.dll
api-ms-win-core-localregistry-l1-1-0.dll
api-ms-win-core-memory-l1-1-0.dll
api-ms-win-core-misc-l1-1-0.dll
api-ms-win-core-namedpipe-l1-1-0.dll
api-ms-win-core-processenvironment-l1-1-0.dll
api-ms-win-core-processthreads-l1-1-0.dll
api-ms-win-core-profile-l1-1-0.dll
api-ms-win-core-rtlsupport-l1-1-0.dll
api-ms-win-core-string-l1-1-0.dll
api-ms-win-core-synch-l1-1-0.dll
api-ms-win-core-sysinfo-l1-1-0.dll
api-ms-win-core-threadpool-l1-1-0.dll
api-ms-win-core-ums-l1-1-0.dll
api-ms-win-core-util-l1-1-0.dll
api-ms-win-core-xstate-l1-1-0.dll
api-ms-win-downlevel-advapi32-l1-1-0.dll
api-ms-win-downlevel-advapi32-l2-1-0.dll
api-ms-win-downlevel-normaliz-l1-1-0.dll
api-ms-win-downlevel-ole32-l1-1-0.dll
api-ms-win-downlevel-shell32-l1-1-0.dll
api-ms-win-downlevel-shlwapi-l1-1-0.dll
api-ms-win-downlevel-shlwapi-l2-1-0.dll
api-ms-win-downlevel-user32-l1-1-0.dll
api-ms-win-downlevel-version-l1-1-0.dll
api-ms-win-security-base-l1-1-0.dll
api-ms-win-security-lsalookup-l1-1-0.dll
api-ms-win-security-sddl-l1-1-0.dll
api-ms-win-service-core-l1-1-0.dll
api-ms-win-service-management-l1-1-0.dll
api-ms-win-service-management-l2-1-0.dll
api-ms-win-service-winsvc-l1-1-0.dll
ceipdata.xml
ceiprole.xml
ceiproleusage.xml
GroupPolicy

To get the list of hidden files from all sub directories we need to add /S switch to the command.

C:\> 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

Example 2 – Deleting Hidden Files

To delete hidden files from command prompt we can use Del command. For example to delete a hidden file named deleteme.doc we need to run the below command.

del /A:H deleteme.doc

Note that /A:H is necessary otherwise you will get ‘file not found’ error like below. This exposes that the file is hidden.

C:\>del deleteme.doc

Could Not Find C:\deleteme.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.

C:\>del * /A:H

To delete hidden files from subfolders also you can do that by adding /S switch

C:\>del * /A:H /S

Conclusion

Now we know how to find and delete hidden files from the command line using dir and del commands. With this knowledge we can now use them to create scripts and do many other tasks!

Leave a Reply

Your email address will not be published. Required fields are marked *

top