Fast listing of nested folders in directory

This command-line finds every subdirectory in the user’s Documents folder:

But the problem is, that it doesn’t ignore the subfolders contained by application packages!
For the command-line “packages” (mostly used for Apps) are just like ordinary directories!

What I need is a “command-line” OR “vanilla” Applescript
with the following attributes:
¢ fast
¢ stand-alone
“ no “tell application xyz” commands contained (slows script down and may cause errors in some situations)
“ no 3rd party osaxen needed (useless to my mind - just nice for personal-only use)
¢ does NOT list the content of packages

optional but appreciated:
¢ option to define a subfolder deph-limit
¢ option to choose whether to handle packages like folders or like files

Output can be returned as alias or POSIX (prefered) paths

Would be great if anybody could help me out with this! Even if its just a hint!

Vincent

You could try using grep to filter a list:

choose folder
get quoted form of (text 1 thru -2 of (POSIX path of result))

try
	do shell script "/usr/bin/find " & result & " -type d | /usr/bin/grep -v '.app/'"
on error errorMsg number errorNum
	display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
end try

Change the shell script in the above script to something like this:

do shell script "/usr/bin/find " & result & " -type d -maxdepth 1 | /usr/bin/grep -v '.app/'"

Same as above:

do shell script "/usr/bin/find " & result & " -type d -maxdepth 1 | /usr/bin/grep -v '.app/' | /usr/bin/grep -v '.app$'"

A possible subroutine:

choose folder
get quoted form of (text 1 thru -2 of (POSIX path of result)) -- This gets rid of the trailing slash.
listSubFolders below (result) with treatAppsAsFiles given maxDepth:1

on listSubFolders below parentFolder given maxDepth:depth, treatAppsAsFiles:appsAreFiles
	set theShellScript to ""
	if depth is greater than 0 then set theShellScript to theShellScript & " -maxdepth " & depth
	set theShellScript to theShellScript & " | /usr/bin/grep -v '.app/'"
	if appsAreFiles then set theShellScript to theShellScript & " | /usr/bin/grep -v '.app$'"
	
	do shell script ("/usr/bin/find " & parentFolder & " -type d" & theShellScript)
end listSubFolders

-- parentFolder is a POSIX path with *no* trailing slash. ("find" will add one.)
-- maxDepth is an integer that is greater then or equal to 0. If it's 0, then all subfolders are searched.
-- treatAppsAsFiles is a boolean. It will compile as "with treatAppsAsFiles" (true) or "without treatAppsAsFiles" (false).

Bruce, you’re great!
I didn’t think about the “find” command!

The problem is just that there are a lot of file formats that are actually packages!
Just to give some Examples:

(and folders don’t even need a file extension like these to become a package - apps like XRay or FileBuddy can make folders into packages and vice versa)

Is there any way to find out if a directory is a package?

Even this

folder of (info for (choose file))

is too smart
(damn, too smart tor this purpose!) and returns true if the file is a package!

I think this is what you mean:

package folder of (info for (choose file))

Best wishes

John M

LOL! Thanx!
Next time I should take a look into the Standard Additions at first!

Now I’ll just have to combine them!

I’ll post the script i have come up, when it’s finished!