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: Shane Stanley <email@hidden>
- Date: Tue, 13 Oct 2015 22:08:39 +1100
On 13 Oct 2015, at 9:42 PM, Axel Luttgens <email@hidden> wrote:
>
> I don’t know why but, in the case of Bert, I immediately envisioned a hierarchy of files and "pure" folders, without thinking further.
It's an easy enough assumption to make -- but I'd argue that's just another reason not to make it. Mac OS is built on Unix, but the stuff on top is also important.
>
> 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 \\)"
Honestly, I think this a case of finding yourself in a hole, and trying to dig your way out. First, it's fraught with peril. And second, it's very inefficient because even if you manage to add every possible extension to your regex pattern, find is still going to traverse all those unnecessary directories. So when I run your script on my home folder, it takes just under 70 seconds. Ouch.
>
> 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.
Yes, that's a lot quicker than find. But is it a big enough win to warrant relying on the indexing being correct? In my test, it comes in around 14 seconds. (I guess searches on keys where there are multiple entries take longer.) It seems to me that it's again a compromise, for no gain.
--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
_______________________________________________
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