• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » How To? » Delete Files Based on Extension, Attribute in Folders & Subfolders

Delete Files Based on Extension, Attribute in Folders & Subfolders

Posted on May 30, 2012 by Renji | Short URL: http://sumtips.com/?p=6751

In this post, I will show how you can easily delete unwanted files within a folder or subfolders based on its extension and attribute. You can even automate this process with Task Scheduler for regular cleaning up.

Before starting, do note that files deleted from command line are permanently deleted, which means deleted files are not stored in Recycle Bin.

Delete Specific File Type from a Folder and its Subfolders

DEL "C:\Folder\*.exe" /S /Q

Windows Command Prompt
This command will delete all EXE (executable) files within the specified directory and its sub directories. /S parameters checks inside subdirectories, and /Q deletes files silently without prompting.

Delete All Files Inside a Folder and Subfolders

DEL "C:\Folder\*.*" /S /Q

This command is useful if you want to delete all files within a directory and its subdirectories. File extension is not checked here.

Delete Files Based on Attribute

Suppose you want to delete files that are having a specific attribute, you can do that with this command:

DEL "C:\Folder\*.*" /S /Q /A:R

This delete all files having Read-Only attribute.

Windows attributes list:

  • R: Read-only files
  • S: System files
  • H: Hidden files
  • A: Files ready for archiving
  • I: Not content indexed files
  • L: Reparse Points

Delete Files that does not have a Specific Attribute

DEL "c:\MyFolder\*.*" /S /Q /A:-S

With this command you can exclude files having a specific attribute. This can be handy, for example, if you don’t want to delete files with System attribute.

Delete All Sub Folders and its content

for /D %%X in ("C:\Folder\*") do RD /S /Q "%%X"

This is a quick command that will recursively delete all subdirectories.

Automate Deletion

Using Windows task scheduler, you can schedule any of the above deletion command to run as frequently as you like.

CMD.EXE /C "DEL C:\Folder\*.exe"

That’s all! No need to use third-party tools for simple tasks as this.


Tweet

Related posts:

  • CSS Attribute Selectors
  • Add “Take Ownership” to Files, Folders & Drives Context Menu
  • Automatically Unhide Files & Restore Shortcuts On Virus Infected PCs
  • How To Make A File Read-Only In Windows
  • Drag & Drop Files/Folders to Compress, Move and More on Windows
Categories: How To?, Tips 'n Tricks | Tags: Command Prompt, Delete, Windows
Snap a Window to Top or Bottom of the Screen
Resize a Program Window to Custom Dimensions using AutoHotkey

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Re-Enable Windows Functions Disabled by Viruses
    • Add Google+ Search to Chrome
    • Display Simple Maintenance Mode Message to Non-Admins
    • Create Presentations Online with SlideRocket
    • Get The New Facebook Profile Now
    • Follow Your World: Know When Google Earth Updates in Your Area
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy