<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The following should count directory entries immediately within a given directory, excluding "." and ".." if present (not all filesystems list those explicitly, although they still otherwise work as expected).  If compiled with -DTEST, it also provides a main() function to exercise the file counting function.  It compiles without warnings and appears to work as expected on at least OS X 10.11.6 (El Capitan), Ubuntu 16.04.2 LTS (Xenial Xerus), and Solaris 9.  I checked man pages for various functions and include files rather than going from memory, to be reasonably sure I was doing everything the proper way, so that it would be as portable as possible.  The actual function is int countfiles(const char *dirpath), and returns the number of files, or -1 in event of error (with errno reflecting the error that caused it to fail, whether opening the directory, or occasionally some problem reading the directory).  There's probably a thing or two I could have done better (a static const int for -1 rather than two uses of the actual constant might have saved four bytes), but other than that, it's pretty clean, IMO.</div><div class=""><br class=""></div><div class="">#include <stdlib.h><br class="">#include <errno.h><br class="">#include <dirent.h><br class="">#include <string.h><br class=""><br class="">#ifdef TEST<br class="">extern int countfiles(const char *);<br class="">#include <stdio.h><br class="">int<br class="">main(int argc, char **argv)<br class="">{<br class=""><span class="Apple-tab-span" style="white-space:pre">    </span>int arg, count, rc = 0;<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">   </span>for (arg = 1; arg < argc; ++arg) {<br class=""><span class="Apple-tab-span" style="white-space:pre">          </span>if ((count = countfiles(argv[arg])) == -1) {<br class=""><span class="Apple-tab-span" style="white-space:pre">                   </span>perror(argv[arg]);<br class=""><span class="Apple-tab-span" style="white-space:pre">                     </span>rc = 1;<br class=""><span class="Apple-tab-span" style="white-space:pre">                </span>}<br class=""><span class="Apple-tab-span" style="white-space:pre">              </span>else<br class=""><span class="Apple-tab-span" style="white-space:pre">                   </span>(void) printf("%s: %d\n", argv[arg], count);<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>}<br class=""><span class="Apple-tab-span" style="white-space:pre">      </span>return (rc);<br class="">}<br class="">#endif<br class=""><br class="">int<br class="">countfiles(const char *dirpath)<br class="">{<br class=""><span class="Apple-tab-span" style="white-space:pre">   </span>int count = 0, errno_save;<br class=""><span class="Apple-tab-span" style="white-space:pre">     </span>DIR *dirp;<br class=""><span class="Apple-tab-span" style="white-space:pre">     </span>struct dirent *dp;<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if ((dirp = opendir(dirpath)) == NULL)<br class=""><span class="Apple-tab-span" style="white-space:pre">         </span>return (-1);<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">      </span>errno = 0; /* because readdir() returns NULL on both EOF and error */<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">     </span>while ((dp = readdir(dirp)) !=NULL) {<br class=""><span class="Apple-tab-span" style="white-space:pre">          </span>if (strcmp(dp->d_name, ".") == 0 ||<br class=""><span class="Apple-tab-span" style="white-space:pre">               </span>    strcmp(dp->d_name, "..") == 0)<br class=""><span class="Apple-tab-span" style="white-space:pre">                      </span>continue;<br class=""><span class="Apple-tab-span" style="white-space:pre">              </span>++count;<br class=""><span class="Apple-tab-span" style="white-space:pre">       </span>}<br class=""><span class="Apple-tab-span" style="white-space:pre">      </span>if (errno != 0) {<br class=""><span class="Apple-tab-span" style="white-space:pre">              </span>errno_save = errno;<br class=""><span class="Apple-tab-span" style="white-space:pre">            </span>(void) closedir(dirp);<br class=""><span class="Apple-tab-span" style="white-space:pre">         </span>errno = errno_save;<br class=""><span class="Apple-tab-span" style="white-space:pre">            </span>return (-1);<br class=""><span class="Apple-tab-span" style="white-space:pre">   </span>}<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>(void) closedir(dirp);<br class=""><span class="Apple-tab-span" style="white-space:pre"> </span>return (count);<br class="">}<br class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 3, 2017, at 09:11, Galen Johnson <<a href="mailto:Galen.Johnson@sas.com" class="">Galen.Johnson@sas.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class="">Thanks for the offer, Kenneth.  I have a simple script (ls $dir | wc -l) as well but I had thought that it was already a part of the Xymon base.  It would be nice to have it as an option to DIR and if I can find the time, I may look into dusting off my C skills and take a stab at it...though using the terms "skills" along side "C" is a stretch for me :-).<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class="">=G=<br class=""></div><div style="margin-top: 0px; margin-bottom: 0px; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><br class=""></div><div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); color: rgb(33, 33, 33);" class=""><hr tabindex="-1" style="display: inline-block; width: 1401.390625px;" class=""><div id="divRplyFwdMsg" dir="ltr" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Kenneth S. Petersen <<a href="mailto:ksp@stougaards.dk" style="color: purple; text-decoration: underline;" class="">ksp@stougaards.dk</a>><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Friday, March 3, 2017 3:37 AM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Galen Johnson; Galen Johnson<br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:xymon@xymon.com" style="color: purple; text-decoration: underline;" class="">xymon@xymon.com</a><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>SV: [Xymon] file counts</font><div class=""> </div></div><div class=""><div class="WordSection1"><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class="">Hi Galen,</span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class="">I’m using the count file feature but with a external script on windows along with bbwin 0.13 or 0.12</span></div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class=""> </span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class="">It a two part script, one cfg file in the bbwin etc folder and one vbs in the bbwin ext folder.</span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class="">Then call it from bbwin.cfg</span></div><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class="">Actually it’s the bbwin, fsmon.vbs that I have altered so it fits my needs.</span></div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class=""> </span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class="">Let me know if you want the script.</span></div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class=""> </span></p><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span lang="EN-US" style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class=""> </span></p><div style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><span lang="EN-US" style="font-size: 10pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><br class=""><br class=""></span><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">Med Venlig Hilsen</span><span style="font-size: 10pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><br class=""></span><span style="font-size: 14pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">Kenneth S. Petersen</span><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class=""><br class="">IT Konsulent – Stougaards IT<br class="">Wiuffsvej 3, DK-4540 Fårevejle, Denmark<br class="">Email:<span class="Apple-converted-space"> </span></span><u class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: blue;" class=""><a href="mailto:info@stougaardsit.dk" style="color: purple; text-decoration: underline;" class="">info@stougaardsit.dk</a></span></u><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="Apple-converted-space"> </span></span><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(31, 73, 125);" class="">Mob.+45 2163 2325<br class=""><br class=""></span><span style="font-size: 11pt; font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class=""></span></div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><span style="font-family: Calibri, sans-serif; color: rgb(68, 84, 106);" class=""> </span></p><div style="margin: 0cm 0cm 0.0001pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class=""><b class=""><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class="">Fra:</span></b><span style="font-size: 11pt; font-family: Calibri, sans-serif;" class=""><span class="Apple-converted-space"> </span>Xymon [<a href="mailto:xymon-bounces@xymon.com" style="color: purple; text-decoration: underline;" class="">mailto:xymon-bounces@xymon.com</a>]<span class="Apple-converted-space"> </span><b class="">På vegne af<span class="Apple-converted-space"> </span></b>Galen Johnson<br class=""><b class="">Sendt:</b><span class="Apple-converted-space"> </span>3. marts 2017 01:30<br class=""><b class="">Til:</b><span class="Apple-converted-space"> </span>Galen Johnson <<a href="mailto:Galen.Johnson@sas.com" style="color: purple; text-decoration: underline;" class="">Galen.Johnson@sas.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:xymon@xymon.com" style="color: purple; text-decoration: underline;" class="">xymon@xymon.com</a><br class=""><b class="">Emne:</b><span class="Apple-converted-space"> </span>Re: [Xymon] file counts</span></div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> </p><div class=""><div class=""><p class="MsoNormal" style="margin: 0cm 0cm 12pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;">Apparently, I wasn't the only one with this need.  I found a thread from 2011.  I really don't want to go that route so consider this a feature request that DIR can support more than just size but file count as well.</p></div><div style="margin: 0cm 0cm 0.0001pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">=G=</div></div><div class=""><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> </p><div class=""><div style="margin: 0cm 0cm 0.0001pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;" class="">On Thu, Mar 2, 2017 at 2:20 PM, Galen Johnson <<a href="mailto:Galen.Johnson@sas.com" target="_blank" style="color: purple; text-decoration: underline;" class="">Galen.Johnson@sas.com</a>> wrote:</div><blockquote style="border-style: none none none solid; border-left-color: rgb(204, 204, 204); border-left-width: 1pt; padding: 0cm 0cm 0cm 6pt; margin-left: 4.8pt; margin-right: 0cm;" class=""><div class=""><div style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white;" class=""><span style="font-family: Calibri, sans-serif;" class="">​Hey,</span></div><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white; background-position: initial initial; background-repeat: initial initial;" class=""><span style="font-family: Calibri, sans-serif;" class=""> </span></p><div style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white;" class=""><span style="font-family: Calibri, sans-serif;" class="">I could've sworn that Xymon had a way to count the number of files in a particular directory (natively) and you could set up alerts based on number of files.  Apparently, I was wrong or I'm not seeing it in the docs.  Obviously, I could get clever with file ages but that's just annoying.  Am I missing something?</span></div><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white; background-position: initial initial; background-repeat: initial initial;" class=""><span style="font-family: Calibri, sans-serif;" class=""> </span></p><div style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white;" class=""><span style="font-family: Calibri, sans-serif;" class="">thanks</span></div><p style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white; background-position: initial initial; background-repeat: initial initial;" class=""><span style="font-family: Calibri, sans-serif; color: rgb(136, 136, 136);" class=""> </span></p><div style="margin-top: 0px; margin-bottom: 0px; margin-left: 65.2pt; background-color: white;" class=""><span style="font-family: Calibri, sans-serif; color: rgb(136, 136, 136);" class="">=G=</span></div></div><p class="MsoNormal" style="margin: 0cm 0cm 12pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;"><br class="">_______________________________________________<br class="">Xymon mailing list<br class=""><a href="mailto:Xymon@xymon.com" style="color: purple; text-decoration: underline;" class="">Xymon@xymon.com</a><br class=""><a href="http://lists.xymon.com/mailman/listinfo/xymon" target="_blank" style="color: purple; text-decoration: underline;" class="">http://lists.xymon.com/mailman/listinfo/xymon</a></p></blockquote></div><p class="MsoNormal" style="margin: 0cm 0cm 0.0001pt 65.2pt; font-size: 12pt; font-family: 'Times New Roman', serif;"> </p></div></div></div></div><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><span style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); float: none; display: inline !important;" class="">Xymon mailing list</span><br style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><a href="mailto:Xymon@xymon.com" style="color: purple; text-decoration: underline; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class="">Xymon@xymon.com</a><br style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""><a href="http://lists.xymon.com/mailman/listinfo/xymon" style="color: purple; text-decoration: underline; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class="">http://lists.xymon.com/mailman/listinfo/xymon</a><br style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 16px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);" class=""></div></blockquote></div><br class=""></body></html>