I was wondering if anyone knew how to delete a directory if it has a specified file in it? For example, if have this directory:
PS C:\Users\mike> dir
Directory: C:\Users\mike
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 9/17/2009 6:26 PM 6615 pic001.jpg
-a--- 9/19/2009 9:58 AM 7527 notes.txt
-a--- 8/31/2009 5:03 PM 10506 Project.xlsx
I would like to delete .\mike if it has a jpg file in it, and any other directory that has .jpg files. If a directory does not have the file specified it should not be deleted.
So far what I have is this:
get-childitem "C:\Users\mike" -include *.jpg -recurse | Where-Object { $_.mode -like 'd*' } | remove-item