A quick way to delete all files with a certain name pattern in Windows

This article introduces a simple way to list and delete all files with a certain name pattern in a folder and all its sub-folders. A common scenario is deleting the hidden thumbs.db files which Windows XP (and in some cases, Windows 7) stores in each folder that contains pictures or video files.

Using Command Prompt

  1. Open Command Prompt. You’ll find it in Start Menu, Accessories folder.
  2. Set the active volume to the one on which your intended files reside. To do so, type the volume letter followed by a colon sign (:) and press Enter key.

    For example:
    C:

  3. Navigate to the folder which you believe to have the files which have the same pattern of name. To so, type cd “folder address, (where folder addressis the address of the folder to which you’d like to navigate,) and press ENTER key.

    For example:
    cd "C:\Documents and Settings\test\My Documents"

  4. (Optional) Get a list of all the files which have the same name pattern. This will give you a chance to verify what is deleted before actually deleting them. To do so, type: dir filename.ext /a /b /s (where filename.extis the name of the files which you’d like to find; wildcards are also acceptable.)

    For example:
    dir thumbs.db /a /b /s

  5. Delete those files. Type del filename.ext /a /s (where filename.extis the name of the files which you’d like to delete; wildcards are also acceptable.)

    For example:
    del thumbs.db /a /s

NOTE: You cannot delete a group of files across more than one volume with only one command. You must repeat this command for each drive.

Using Windows PowerShell

  1. Start Windows PowerShell. You’ll find it in Start Menu.
  2. Navigate to the folder which you believe to have the files which have the same pattern of name. To so, type Set-Location ‘folder address, (where folder addressis the address of the folder to which you’d like to navigate,) and press
    ENTER key.

    For example:
    Set-Location 'C:\Documents and Settings\test\My Documents'

  3. (Optional) Get a list of all the files which have the same name pattern. This will give you a chance to verify what is deleted before actually deleting them. To do so, type: Get-ChildItem -include filename.ext -recurse -force (where filename.extis the name of the files which you’d like to find; wildcards are also acceptable.)

    For example:
    Get-ChildItem -include thumbs.db -recurse -force

  4. Delete those files. Type Get-ChildItem -include filename.ext -recurse -force | Remove-Item -force (where filename.extis the name of the files which you’d like to delete; wildcards are also acceptable.)

    For example:
    Get-ChildItem -include thumbs.db -recurse -force | Remove-Item -force

NOTE: You cannot delete a group of files across more than one volume with only one command. You must repeat this command for each drive.

Advertisements

Posted on 2 June 2010, in Windows Administration and tagged , , , , , . Bookmark the permalink. 1 Comment.

  1. Nice! I’m been using Win 7 Ultimate and have been having problems with Thums.db for quite some time. Thanks!

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: