Re: Shell script to get a list of all subfolders inside a folder
Re: Shell script to get a list of all subfolders inside a folder
- Subject: Re: Shell script to get a list of all subfolders inside a folder
- From: Axel Luttgens <email@hidden>
- Date: Tue, 13 Oct 2015 12:42:44 +0200
> Le 13 oct. 2015 à 01:13, Shane Stanley a écrit :
>
> On 13 Oct 2015, at 2:19 AM, Axel Luttgens <email@hidden> wrote:
>>
>> Probably not the most efficient, but should be quicker than Finder’s "entire contents":
>>
>> property mylist : {}
>>
>> set myfolder to alias "Macintosh HD:Users:bertus:Desktop:example folder"
>>
>> set myfolder to quoted form of POSIX path of myfolder
>> set AppleScript's text item delimiters to {return}
>> set mylist to text items of (do shell script "/usr/bin/find " & myfolder & " -type d")
>
> The problem with using find -- and most shell commands -- is that they generally can't distinguish between packages and folders. So this is going to lump in packages such as .rtfd and .scptd files, not to mention .app files. Worse, it will include folders within packages.
Hello Shane,
You are of course right.
I don’t know why but, in the case of Bert, I immediately envisioned a hierarchy of files and "pure" folders, without thinking further. Well, that’s probably because I’ve always been under the impression he is busy in some kind of publishing company.
But yes, even in that case, some "documents" may in fact be folders; for example rtfd or older pages documents. If such cases are easily identified and enumerated, above do shell script could be replaced with something like this:
do shell script "/usr/bin/find " & myfolder & " -type d \\( \\( -iregex '.*\\.(rtfd|pages)$' -and -prune \\) -or -print \\)"
On the other hand, one could decide to rely on Spotlight and make use of:
do shell script "/usr/bin/mdfind -onlyin " & myfolder & " 'kMDItemContentType = public.folder'"
This should be quicker than the traversal performed by find, but supposes the indexes to be up to date.
Axel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden