number of items in a folder using shell

Hello,
to get the number of items in a given folder I use the following syntax in a shell:

mShell.Execute “find -x " + foo.shellpath + " -type f | wc -l”

and I get the total number of items, including items in subfolders.
Can anybody tell me how to get the number of items SKIPPING subfolders-aliases?
For instance, if foo contains 5 subfolders, and two of them are aliases, I’d like to skip the two aliases.
I made a several google-searches on the subject, but I could not find the answer.

Suggestions welcome. Thank you in advance.

How about using a plugin?

Or some Xojo code with folderitems?

I’d better go for “some Xojo code with folderitems”. Are you referring to some specific code, or just employing normal recursion skipping alias?
Thanks.

Yes. Normal folderitem Loops with checking trueitem

Or if you need speed, check the DirectorySizeMBS Class here:

http://monkeybreadsoftware.net/class-directorysizembs.shtml

I just added the Linux part there last week.

Christian, thank for answering.
At present, no plugin needed.

EDIT - I hit Save instead of Preview …

theShell.Execute "ls -1 /Path/To/Folder | wc -l"

That’s the number one, not a lower case ell.

To weed out the non-directory, non-folder items:

theShell.Execute "ls -lO /Path/To/Folder | grep ^[-d] | wc -l

@Tim Jones First of all, thank you for answering.
As for the snippets: the first one skips the content of all folders, while I’d like to skip alias-folder/directories’s content only.
The second one returns “0”.

Here is the output on my system just to demonstrate that the commands work. I’m using my system’s root folder stepping through each command:

$ ls -1 /
Applications
DAXbroadcastTemp
Desktop
Library
Network
System
Users
Volumes
bin
bru
cache
cores
dev
etc
ffaconfig-out.txt
home
installer.failurerequests
net
opt
private
sbin
tmp
usr
var

With the wc -l added:

$ ls -1 / | wc -l
      24

Using the second form to only count normal files or folders:

$ ls -lO / 
total 71
drwxrwxr-x+ 90 root    admin  sunlnk            3060 Aug 12 10:55 Applications
drwxr-xr-x   3 root    wheel  -                  102 Jul 16 15:15 DAXbroadcastTemp
drwx------+  3 tjones  admin  -                  102 Jul 31 11:35 Desktop
drwxr-xr-x+ 61 root    wheel  sunlnk            2074 Aug  8 16:28 Library
drwxr-xr-x@  2 root    wheel  hidden              68 Feb 25 15:50 Network
drwxr-xr-x@  4 root    wheel  restricted         136 Jul 21 12:00 System
drwxr-xr-x   8 root    admin  -                  272 Aug 15 09:34 Users
drwxrwxrwt@  6 root    admin  hidden             204 Aug 20 21:37 Volumes
drwxr-xr-x@ 39 root    wheel  restricted,hidden 1326 Jul 21 12:00 bin
drwxr-xr-x  47 tjones  staff  -                 1598 Aug 12 10:55 bru
drwxr-xr-x   4 root    wheel  -                  136 Jul 16 15:29 cache
drwxrwxr-t@  2 root    admin  hidden              68 Feb 25 15:50 cores
dr-xr-xr-x   3 root    wheel  hidden            5507 Aug 20 21:33 dev
lrwxr-xr-x@  1 root    wheel  restricted,hidden   11 Jul 16 11:02 etc -> private/etc
-rw-r--r--   1 root    wheel  -                 8979 Jul 16 15:15 ffaconfig-out.txt
dr-xr-xr-x   2 root    wheel  hidden               1 Aug 20 21:33 home
-rw-r--r--@  1 root    wheel  hidden             313 Aug  2  2015 installer.failurerequests
dr-xr-xr-x   2 root    wheel  hidden               1 Aug 20 21:33 net
drwxr-xr-x@  4 root    wheel  hidden             136 Jul 22 12:00 opt
drwxr-xr-x@  6 root    wheel  sunlnk,hidden      204 Jul 16 11:03 private
drwxr-xr-x@ 59 root    wheel  restricted,hidden 2006 Jul 21 12:00 sbin
lrwxr-xr-x@  1 root    wheel  restricted,hidden   11 Jul 16 11:02 tmp -> private/tmp
drwxr-xr-x@ 12 root    wheel  restricted,hidden  408 Jul 16 11:22 usr
lrwxr-xr-x@  1 root    wheel  restricted,hidden   11 Jul 16 11:02 var -> private/var

With the grep added to remove links / aliases and other odd items:

$ ls -lO / | grep ^[-d]
drwxrwxr-x+ 90 root    admin  sunlnk            3060 Aug 12 10:55 Applications
drwxr-xr-x   3 root    wheel  -                  102 Jul 16 15:15 DAXbroadcastTemp
drwx------+  3 tjones  admin  -                  102 Jul 31 11:35 Desktop
drwxr-xr-x+ 61 root    wheel  sunlnk            2074 Aug  8 16:28 Library
drwxr-xr-x@  2 root    wheel  hidden              68 Feb 25 15:50 Network
drwxr-xr-x@  4 root    wheel  restricted         136 Jul 21 12:00 System
drwxr-xr-x   8 root    admin  -                  272 Aug 15 09:34 Users
drwxrwxrwt@  6 root    admin  hidden             204 Aug 20 21:37 Volumes
drwxr-xr-x@ 39 root    wheel  restricted,hidden 1326 Jul 21 12:00 bin
drwxr-xr-x  47 tjones  staff  -                 1598 Aug 12 10:55 bru
drwxr-xr-x   4 root    wheel  -                  136 Jul 16 15:29 cache
drwxrwxr-t@  2 root    admin  hidden              68 Feb 25 15:50 cores
dr-xr-xr-x   3 root    wheel  hidden            5507 Aug 20 21:33 dev
-rw-r--r--   1 root    wheel  -                 8979 Jul 16 15:15 ffaconfig-out.txt
dr-xr-xr-x   2 root    wheel  hidden               1 Aug 20 21:33 home
-rw-r--r--@  1 root    wheel  hidden             313 Aug  2  2015 installer.failurerequests
dr-xr-xr-x   2 root    wheel  hidden               1 Aug 20 21:33 net
drwxr-xr-x@  4 root    wheel  hidden             136 Jul 22 12:00 opt
drwxr-xr-x@  6 root    wheel  sunlnk,hidden      204 Jul 16 11:03 private
drwxr-xr-x@ 59 root    wheel  restricted,hidden 2006 Jul 21 12:00 sbin
drwxr-xr-x@ 12 root    wheel  restricted,hidden  408 Jul 16 11:22 usr

With the grep and wc added:

$ ls -lO / | grep ^[-d] | wc -l
      21

However, I did just realize that that won’t catch aliases as you’re looking to do. In that case, we need one more command to get the alias count so you can subtract it from the number returned in “ls -lO / | grep ^[-d] | wc -l”. This is a folder that has 25 files from the above, but with 2 aliases.

$ IFS=$'\
'; for x in `ls -1 /`; do mdls -raw -name kMDItemKind "/$x" | grep Alias$; done | wc -l
    2

That will return the number of alias files.
Then, subtract 2 from 25 to get 23. That counts only files and directories - no aliases, no symlinks, no character special nodes, etc.
A bit convoluted, but the combination will get you what you want.

Tim, please bear with me: where, in the second run, should I enter the target-folder? Here are a couple of the outputs I get for a folder containing 2 files and 2 aliases:

$ ls -lO /Users/carlorubini/Desktop/Uploads | grep ^[-d] | wc -l
4
$ IFS=$’
‘; for x in ls -1 /; do mdls -raw -name kMDItemKind “/$x” | grep Alias$; done | wc -l
0
$ IFS=$’
'; for x in ls -1 /Users/carlorubini/Desktop/Uploads ; do mdls -raw -name kMDItemKind “/$x” | grep Alias$; done | wc -l
0

Yes - you need to change the path sent to the ls command as well as the mdls command. It would actually be more straight-forward to “cd” into the folder and THEN use the “./” path as the check point.

Fine. Thank you.