Get full directory contents with AppleScript

Alexsander Akers picture Alexsander Akers · Jan 19, 2010 · Viewed 34.1k times · Source

I need to get the entire (visible) contents of a folder and its subfolders as a list. Is this possible?

Answer

mcgrailm picture mcgrailm · Mar 31, 2010

that is way more work than needed. I know this is an old post but I want you both to see how easy this can be

  tell application "Finder"
     set file_list to entire contents of (choose folder with prompt "Please select directory.")
   end tell 

if you want a list of file names then you could do this

  tell application "Finder"
    set file_list to name of every file of entire contents of (choose folder with prompt "Please select directory.")
   end tell

Due to the comments that follow this post I asked a group of experts in business to look at this question and evaluate our answer in an unbiased manner and the answer I got was thsis

"How about a pox on both your houses? :-)

Yes, entire contents does exactly what you say -- but it easily chokes on large folders, and takes forever (and a day if you're on 10.6). It's OK for small things, like extracting all the files of one kind out of a folder you know will only contain a small number of files.

The recursive method also works well -- but it's using "list folder", and the dictionary listing for it says it's deprecated and we shouldn't use it any more."

So I hear by declare that I was wrong! both of these solutions are valid but have "pox" or holes in their uses. My applogies to to Philip. Should he decide to edit his answer (because thats the only way to change my vote)I will be happy to return and give him +1