return list of only mp3 files

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

return list of only mp3 files

Post by reelstuff » Fri Feb 05, 2010 6:35 pm

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

Klaus
Posts: 14198
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: return list of only mp3 files

Post by Klaus » Fri Feb 05, 2010 8:05 pm

Hi reelstuf,,

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

Et voila, only MP3 files in the list :)


Best

Klaus

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Re: return list of only mp3 files

Post by reelstuff » Fri Feb 05, 2010 8:54 pm

Thanks, yes, that does it, nice thanks

Post Reply