CodeSteps

Python, C, C++, C#, PowerShell, Android, Visual C++, Java ...

Windows – DEL command – How to delete files based on attributes?

Windows maintains file attributes to manage the files in the File System. DEL command allows us to delete the files based on the file attributes. Through this Article we will discuss about deleting the files based on file attributes.

DEL command provides “/A” switch to allow to select the files to be deleted based on the file attributes. Along with this switch you need to pass below parameters too to represent the specific file attribute.

  • R – Represents read-only files
  • S – System files
  • H – Hidden files
  • A – Files ready for Archiving

Let’s put these together to delete the files based on file attributes.

Delete the read-only files

If you try to delete the read-only files, System with throw the below message.

Access is denied.

Either you need to forcibly delete the file or you need to delete the file by selecting it’s read-only attribute. Here is the command to delete all the read-only files.

C:\>del . /ar
C:\*, Are you sure (Y/N)?

Observe that, System will prompt for the confirmation before deleting the read-only files.

If you know the file is read-only, you can use this attribute directly and System will delete the file without prompt for the confirmation. For example, assuming “sample.txt” is the read-only file and below command will delete the file without prompting.

C:\> del sample.txt /ar

Delete the hidden files, system files etc,.

Similarly, you can delete the hidden files by using below command.

C:\> del . /ah

You can use below command to delete System files. Be cautious when you delete the system files. Accidental deleting of system files will cause system failure.

C:\> del . /as

And you can delete the files ready for archiving by using below command.

C:\> del . /aa

Be on learning path always!

// Malin

Windows – DEL command – How to delete files based on attributes?

2 thoughts on “Windows – DEL command – How to delete files based on attributes?

  1. /A switch is used to select the files to delete based on attributes. You can add multiple attributes after the switch. Prefix with – meaning exclude the specific attribute.

    For example, below command will delete the file(s) with read-only & hidden attributes but not the system file(s).

    del . /a:rh-s

  2. I wanted to know how to string several attributes after the /A switch.
    I also need to know hwo to PREVENT teh command from seleting System and Parse-Point files.
    Something like,
    del /A:-s-l
    But what is the syntax for the stirng of attributes?

Leave a Reply

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

Scroll to top