Page 1 of 1

return list of only mp3 files

Posted: Fri Feb 05, 2010 6:35 pm
by reelstuff
I was looking at some file examples, which works very nicely however, I wanted to only return
a specific files such as an MP3 file and ignoring all other files in the folder.

any thoughts or suggestions, would be greatly appreciated,

I tried a couple of different settings, but just keep getting all the files in the folder,

when you execute the following,

Code: Select all

 put listSortedFiles(currentFolder(), currentRecurse()) into field "Result"
it lists all the files in the folder,

Code: Select all

function listSortedFiles pFolder, pRecurse
  local tFiles
  put listFiles(pFolder, pRecurse) into tFiles
  # HINT: Try using listFilesWithPaths() instead of listFiles() to return full path of each file.
  # Try changing the listSortedFileSortKey() function to customize how files are sorted.
  sort lines of tFiles by listSortedFilesSortKey(each)
  return tFiles
end listSortedFiles

# Used by the listSortedFiles() function. Returns a sort key from each file's name to
# allow the sorting to be fully customized. There are three possible options already
# given here, try commenting out the first / second options to see the others working.
function listSortedFilesSortKey pFile
  # Use this value for a normal text sort
  return pFile
  
  # Use this value to sort on the entire path
  return the directory & slash & pFile
  
  # Use this value to sort by extension
  local tExtension
 set the itemDelimiter to "."
  put item -1 of pFile into tExtension
  set the itemDelimiter to comma
  return tExtension
end listSortedFilesSortKey

Re: return list of only mp3 files

Posted: Fri Feb 05, 2010 8:05 pm
by Klaus
Hi reelstuf,,

I would use "filter":
...
filter list_of_files with "*.mp3"
...

Et voila, only MP3 files in the list :)


Best

Klaus

Re: return list of only mp3 files

Posted: Fri Feb 05, 2010 8:54 pm
by reelstuff
Thanks, yes, that does it, nice thanks