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?

Leave a Reply

Your email address will not be published.

Scroll to top