0

I want to delete all files from my "music" folder that aren't .mp3, .mp4 or .m4a.

This is the folder structure:

H:/Music/Artist/Album/Files

There are pictures like Folder.jpg, playlist files, .txts and etc in those folders.

I'm running Windows 8.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
thomi
  • 3
  • 4
  • Does this http://stackoverflow.com/questions/5193282/delete-files-that-match-regex help? and this one http://stackoverflow.com/questions/14440692/windows-scripting-list-files-not-matching-a-pattern – Vishnuprasad R Aug 02 '13 at 20:42
  • 1
    Or this one: http://stackoverflow.com/questions/9424380/delete-excluding-some-extensions – Andriy M Aug 02 '13 at 22:13
  • Please be more specific which step you are having trouble with. Is it the "find all the files" part or the "is it a music file?" part or is it the "delete the file" part? – Raymond Chen Aug 25 '15 at 14:54

3 Answers3

2

set up an array with do-not-delete-extensions and compare all files with it:

@ECHO OFF &SETLOCAL
SET "startfolder=H:/Music/Artist/Album/Files"
FOR %%a IN (
    .mp2
    .mp3
    .mp4
    .m4a
    .wav
    .flac
    .ac3
    .dts
    ) DO (
    SET "$%%a=1"
)
FOR /r "%startfolder%" %%a IN (*) DO IF NOT DEFINED $%%~xa ECHO DEL "%%~fa"

Please note: files without extension will be deleted.

Endoro
  • 37,015
  • 8
  • 50
  • 63
0

You could try:

  1. MKDIR to create a temp sub-folder
  2. MOVE all music files (*.mp?, *.m4a, *.wav, ...) to that folder.
  3. DELete all remaining files
  4. MOVE the music files back.
  5. RMDIR the temp sub-folder.
Lee Meador
  • 12,829
  • 2
  • 36
  • 42
-1

If this is a "one time task", use windows explorer (sort for "type"). This will be much faster (and safer) than writing and testing a batch for it.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Problem is I have over 100 artists subfolders and more subfolders in there. But you have me an idea: I searched for "*.*" in the folder, sorted by type and deleted everything I didn't want. – thomi Aug 02 '13 at 21:39
  • -1. "Use Windows Explorer" is not a suitable answer to a programming question. This is at best a comment to the original question. It is not an answer. – Ken White Aug 03 '13 at 06:56