Getting an XML File List from K3b Project Files

Suppose you've been backing up your hard drive to discs using K3b. Suppose you've been saving off each disc as a K3b project, and writing just the project name on the disc. Now suppose you want to get at the list of files in each of those projects (so you can eventually create a complete index for all those discs). You'd be just like me today ;-).

Luckily for you K3b project files are just zip-compressed archives with a couple xml files in there. One file is called maindata.xml, it has an xml representation of the directory structure of the disc with all the filenames along with some other stuff I'm not interested in today. I wanted an easy bash script to get the maindata.xml file out of each project and save it with the name of the K3b project (minus the extension).

What worked for me was this:

for f in *.k3b ; do unzip -p -- "${f}" maindata.xml > "${f%.*}.xml" ; done ;

I just ran this in the directory with all my .k3b files in it and it pulled all the xml files out. Next step might be some simple PHP to pull just filenames out.
(update: I added some more quotes & braces for filenames with spaces)

Your rating: None Average: 4 (8 votes)