Page 1 of 1
Recurse through directories and convert sound files
Posted: Tue Apr 28, 2009 6:17 pm
by larryh
I have a couple of thousand wave files that are neatly organized in folders and subfolders. I would like to create a Rev script that will recurse through each of the files and apply a shell command to it. I want to apply a LAME MP3 conversion to each file and output to the same directory structure (although with a different root - see below). Any pointers as to how to recurse through the directory structure and apply the command to each file?
Thanks!
Larry
Posted: Tue Apr 28, 2009 8:04 pm
by bn
larry,
are there subfolders of /soundfilesWAV/A/ ?
in other words do you know the structure of your folders? Are there only wav-files in these folders or other files also?
this example gives you the files of the subfolders one level deep with paths
Code: Select all
on mouseUp
answer folder "please choose the WAV folder"
if it is empty then exit mouseUp
put the defaultfolder into origDefaultFolder
put it into tWAVFolder
set the defaultfolder to tWAVFolder
put the folders into tWAVSubFolders
-- filter out operating system folders on mac (like "..", or starting with "." to make it invisible)
filter tWAVSubFolders without ".*"
-- filter without application folders, on the mac application may be packages that look like folders to Rev
filter tWAVSubFolders without "*.app"
put "" into tmyWAVListWithPath
repeat for each line aFolder in tWAVSubFolders
put tWAVFolder & "/" & aFolder & "/" into tActualFolder
set the defaultfolder to tActualFolder
put the files into tallFiles
-- filter for macStyle ".xyz" files
filter tallFiles without ".*"
if tallFiles <> "" then
repeat for each line aSingleFile in tallFiles
put tActualFolder & aSingleFile & return after tmyWAVListWithPath
end repeat
end if
end repeat
delete last char of tmyWAVListWithPath -- the last return
put tmyWAVListWithPath -- goes to the message box now, could go into a field
set the defaultfolder to origDefaultFolder -- be nice and restore the original defaultfolder
end mouseUp
regards
Bernd
Posted: Tue Apr 28, 2009 11:26 pm
by Mark Smith
The first thing I'd do is build a list of all the wav files. There are lots of 'directory walker' scripts about, but here's mine:
Code: Select all
function getAllFiles foName
put the defaultfolder into oldFolder
set the defaultfolder to foName
repeat for each line L in the files
if char 1 of L is "." then next repeat
put foName & "/" & L & cr after theFiles
end repeat
repeat for each line L in the folders
if char 1 of L is "." then next repeat
put getAllFiles(foName & "/" & L) & cr after theFiles
end repeat
filter theFiles without empty
set the defaultfolder to oldFolder
return theFiles
end getAllFiles
You'll also need to create the necessary directory structure in the target folder, so this command is useful
Code: Select all
on createPath pPath
set the itemDelimiter to "/"
repeat with n = 1 to the number of items in pPath - 1
if there is no folder (item 1 to n of pPath) then
create folder (item 1 to n of pPath)
end if
end repeat
end createPath
it's also useful for shell commands to have Ken Ray's "q" quoting function available:
Code: Select all
function q pString
return quote & pString & quote
end q
so a basic function for doing the work would be:
Code: Select all
on makeMp3s pSourceFolder, pTargetFolder
put getAllFiles(pSourceFolder) into tWavList
filter tWavList with "*.wav" -- remove all the non-wav files
repeat for each line tWav in tWavList
-- build the target file path
put tWav into tMp3
replace pSourceFolder with pTargetFolder in tMp3
replace ".wav" with ".mp3" in tMp3
createPath tMp3
get shell("flac" && q(tWav) && "-o" && q(tMp3))
end repeat
end makeMp3s
Best,
Mark Smith
Posted: Wed Apr 29, 2009 6:48 pm
by larryh
Thanks Mark and Bernd, very helpful!