Directory traversing file converter script?

Anton Rolls anton at
Sat Apr 19 05:50:03 UTC 2008

Hi David,

David Fletcher wrote:
> I've done a little bit of bash scripting, to do nightly and weekly backups of 
> a subversion server, and convert a directory of files from, say, png format 
> at the full resolution of my camera to jpg files for printing at the shop as 
> 8x6 inches @ 300dpi.
> What I would like now, is a script that works a little bit like rsync, in that 
> it can traverse a complete directory tree and detect new files, except that 
> I'd like to have it create a duplicate directory tree, with the files 
> converted to a different format.
> For example, two applications I would like to implement are:-
> 1) Rip my audio CDs to flac format and have the computer automatically 
> duplicate the flac directories, but with the files converted to ogg
> 2) Have selections of digital photographs in png format converted to jpg for a 
> digital photo frame, in a duplicated directory structure.
> Does anybody know of such a script that I could adapt/build upon?
> I have found one called flac2ogg but I don't know any python.
> Dave

This approach could work for you:

Your source *.flac files are assumed to be somewhere in the
ent/Music/ directory.

0.  Create 'mirror' directory and give it an old date.
     (Older than when you started adding your *.flac files.)

	mkdir mirror
	touch -d "2000-01-01" mirror

     (only need do this once)

1.  Create a script file 'flacs2oggs' which processes all your files.
     Original *.flac are in the 'ent/Music' directory, they must be
     newer than the 'mirror' directory. Format each line so it
     calls oggenc on your input file and saves the output in the
     mirror directory, with an extra '.ogg' filename extension.

	find ent/Music/ -iname "*.flac" -newer mirror -printf "oggenc -q 6 
\042%h/%f\042 -o \042mirror/%h/%f.ogg\042\n" > flacs2oggs

2.  Run the script.

	bash flacs2oggs

3.  Rename the "*.flac.ogg" files in the mirror directory to *.ogg
     files. (I leave this to you to figure out if needed.)

4.  Update the timestamp on the mirror directory.

	touch mirror

5.  Add more files to the ent/Music directory.

6.  ... and repeat from step 1 any time you want to update.

Good luck!


More information about the kubuntu-users mailing list