4

I have tried to follow the advice here: Need to delete all the files with one extension on a drive in Windows 7

But if I want to delete all files in a specific folder, with a specific extension, that doesn't work.

I have a folder with *.ASP and *.ASPX files, and I need to delete all the *.ASP files but keep the ASPX pages.

I also need to delete a folder if it is empty, after deleting the file(s).

How would I delete all the ASP pages easily, including empty folders? Command prompt is no problem.

EDIT: This is the trick in PowerShell:

Get-ChildItem -path . -recurse -include *.asp | 
  Where-Object {-not $_.PSIsContainer} |
  Remove-Item -Verbose
1

2 Answers 2

5

To remove all files with a specific extension can be done with something like:

cd C:\ path\to\directory\extension
del /s *.extension

For removing empty folders I would suggest looking at a question from stackoverflow:

https://stackoverflow.com/questions/7831286/how-to-delete-empty-folders-using-windows-command-prompt

EDIT: Obviously I suggest caution running this sort of command on an entire drive. There might be something you need. So do be careful.

5
  • That doesn't delete it recursively, does it?
    – slhck
    Commented Feb 3, 2014 at 9:32
  • My apologies. /s will do that for you. You can also include /p for a prompt on each file if you really wish. Commented Feb 3, 2014 at 9:36
  • 2
    This removes both *.ASP and *.ASPX in my end :-) Commented Feb 3, 2014 at 9:41
  • Seems to be a problem with old DOS commands. Seems you can do something with PowerShell, but I don't have much knowledge of this. There appears to be a good answer from serverfault: serverfault.com/questions/42856/delete-just-asp-files Commented Feb 3, 2014 at 9:47
  • Works great. Use del /s /p *.extension if you want a prompt for confirmation for each file deletion. Commented Feb 10, 2015 at 20:56
0

Here's the way to do it with JP Software's TCC/LE:

del /s /x *.asp

The /s option causes recursion into subdirectories, and the /x option causes emptied directories to be removed.

TCC will not match short filenames with the *.asp wildcard. That sort of wildcard matching is a non-default feature that has to be turned on. The wildcard will just match long filenames, so the problem caused by *.aspx files happening to have *.asp short filenames will not occur.

Further reading

  • JP Software. DEL. Take Command / TCC Help.
  • JP Software. LFN Searches. Take Command / TCC Help.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .