16

I have a folder called "test-folder" which contains alot of files with different types. I want to delete all music files. (mp3, mp4, mpeg ...)

I know i can delete all mp3 files like this:

remove-item C:\path\to\test-folder\"*.mp3*"

Is it possible to add multiple wildcard selectors e.g.:

remove-item C:\path\to\test-folder\"*.mp3*+*.mpeg*"

so i can delete all the music files with one command?

3 Answers 3

18

For a single directory:

remove-item C:\path\to\test-folder\* -include *.mp3, *.mpeg

or a useful method for when files span multiple directories:

remove-item C:\path\to\test-folder\*.mp3, C:\path\to\other\test-folder\*.mpeg

or you could move to that directory first:

cd C:\path\to\test-folder\
remove-item *.mp3, *.mpeg

Use Get-Help Remove-Item -full for full details of available flags and usage.

1
  • 1
    Thanks for the info about Get-Help.
    – Black
    Feb 24, 2016 at 19:50
0
remove-item C:\path\to\test\folder\* -include .mp4,.mp3

The above command needs to changed a little to work correctly (courtesy @root)

remove-item C:\path\to\test\folder\* -include *.mp4,*.mp3
3
  • Close, but I believe you would need the wildcard in front of the extensions.
    – root
    Feb 24, 2016 at 19:19
  • Well to be honest I cannot test this right now so I am not going to doubt you but I would also like to point out that I think the one wildcard character that I already have in the path would do the trick, again you might be totally correct.
    – Jay T.
    Feb 24, 2016 at 19:22
  • It actually needs both - the asterisk at the end of the file path and at the beginning of each extension delimiter.
    – root
    Feb 24, 2016 at 19:25
0

For the opposite case, I want to remove all of the ArtWork, db, Zune, desktop files from the Music folders. We need to use -Recurse for network drive NAS1:

\\NAS1\Public> remove-item '.\Shared Music\*' -include desktop.ini,_msl.db,Zune*.jpg,Folder.jpg,AlbumArt*.jpg -Recurse

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.