thomi
thomi

Reputation: 3

Batch to delete all files that are not music files

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.

Upvotes: 0

Views: 1957

Answers (3)

Endoro
Endoro

Reputation: 37569

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.

Upvotes: 2

Lee Meador
Lee Meador

Reputation: 12985

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.

Upvotes: 0

Stephan
Stephan

Reputation: 56180

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.

Upvotes: -1

Related Questions