Finding and moving corrupt FLACs in Windows

A few months ago I received the following email from Ron Lyster, a long time bliss user:

A couple months ago, while I was out of town, my music server suffered a crash. I found a program to recover the lost files, and had a backup set as well, but it seems that there are quite a few files that remain corrupted. Do you know of any products that can search for corrupt FLAC files and then delete or move them elsewhere?

Let's break the problem down: first we need to identify the corrupt files. If we can store the filenames in a file, we can then use that list of files to perform further work, such as deleting them, or moving them elsewhere.

The good news is that FLACs have a corruption detection mechanism built in. By using either the FLAC command line or FLAC Frontend you can detect corrupt files from a list of FLACs.

Using the flac command line it's easy to redirect the output into a file. If you follow the Windows GUI way, however, you need a way of redirecting the output into a file. You can either copy and paste the output from the Command Prompt window, or grasp the nettle and use the flac command line after all! But if you must use FLAC Frontend...

The command prompt box that opens listing all the files can be copy/pasted. You click the "C:\" icon at the top left of the window, got to Edit > Mark. This allows you to draw a rectangle to copy the text. Press enter and the text is copied. You'll have to drag the rectangle down the screen allowing it to scroll with this many files. You may also need to set the output buffer to something large to make sure all files are reported.

Then paste this list into a text file, to at least give you something to work against. A proper text editor like EditPlus is best for this, as it will then allow you to filter out the bad files from good (this isn't a problem on the command line, because only the bad files are reported).

Another option, that Ron ended up using, is to use audiotester (scroll down the page). It's a simple app for looking for corrupt audio files.

Once you have a list of files, you want something like this:

C:\Users\Dan\Music\John_Tavener\Song_for_Athene\17-Solfeggio.flac
C:\Users\Dan\Music\Zero_7-Simple_Things\09-Out_of_Town.mp3

Let's say that list is stored in C:\Users\Dan\Desktop\FLAC_corrupt.txt.

You now need to write a Windows batch script to iterate through the list and move the files. Let's start with a test:

set FILELIST=C:\Users\Dan\Desktop\FLAC_corrupt.txt
for /f "tokens=*" %%a in (%filelist%) do echo "%%a"

That should echo (print out) each line in the file. If the script is inside a batch file, you need to double the %s for %%a as above. If you type this in a command prompt, just use one %.

Once you're happy, you can perform the move. Ron reported back to me to say that this final script worked:

set FILELIST=C:\Users\Dan\Desktop\FLAC_corrupt.txt
set DESTPATH=F:\Corrupt_Files
for /f "tokens=*" %%a in (%filelist%) do move "%%a" "%destpath%\"

Hope this helps!

Thanks to karlhols for the image above.
tags: mailbag
blog comments powered by Disqus

The Music Library Management blog

Dan Gravell

I'm Dan, the founder and programmer of bliss. I write bliss to solve my own problems with my digital music collection.