From owner-freebsd-questions@FreeBSD.ORG Mon May 9 02:38:01 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1359A106566B for ; Mon, 9 May 2011 02:38:01 +0000 (UTC) (envelope-from chris@monochrome.org) Received: from mail.monochrome.org (b4.ebbed1.client.atlantech.net [209.190.235.180]) by mx1.freebsd.org (Postfix) with ESMTP id B4D1F8FC17 for ; Mon, 9 May 2011 02:38:00 +0000 (UTC) Received: from [192.168.1.11] ([192.168.1.11]) by mail.monochrome.org (8.14.3/8.14.3) with ESMTP id p492bxrg069917; Sun, 8 May 2011 22:37:59 -0400 (EDT) (envelope-from chris@monochrome.org) Date: Sun, 8 May 2011 22:37:59 -0400 (EDT) From: Chris Hill To: Antonio Olivares In-Reply-To: Message-ID: References: User-Agent: Alpine 2.00 (BSF 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: FreeBSD Questions Subject: Re: fix an audio conversion script to work through multiple directories and convert mp3s to ogg vorbis X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 May 2011 02:38:01 -0000 On Sun, 8 May 2011, Antonio Olivares wrote: > On Sat, May 7, 2011 at 4:03 PM, Chris Hill wrote: >> On Sat, 7 May 2011, Antonio Olivares wrote: >> >>> My question is the following: >>> How can I run the script to recursively find all mp3's and convert >>> them to ogg vorbis(with ogg extension already in place/or rename them >>> in one step[instead of running two scripts] and deleting the mp3's) >>> all in one time? >> >> I had a similar (but not identical) problem [ snip ] >> My script is at http://pastebin.com/77NRE6SZ - maybe you can adapt it >> to your needs. > Thank you for your suggestion. But I have gotten into a problem I get > errors and too many directories :(, Directories with spaces get > recreated and no ogg files are created :( If your directory and/or file names have spaces, you will have to quote the filenames somehow: 'file name' vs. file_name. Maybe you could escape the spaces? None of my names have spaces, for exactly this reason. [ Script mostly snipped ] > ===================================================== > #!/bin/sh > # From Steve Parker, only slightly modified: [ snip ] > traverse() > { > # Traverse a directory > > ls "$1" | while read i > do > if [ -d "$1/$i" ]; then > THISDIR=$1/$i > # Calling this as a subshell means that when the called > # function changes directory, it will not affect our > # current working directory > > if [ -d $OGGROOT/$THISDIR ]; then > # directory exists, leave it be > echo "$OGGROOT/$THISDIR already exists, not created." > else > mkdir $OGGROOT/$THISDIR > echo "Copying $THISDIR to $OGGROOT/$THISDIR" > fi > > traverse "$1/$i" `expr $2 + 1` > else [ snip ] > fi > done > } > > traverse . 0 > ===================================================== > > I have modified to above script. I don't get how the directory > structure is copied? I don't see a cp -r from_directory/ to > _directory/ then mplayer -ao .... There is no cp -R. What this is doing is replicating the directory structure, then copying each file. I missed it too, the first several times I looked at it. Almost the entire script is the definition of the traverse() function, which is called in the last line. The function then calls itself whenever it finds a directory, which makes it recurse. I thought it was pretty clever; wish I'd thought of it. [ snip ] > Thanks for helping. I am experimenting and trying not to shoot myself > in the foot. So was I; that's the main reason why there are all those `echo "something"` lines - I wanted to see what it would try to do, before actually turning it loose on my files. That and the fact that doing all the conversions takes a few hours. Good luck. -- Chris Hill chris@monochrome.org ** [ Busy Expunging ]