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
For a single directory:
remove-item C:\path\to\test-folder\* -include *.mp3, *.mpegor a useful method for when files span multiple directories:
remove-item C:\path\to\test-folder\*.mp3, C:\path\to\other\test-folder\*.mpegor you could move to that directory first:
cd C:\path\to\test-folder\
remove-item *.mp3, *.mpegUse Get-Help Remove-Item -full for full details of available flags and usage.
remove-item C:\path\to\test\folder\* -include .mp4,.mp3The above command needs to changed a little to work correctly (courtesy @root)
remove-item C:\path\to\test\folder\* -include *.mp4,*.mp3 3 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