C/C++ User's Journal STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - where the Standard Template Library meets the Active Template Library COMSTL - where the Standard Template Library meets the Component Object Model
Synesis Software InetSTL - where the Standard Template Library meets the Internet UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Test Programs

Introduction

Version 1.6.2 contains nine test programs.

C.c

This program uses the raw recls C API functions, implementing a recursive search for a given pattern, from a given directory

Cpp.cpp

This program uses the recls/C++ mapping classes, implementing a recursive search for a given pattern, from a given directory (Win32 platform)

WinForm.cs

This program uses the recls/C# mapping classes, implementing a recursive search for a given pattern, and other flags, from a given directory

namespace CS
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using recls;

    public class WinForm : System.Windows.Forms.Form
    {
        private System.ComponentModel.Container components = null;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.TextBox searchRoot;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox pattern;
        private System.Windows.Forms.Button btnSearch;
        private System.Windows.Forms.ListView listFiles;
        private System.Windows.Forms.ListView listProperties;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.ListBox listDirectoryParts;
        private System.Windows.Forms.CheckBox chkRecursive;
        private System.Windows.Forms.CheckBox chkDirectoryParts;
        private System.Windows.Forms.Label lblDirectoryParts;
        private System.Windows.Forms.ProgressBar progbar;
        private System.Windows.Forms.RadioButton rbtnFiles;
        private System.Windows.Forms.RadioButton rbtnDirectories;
        private System.Windows.Forms.RadioButton rbtnBoth;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.TextBox host;
        private System.Windows.Forms.TextBox username;
        private System.Windows.Forms.TextBox password;
        private System.Windows.Forms.Label label3;

        public WinForm()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        protected override void Dispose (bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.searchRoot = new System.Windows.Forms.TextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.pattern = new System.Windows.Forms.TextBox();
            this.btnSearch = new System.Windows.Forms.Button();
            this.label3 = new System.Windows.Forms.Label();
            this.listFiles = new System.Windows.Forms.ListView();
            this.listProperties = new System.Windows.Forms.ListView();
            this.label4 = new System.Windows.Forms.Label();
            this.lblDirectoryParts = new System.Windows.Forms.Label();
            this.listDirectoryParts = new System.Windows.Forms.ListBox();
            this.chkRecursive = new System.Windows.Forms.CheckBox();
            this.chkDirectoryParts = new System.Windows.Forms.CheckBox();
            this.progbar = new System.Windows.Forms.ProgressBar();
            this.rbtnFiles = new System.Windows.Forms.RadioButton();
            this.rbtnDirectories = new System.Windows.Forms.RadioButton();
            this.rbtnBoth = new System.Windows.Forms.RadioButton();
            this.label5 = new System.Windows.Forms.Label();
            this.host = new System.Windows.Forms.TextBox();
            this.label6 = new System.Windows.Forms.Label();
            this.username = new System.Windows.Forms.TextBox();
            this.label7 = new System.Windows.Forms.Label();
            this.password = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(8, 48);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 16);
            this.label1.TabIndex = 6;
            this.label1.Text = "Search &root:";
            // 
            // searchRoot
            // 
            this.searchRoot.Location = new System.Drawing.Point(112, 48);
            this.searchRoot.Name = "searchRoot";
            this.searchRoot.Size = new System.Drawing.Size(632, 20);
            this.searchRoot.TabIndex = 7;
            this.searchRoot.Text = "";
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(8, 88);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(100, 16);
            this.label2.TabIndex = 8;
            this.label2.Text = "&Pattern:";
            // 
            // pattern
            // 
            this.pattern.Location = new System.Drawing.Point(112, 80);
            this.pattern.Name = "pattern";
            this.pattern.TabIndex = 9;
            this.pattern.Text = "*.*";
            // 
            // btnSearch
            // 
            this.btnSearch.Location = new System.Drawing.Point(664, 80);
            this.btnSearch.Name = "btnSearch";
            this.btnSearch.Size = new System.Drawing.Size(80, 23);
            this.btnSearch.TabIndex = 15;
            this.btnSearch.Text = "&Search";
            this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
            // 
            // label3
            // 
            this.label3.Location = new System.Drawing.Point(8, 120);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(100, 16);
            this.label3.TabIndex = 16;
            this.label3.Text = "F&iles:";
            // 
            // listFiles
            // 
            this.listFiles.Location = new System.Drawing.Point(8, 136);
            this.listFiles.MultiSelect = false;
            this.listFiles.Name = "listFiles";
            this.listFiles.Size = new System.Drawing.Size(384, 368);
            this.listFiles.TabIndex = 17;
            this.listFiles.View = System.Windows.Forms.View.Details;
            this.listFiles.SelectedIndexChanged += new System.EventHandler(this.listFiles_SelectedIndexChanged);
            // 
            // listProperties
            // 
            this.listProperties.Location = new System.Drawing.Point(400, 136);
            this.listProperties.Name = "listProperties";
            this.listProperties.Size = new System.Drawing.Size(344, 224);
            this.listProperties.TabIndex = 19;
            this.listProperties.View = System.Windows.Forms.View.Details;
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(408, 120);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(100, 16);
            this.label4.TabIndex = 18;
            this.label4.Text = "Pr&operties";
            // 
            // lblDirectoryParts
            // 
            this.lblDirectoryParts.Location = new System.Drawing.Point(400, 368);
            this.lblDirectoryParts.Name = "lblDirectoryParts";
            this.lblDirectoryParts.Size = new System.Drawing.Size(120, 16);
            this.lblDirectoryParts.TabIndex = 20;
            this.lblDirectoryParts.Text = "Directory par&ts:";
            // 
            // listDirectoryParts
            // 
            this.listDirectoryParts.Location = new System.Drawing.Point(400, 384);
            this.listDirectoryParts.Name = "listDirectoryParts";
            this.listDirectoryParts.Size = new System.Drawing.Size(344, 121);
            this.listDirectoryParts.TabIndex = 21;
            // 
            // chkRecursive
            // 
            this.chkRecursive.Checked = true;
            this.chkRecursive.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkRecursive.Location = new System.Drawing.Point(224, 88);
            this.chkRecursive.Name = "chkRecursive";
            this.chkRecursive.Size = new System.Drawing.Size(96, 16);
            this.chkRecursive.TabIndex = 10;
            this.chkRecursive.Text = "Recursi&ve";
            // 
            // chkDirectoryParts
            // 
            this.chkDirectoryParts.Checked = true;
            this.chkDirectoryParts.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkDirectoryParts.Location = new System.Drawing.Point(328, 88);
            this.chkDirectoryParts.Name = "chkDirectoryParts";
            this.chkDirectoryParts.Size = new System.Drawing.Size(104, 16);
            this.chkDirectoryParts.TabIndex = 11;
            this.chkDirectoryParts.Text = "Directory P&arts";
            // 
            // progbar
            // 
            this.progbar.Location = new System.Drawing.Point(8, 512);
            this.progbar.Name = "progbar";
            this.progbar.Size = new System.Drawing.Size(736, 16);
            this.progbar.TabIndex = 11;
            // 
            // rbtnFiles
            // 
            this.rbtnFiles.Appearance = System.Windows.Forms.Appearance.Button;
            this.rbtnFiles.Checked = true;
            this.rbtnFiles.Location = new System.Drawing.Point(440, 80);
            this.rbtnFiles.Name = "rbtnFiles";
            this.rbtnFiles.Size = new System.Drawing.Size(48, 24);
            this.rbtnFiles.TabIndex = 12;
            this.rbtnFiles.TabStop = true;
            this.rbtnFiles.Text = "&Files";
            // 
            // rbtnDirectories
            // 
            this.rbtnDirectories.Appearance = System.Windows.Forms.Appearance.Button;
            this.rbtnDirectories.Location = new System.Drawing.Point(496, 80);
            this.rbtnDirectories.Name = "rbtnDirectories";
            this.rbtnDirectories.Size = new System.Drawing.Size(72, 24);
            this.rbtnDirectories.TabIndex = 13;
            this.rbtnDirectories.Text = "&Directories";
            // 
            // rbtnBoth
            // 
            this.rbtnBoth.Appearance = System.Windows.Forms.Appearance.Button;
            this.rbtnBoth.Location = new System.Drawing.Point(576, 80);
            this.rbtnBoth.Name = "rbtnBoth";
            this.rbtnBoth.Size = new System.Drawing.Size(48, 24);
            this.rbtnBoth.TabIndex = 14;
            this.rbtnBoth.Text = "&Both";
            // 
            // label5
            // 
            this.label5.Location = new System.Drawing.Point(8, 16);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(96, 23);
            this.label5.TabIndex = 0;
            this.label5.Text = "&Host:";
            // 
            // host
            // 
            this.host.Location = new System.Drawing.Point(112, 16);
            this.host.Name = "host";
            this.host.Size = new System.Drawing.Size(128, 20);
            this.host.TabIndex = 1;
            this.host.Text = "";
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(248, 16);
            this.label6.Name = "label6";
            this.label6.TabIndex = 2;
            this.label6.Text = "&Username:";
            // 
            // username
            // 
            this.username.Location = new System.Drawing.Point(360, 16);
            this.username.Name = "username";
            this.username.Size = new System.Drawing.Size(144, 20);
            this.username.TabIndex = 3;
            this.username.Text = "";
            // 
            // label7
            // 
            this.label7.Location = new System.Drawing.Point(512, 16);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(80, 23);
            this.label7.TabIndex = 4;
            this.label7.Text = "&Password:";
            // 
            // password
            // 
            this.password.Location = new System.Drawing.Point(600, 16);
            this.password.Name = "password";
            this.password.PasswordChar = '*';
            this.password.Size = new System.Drawing.Size(144, 20);
            this.password.TabIndex = 5;
            this.password.Text = "";
            // 
            // WinForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(752, 531);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.password,
                                                                          this.label7,
                                                                          this.username,
                                                                          this.label6,
                                                                          this.host,
                                                                          this.label5,
                                                                          this.rbtnFiles,
                                                                          this.progbar,
                                                                          this.chkDirectoryParts,
                                                                          this.chkRecursive,
                                                                          this.listDirectoryParts,
                                                                          this.lblDirectoryParts,
                                                                          this.label4,
                                                                          this.listProperties,
                                                                          this.listFiles,
                                                                          this.label3,
                                                                          this.btnSearch,
                                                                          this.pattern,
                                                                          this.label2,
                                                                          this.searchRoot,
                                                                          this.label1,
                                                                          this.rbtnDirectories,
                                                                          this.rbtnBoth});
            this.Name = "WinForm";
            this.Text = "recls C# mapping test";
            this.Load += new System.EventHandler(this.WinForm_Load);
            this.ResumeLayout(false);

        }
        #endregion

        [STAThread]
        static void Main() 
        {
            Application.Run(new WinForm());
        }
        
        private void btnSearch_Click(object sender, System.EventArgs e)
        {
            progbar.Maximum = 1000;

            RECLS_FLAG  flags = 0;

            if(rbtnBoth.Checked)
            {
                flags |= RECLS_FLAG.RECLS_F_DIRECTORIES | RECLS_FLAG.RECLS_F_FILES;
            }
            else if(rbtnFiles.Checked)
            {
                flags |= RECLS_FLAG.RECLS_F_FILES;
            }
            else if(rbtnDirectories.Checked)
            {
                flags |= RECLS_FLAG.RECLS_F_DIRECTORIES;
            }

            if(chkRecursive.Checked)
            {
                flags |= RECLS_FLAG.RECLS_F_RECURSIVE;
            }

            if(chkDirectoryParts.Checked)
            {
                flags |= RECLS_FLAG.RECLS_F_DIRECTORY_PARTS;
            }

            listDirectoryParts.Enabled = chkDirectoryParts.Checked;
            lblDirectoryParts.Enabled = chkDirectoryParts.Checked;

            Search  fs;

            if(host.Text.Length > 0)
            {
                fs = new FtpSearch(host.Text, username.Text, password.Text, searchRoot.Text, pattern.Text, flags);
            }
            else
            {
                fs = new FileSearch(searchRoot.Text, pattern.Text, flags);
            }

            listFiles.Items.Clear();
            listProperties.Items.Clear();
            listDirectoryParts.Items.Clear();

            foreach(FileEntry fe in fs)
            {
                ListViewItem    lvi = new ListViewItem(fe.Path);

                lvi.Tag = fe;

                listFiles.Items.Add(lvi);

                if(1 + progbar.Value == progbar.Maximum)
                {
                    progbar.Value = 0;
                }
                else
                {
                    progbar.Value = 1 + progbar.Value;
                }
                progbar.Update();

                listFiles.Update();
            }

            progbar.Value = 0;
        }

        private void WinForm_Load(object sender, System.EventArgs e)
        {
            int cx;
            
            cx = listFiles.Width - 4;
            listFiles.Columns.Add("Filename", cx, HorizontalAlignment.Left);

            cx = listProperties.Width - 4;
            listProperties.Columns.Add("Property", cx * 2 / 5, HorizontalAlignment.Left);
            listProperties.Columns.Add("Value", cx * 3 / 5, HorizontalAlignment.Left);
        }

        private void listFiles_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            ListView.SelectedListViewItemCollection items = listFiles.SelectedItems;

            if(items.Count == 1)
            {
                PopulateProperties((FileEntry)items[0].Tag);
            }
        }

        private string TranslateEntryAttributes(FileEntry fe)
        {
            string  s   =   "";

            if(fe.IsDirectory)
            {
                if(s.Length > 0)
                {
                    s += " ";
                }
                s += "[Directory]";
            }

            if(fe.IsLink)
            {
                if(s.Length > 0)
                {
                    s += " ";
                }
                s += "[Link]";
            }

            if(fe.IsReadOnly)
            {
                if(s.Length > 0)
                {
                    s += " ";
                }
                s += "[Read only]";
            }

            return s;
        }

        private void PopulateProperties(FileEntry entry)
        {
            listProperties.Items.Clear();
            listDirectoryParts.Items.Clear();

            listProperties.Items.Add("Path").SubItems.Add(entry.Path);
            listProperties.Items.Add("Drive").SubItems.Add(entry.Drive.ToString());
            listProperties.Items.Add("Directory").SubItems.Add(entry.Directory);
            listProperties.Items.Add("DirectoryPath").SubItems.Add(entry.DirectoryPath);
            listProperties.Items.Add("File").SubItems.Add(entry.File);
            listProperties.Items.Add("ShortFile").SubItems.Add(entry.ShortFile);
            listProperties.Items.Add("FileName").SubItems.Add(entry.FileName);
            listProperties.Items.Add("FileExt").SubItems.Add(entry.FileExt);
            listProperties.Items.Add("CreationTime").SubItems.Add(entry.CreationTime.ToString());
            listProperties.Items.Add("ModificationTime").SubItems.Add(entry.ModificationTime.ToString());
            listProperties.Items.Add("LastAccessTime").SubItems.Add(entry.LastAccessTime.ToString());
            listProperties.Items.Add("LastStatusChangeTime").SubItems.Add(entry.LastStatusChangeTime.ToString());
            listProperties.Items.Add("Attributes").SubItems.Add(TranslateEntryAttributes(entry));

            foreach(string part in entry.DirectoryParts)
            {
                listDirectoryParts.Items.Add(part);
            }
        }
    }
}

COM.cpp

This program uses the recls/COM mapping coclasses, implementing a recursive search for a given pattern, and other flags, from a given directory

/* 
 * File:        COM.cpp
 *
 * Purpose:     Implementation file for the COM project.
 *
 * Created:     19th December 2003
 * Updated:     20th May 2005
 *
 * Status:      Wizard-generated
 *
 * License:     (Licensed under the Synesis Software Open License)
 *
 *              Copyright 2003-2005, Synesis Software Pty Ltd.
 *              All rights reserved.
 *
 *              www:        http://www.synesis.com.au/software
 *
 *              email:      software@synesis.com.au
 *
 *              This source code is placed into the public domain 2003
 *              by Synesis Software Pty Ltd. There are no restrictions
 *              whatsoever to your use of the software. 
 *
 *              This source code is provided by Synesis Software Pty Ltd "as is"
 *              and any warranties, whether expressed or implied, including, but
 *              not limited to, the implied warranties of merchantability and
 *              fitness for a particular purpose are disclaimed. In no event
 *              shall the Synesis Software Pty Ltd be liable for any direct,
 *              indirect, incidental, special, exemplary, or consequential
 *              damages (including, but not limited to, procurement of
 *              substitute goods or services; loss of use, data, or profits; or
 *              business interruption) however caused and on any theory of
 *              liability, whether in contract, strict liability, or tort
 *              (including negligence or otherwise) arising in any way out of
 *              the use of this software, even if advised of the possibility of
 *              such damage. 
 *
 *              Neither the name of Synesis Software Pty Ltd nor the names of
 *              any subdivisions, employees or agents of Synesis Software Pty
 *              Ltd, nor the names of any other contributors to this software
 *              may be used to endorse or promote products derived from this
 *              software without specific prior written permission. 
 *
 * 

#include <stlsoft.h>
#if !defined(_STLSOFT_VER_1_8_3)
# error STLSoft version 1.8.3 or greater required. (www.stlsoft.org/downloads.html)
#endif /* STLSoft version */

#include <atlstl.h>

#include <comstl.h>
#include <comstl/enumerator_policies.hpp>
#include <comstl/initialisers.hpp>
#include <comstl/interface_cast.hpp>
#include <comstl/value_policies.hpp>
#include <comstl/enum_sequence.hpp>
#include <comstl/coll_sequence.hpp>

#include <comstl/method_cast.hpp>

#include <winstl.h>
#include <winstl/char_conversions.hpp>

#include <recls_com.h>
#include <recls_com_i.c>

/* Standard C++ Header Files */
# include <iostream>
# include <iomanip>

using std::cout;
using std::wcout;
using std::cerr;
using std::endl;

/* Standard C Header Files */
#include <stdio.h>
#include <stdlib.h>

#ifdef _MSC_VER
# include <CrtDbg.h>
#endif /* _MSC_VER */

//#define USE_ENUMVARIANT
#define USE_ENUMENTRY

/* 
 * Helper functions
 */

template<typename S>
S &operator <<(S &s, CComBSTR const &bstr)
{
    wchar_t const   *str = bstr;

    return s << str;
}

namespace comstl
{
    inline CComBSTR &transfer_resource(CComBSTR &r, BSTR v)
    {
        comstl_message_assert("Resource destination not empty!", NULL == r.m_str);
        r.m_str = v;

        return r;
    }
}

/* 
 * Forward declarations
 */

static void usage(int bExit, char const *reason);
int processRoot(IFileSearch *search, CComBSTR const &rootDir, CComBSTR const &pattern, long flags, int bSuccinct, int bFTP);
int processRoot(IFtpSearch *search, CComBSTR const &host, CComBSTR const &username, CComBSTR const &password, CComBSTR const &rootDir, CComBSTR const &pattern, long flags, int bSuccinct, int bFTP);
int processCollection(ISearchCollection *psc, long flags, int bSuccinct, int bFTP);

/* 
 * Main
 */

int main(int argc, char *argv[])
{
#if 0
    ::Sleep(100000);
#endif /* 0 */

#if defined(_MSC_VER) && \
    defined(_DEBUG)
    _CrtMemState    memState;
#endif /* _MSC_VER && _MSC_VER */
    int             iRet            =   0;
    int             i;
    int             totalFound      =   0;
    int             bAllHardDrives  =   false;
    char const      *host           =   NULL;
    char const      *username       =   NULL;
    char const      *password       =   NULL;
    char const      *pattern        =   NULL;
    char const      *rootDir        =   NULL;
    long            flags           =   RECLS_F_RECURSIVE;
    int             bSuccinct       =   false;

    for(i = 1; i < argc; ++i)
    {
        const char  *arg    =   argv[i];

        if(arg[0] == '-')
        {
            if(arg[1] == '-')
            {
                /* -- arguments */
            }
            else
            {
                /* - arguments */
                switch(arg[1])
                {
                    case    '?':
                        usage(1, NULL);
                        break;
                    case    'R':    /* Do not recurse */
                        flags &= ~(RECLS_F_RECURSIVE);
                        break;
                    case    'p':    /* Show directory parts */
                        flags |= RECLS_F_DIRECTORY_PARTS;
                        break;
                    case    'f':    /* Find files */
                        flags |= RECLS_F_FILES;
                        break;
                    case    'd':    /* Find directories */
                        flags |= RECLS_F_DIRECTORIES;
                        break;
                    case    'h':    /* Searches from hard drives */
                        bAllHardDrives = true;
                        break;
                    case    's':    /* Show only the full path; WHEREIS functionality */
                        bSuccinct = true;
                        break;
                    case    'H':    /* FTP host */
                        host = arg + 2;
                        break;
                    case    'U':    /* FTP username */
                        username = arg + 2;
                        break;
                    case    'P':    /* FTP password */
                        password = arg + 2;
                        break;
                    default:
                        usage(1, "Invalid argument(s) specified");
                        break;
                }
            }
        }
        else
        {
            /* other arguments */
            if(NULL == pattern)
            {
                pattern = arg;
            }
            else if(NULL == rootDir)
            {
                rootDir = arg;
            }
            else
            {
                usage(1, "Invalid argument(s) specified");
            }
        }
    }

    if( NULL != password &&
        (   NULL == host ||
            NULL == username))
    {
        usage(1, "Must specify host and username if specifying password");
    }

    if( NULL != username &&
        NULL == host)
    {
        usage(1, "Must specify host if specifying username");
    }

    if( NULL != host &&
        bAllHardDrives)
    {
        usage(1, "-h flag meaningless to FTP searches");
    }

    if( NULL != host &&
        NULL == rootDir)
    {
        usage(1, "Must specify a root directory for FTP searches");
    }

#if defined(_MSC_VER) && \
    defined(_DEBUG)
    _CrtMemCheckpoint(&memState);
#endif /* _MSC_VER && _MSC_VER */

    // Search for files if neither files or directories specified
    //
    // Even though this is not necessary, because the recls API provides the
    // same interpretation, it's best to be explicit.
    if(0 == (flags & (RECLS_F_FILES | RECLS_F_DIRECTORIES)))
    {
        flags |= RECLS_F_FILES;
    }

#if 0
    if(NULL == pattern)
    {
        pattern = Recls_GetWildcardsAll();
    }
#endif /* 0 */

    if(NULL == rootDir)
    {
        rootDir = ".";
    }

    if(NULL != host)
    {
        IFtpSearch             *search;
        comstl::com_initialiser init;
        HRESULT                 hr      =   ::CoCreateInstance(CLSID_FileSearch, NULL, CLSCTX_ALL, IID_IFtpSearch, (void**)&search);

        if(FAILED(hr))
        {
            cerr << "Failed to load the recls COM server! Please check your installation" << endl;
        }
        else
        {
//            CComBSTR    bstrPattern = comstl::method_cast<CComBSTR>(search, &IFileSearch::get_WildcardsAll);

            // The ATL conversion is not to be trusted for early versions, so we do it here.
            winstl::a2w host_(host);
            winstl::a2w username_(username);
            winstl::a2w password_(password);
            winstl::a2w rootDir_(rootDir);
            winstl::a2w pattern_(pattern);

            CComBSTR    bstrHost(stlsoft::c_str_ptr(host));
            CComBSTR    bstrUsername(stlsoft::c_str_ptr(username));
            CComBSTR    bstrPassword(stlsoft::c_str_ptr(password));
            CComBSTR    bstrRootDir(stlsoft::c_str_ptr(rootDir));
            CComBSTR    bstrPattern(stlsoft::c_str_ptr(pattern));

            if(0 == stlsoft::c_str_len(bstrPattern))
            {
                bstrPattern = L"*";
            }

            totalFound = processRoot(search, bstrHost, bstrUsername, bstrPassword, bstrRootDir, bstrPattern, flags, bSuccinct, true);

            search->Release();
        }
    }
    else
    {
        IFileSearch             *search;
        comstl::com_initialiser init;
        HRESULT                 hr      =   ::CoCreateInstance(CLSID_FileSearch, NULL, CLSCTX_ALL, IID_IFileSearch, (void**)&search);

        if(FAILED(hr))
        {
            cerr << "Failed to load the recls COM server! Please check your installation" << endl;
        }
        else
        {
            winstl::a2w pattern_(pattern);
            CComBSTR    bstrPattern(stlsoft::c_str_ptr(pattern));

            if(0 == stlsoft::c_str_len(bstrPattern))
            {
                bstrPattern = comstl::method_cast<CComBSTR>(search, &IFileSearch::get_WildcardsAll);;
            }

            if(bAllHardDrives)
            {
                LPUNKNOWN   punkRoots;

                hr = search->get_Roots(&punkRoots);

                if(SUCCEEDED(hr))
                {
                    typedef comstl::enumerator_sequence<IEnumString, LPOLESTR, comstl::LPOLESTR_policy> enum_sequence_t;

                    enum_sequence_t             roots(comstl::interface_cast_addref<LPENUMSTRING>(punkRoots), false);
                    enum_sequence_t::iterator   begin   =   roots.begin();
                    enum_sequence_t::iterator   end     =   roots.end();

                    for(; begin != end; ++begin)
                    {
                        totalFound += processRoot(search, *begin, bstrPattern, flags, bSuccinct, false);
                    }

                    punkRoots->Release();
                }
            }
            else
            {
                winstl::a2w rootDir_(rootDir);
                CComBSTR    bstrRootDir(stlsoft::c_str_ptr(rootDir));

                totalFound = processRoot(search, bstrRootDir, bstrPattern, flags, bSuccinct, false);
            }

            search->Release();
        }
    }

    fprintf(stdout, "Total found: %d\n", totalFound);

#if defined(_MSC_VER) && \
    defined(_DEBUG)
    _CrtMemDumpAllObjectsSince(&memState);
#endif /* _MSC_VER && _MSC_VER */

    return iRet;
}

/* 
 * Function implementations
 */

void usage(int bExit, char const *reason)
{
    cerr << "recls COM (C++) Test Program: COM" << endl << endl;

    if(NULL != reason)
    {
        cerr << "  Error: " << reason << endl << endl;
    }

    cerr << "Usage: COM [-d] [-f] [-h] [-p] [-R] [-s] [-H<host>] [-U<username>] [-P<password>] [<pattern>] [<root-dir>]" << endl;
    cerr << "\t-R               -   does not recurse; recursive search is the default" << endl;
    cerr << "\t-p               -   evaluate and display directory parts" << endl;
    cerr << "\t-d               -   search for directories" << endl;
    cerr << "\t-f               -   search for files (this is the default, if -d is not specified" << endl;
    cerr << "\t-h               -   searches from hard drive roots. (Ignore <root-dir>.)" << endl;
    cerr << "\t-s               -   succinct; shows only the path" << endl;
    cerr << "\t-H<host>         -   performs an FTP search on the given host" << endl;
    cerr << "\t-U<username>     -   username to use to log on to <host>" << endl;
    cerr << "\t-P<password>     -   password to use to log on to <host>" << endl;
    cerr << "\t<pattern>        -   search pattern, e.g. \"*.cpp\"; default is to search for all files" << endl;
    cerr << "\t<root-dir>       -   root directory of search; default is current working directory" << endl;

    if(bExit)
    {
        exit(EXIT_FAILURE);
    }
}

int processRoot(IFtpSearch *search, CComBSTR const &host, CComBSTR const &username, CComBSTR const &password, CComBSTR const &rootDir, CComBSTR const &pattern, long flags, int bSuccinct, int bFTP)
{
    int         totalFound  =   0;
    IUnknown    *punkResults;
    HRESULT     hr          =   search->Search(host, username, password, rootDir, pattern, flags, &punkResults);

    if(SUCCEEDED(hr))
    {
        ISearchCollection   *psc = comstl::interface_cast_addref<ISearchCollection*>(punkResults);

        if(NULL != psc)
        {
            totalFound = processCollection(psc, flags, bSuccinct, bFTP);

            psc->Release();
        }

        punkResults->Release();
    }

    return totalFound;
}

int processRoot(IFileSearch *search, CComBSTR const &rootDir, CComBSTR const &pattern, long flags, int bSuccinct, int bFTP)
{
    int         totalFound  =   0;
    IUnknown    *punkResults;
    HRESULT     hr          =   search->Search(rootDir, pattern, flags, &punkResults);

    if(SUCCEEDED(hr))
    {
        ISearchCollection   *psc = comstl::interface_cast_addref<ISearchCollection*>(punkResults);

        if(NULL != psc)
        {
            totalFound = processCollection(psc, flags, bSuccinct, bFTP);

            psc->Release();
        }

        punkResults->Release();
    }

    return totalFound;
}

int processCollection(ISearchCollection *psc, long flags, int bSuccinct, int bFTP)
{
    int             totalFound      =   0;

#if defined(USE_ENUMVARIANT)
    typedef comstl::collection_sequence<    ISearchCollection
                                        ,   IEnumVARIANT
                                        ,   VARIANT
                                        ,   comstl::VARIANT_policy
                                        >           coll_seq_t;
#elif defined(USE_ENUMENTRY)
    typedef comstl::collection_sequence<    ISearchCollection
                                        ,   IEnumFileEntry
                                        ,   IFileEntry*
                                        ,   comstl::interface_policy<IFileEntry>
                                        >           coll_seq_t;
#else
# error Must specify USE_ENUMVARIANT or USE_ENUMENTRY
#endif /* 0 */

    coll_seq_t              collection(psc, true, bFTP ? 1 : 0);
    coll_seq_t::iterator    b   =   collection.begin();
    coll_seq_t::iterator    e   =   collection.end();

    for(; b != e; ++b)
    {
        ++totalFound;

#if defined(USE_ENUMVARIANT)
        IFileEntry  *pfe = comstl::interface_cast_addref<IFileEntry*>((*b).punkVal);
#elif defined(USE_ENUMENTRY)
        IFileEntry  *pfe = *b;
#else
# error Must specify USE_ENUMVARIANT or USE_ENUMENTRY
#endif /* 0 */

        CComBSTR    path                    =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_Path);
        OLECHAR     drive                   =   ::comstl::method_cast<OLECHAR>(pfe, &IFileEntry::get_Drive);
        CComBSTR    directory               =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_Directory);
        CComBSTR    directoryPath           =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_DirectoryPath);
        CComBSTR    uncDrive;
        LPUNKNOWN   directoryParts          =   ::comstl::method_cast<LPUNKNOWN>(pfe, &IFileEntry::get_DirectoryParts);
        CComBSTR    file                    =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_File);
        CComBSTR    shortFile               =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_ShortFile);
        CComBSTR    fileName                =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_FileName);
        CComBSTR    fileExt                 =   ::comstl::method_cast<CComBSTR>(pfe, &IFileEntry::get_FileExt);
        DATE        creationTime            =   ::comstl::method_cast<DATE>(pfe, &IFileEntry::get_CreationTime);
        DATE        modificationTime        =   ::comstl::method_cast<DATE>(pfe, &IFileEntry::get_ModificationTime);
        DATE        lastAccessTime          =   ::comstl::method_cast<DATE>(pfe, &IFileEntry::get_LastAccessTime);
        DATE        lastStatusChangeTime    =   ::comstl::method_cast<DATE>(pfe, &IFileEntry::get_LastStatusChangeTime);
        long        size                    =   ::comstl::method_cast<long>(pfe, &IFileEntry::get_Size);
        BOOL        isReadOnly              =   ::comstl::method_cast<BOOL>(pfe, &IFileEntry::get_IsReadOnly);
        BOOL        isDirectory             =   ::comstl::method_cast<BOOL>(pfe, &IFileEntry::get_IsDirectory);
        BOOL        isLink                  =   FALSE;
        BOOL        isUNC                   =   FALSE;

        if(::comstl::interface_cast_test<IFileEntry2*>(pfe))
        {
            IFileEntry2 *pfe2   =   ::comstl::interface_cast_addref<IFileEntry2*>(pfe);

            if(NULL != pfe2)
            {
                uncDrive            =   ::comstl::method_cast<CComBSTR>(pfe2, &IFileEntry2::get_UNCDrive);
                isLink              =   ::comstl::method_cast<BOOL>(pfe2, &IFileEntry2::get_IsLink);
                isUNC               =   ::comstl::method_cast<BOOL>(pfe2, &IFileEntry2::get_IsUNC);

                pfe2->Release();
            }
        }

        wcout << L"  " << path << endl;

        if(!bSuccinct)
        {
            int off = 0;

            wcout << L"  " << directoryPath << endl;
            if(isUNC)
            {
                wcout << L"  " << uncDrive << endl;
                off += uncDrive.Length();
            }
            else
            {
                wcout << L"  " << (wchar_t const *)winstl::a2w((char const*)&drive, 1) << endl;
                off += 2;
            }
            wcout << L"  " << std::setw(off + directory.Length()) << directory << std::setw(1) << endl;

            if( (flags & RECLS_F_DIRECTORY_PARTS) == RECLS_F_DIRECTORY_PARTS &&
                NULL != directoryParts)
            {
                typedef comstl::collection_sequence<    IDirectoryPartsCollection
                                                    ,   IEnumVARIANT
                                                    ,   VARIANT
                                                    ,   comstl::VARIANT_policy
                                                    ,   VARIANT const &
                                                    ,   comstl::forward_cloning_policy<IEnumVARIANT>
                                                    ,   2
                                                    >           parts_seq_t;

                parts_seq_t             dirParts(comstl::interface_cast_addref<IDirectoryPartsCollection*>(directoryParts), false);
                parts_seq_t::iterator   b   =   dirParts.begin();
                parts_seq_t::iterator   e   =   dirParts.end();

                for(; b != e; ++b)
                {
                    CComVariant vPart(*b);  vPart.ChangeType(VT_BSTR);
                    CComBSTR    dirPart(vPart.bstrVal);

                    off += dirPart.Length();
                    wcout << L"  " << std::setw(off) << dirPart << std::setw(1) << endl;
                }

                directoryParts->Release();
            }
            else
            {
                off += directory.Length();
            }

            off += file.Length();
            wcout << L"  " << std::setw(off) << file << std::setw(1) << endl;
            if(fileExt.Length() > 0)
            {
                wcout << L"  " << std::setw(off - (1 + fileExt.Length())) << fileName << std::setw(1) << endl;
                wcout << L"  " << std::setw(off) << fileExt << std::setw(1) << endl;
            }
            else
            {
                wcout << L"  " << std::setw(off) << fileName << std::setw(1) << endl;
            }

            if(isReadOnly)
            {
                wcout << L"    - Read-only" << endl;
            }
            if(isDirectory)
            {
                wcout << L"    - Directory" << endl;
            }
            else
            {
                wcout << L"    - File" << endl;
            }
            if(isLink)
            {
                wcout << L"    - Link" << endl;
            }
            if(isUNC)
            {
                wcout << L"    - UNC" << endl;
            }
        }

#if defined(USE_ENUMVARIANT)
        pfe->Release();
#endif /* USE_ENUMVARIANT */
    }

    return totalFound;
}


/* 
 * End of file
 */

VBClient.frm

This program uses the recls/COM mapping coclasses, implementing a recursive search for a given pattern, and other flags, from a given directory

VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Form1"
   ClientHeight    =   7320
   ClientLeft      =   45
   ClientTop       =   360
   ClientWidth     =   11550
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   7320
   ScaleWidth      =   11550
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.ListBox lstDirectoryParts 
      Height          =   2010
      Left            =   6360
      TabIndex        =   15
      Top             =   5040
      Width           =   5055
   End
   Begin VB.ListBox lstProperties 
      Height          =   2790
      Left            =   6360
      TabIndex        =   13
      Top             =   1800
      Width           =   5055
   End
   Begin VB.OptionButton rdoBoth 
      Caption         =   "&Both"
      Height          =   375
      Left            =   8160
      Style           =   1  'Graphical
      TabIndex        =   11
      Top             =   720
      Width           =   975
   End
   Begin VB.OptionButton rdoDirectories 
      Caption         =   "&Directories"
      Height          =   375
      Left            =   7080
      Style           =   1  'Graphical
      TabIndex        =   10
      Top             =   720
      Width           =   975
   End
   Begin VB.OptionButton rdoFiles 
      Caption         =   "&Files"
      Height          =   375
      Left            =   6120
      Style           =   1  'Graphical
      TabIndex        =   9
      Top             =   720
      Width           =   855
   End
   Begin VB.CheckBox chkRecursive 
      Caption         =   "Recursi&ve"
      Height          =   375
      Left            =   3360
      TabIndex        =   8
      Top             =   720
      Width           =   1215
   End
   Begin VB.CheckBox chkDirParts 
      Caption         =   "Directory P&arts"
      Height          =   375
      Left            =   4680
      TabIndex        =   7
      Top             =   720
      Width           =   1335
   End
   Begin VB.TextBox txtPattern 
      Height          =   375
      Left            =   1320
      TabIndex        =   5
      Text            =   "*.*"
      Top             =   720
      Width           =   1935
   End
   Begin VB.ListBox lstFiles 
      Height          =   5325
      Left            =   120
      TabIndex        =   3
      Top             =   1800
      Width           =   6135
   End
   Begin VB.CommandButton btnSearch 
      Caption         =   "&Search"
      Height          =   375
      Left            =   10080
      TabIndex        =   2
      Top             =   600
      Width           =   1335
   End
   Begin VB.TextBox txtSearchRoot 
      Height          =   375
      Left            =   1320
      TabIndex        =   1
      Text            =   "."
      Top             =   240
      Width           =   10095
   End
   Begin VB.Label Label5 
      Caption         =   "Directory pa&rts:"
      Height          =   255
      Left            =   6360
      TabIndex        =   14
      Top             =   4680
      Width           =   1815
   End
   Begin VB.Label Label4 
      Caption         =   "P&roperties:"
      Height          =   255
      Left            =   6360
      TabIndex        =   12
      Top             =   1440
      Width           =   1575
   End
   Begin VB.Label Label3 
      Caption         =   "F&iles:"
      Height          =   255
      Left            =   120
      TabIndex        =   6
      Top             =   1440
      Width           =   1335
   End
   Begin VB.Label Label2 
      Caption         =   "&Pattern:"
      Height          =   255
      Left            =   120
      TabIndex        =   4
      Top             =   840
      Width           =   975
   End
   Begin VB.Label Label1 
      Caption         =   "Search &root:"
      Height          =   255
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Private g_index As Integer
Private g_entries As Collection

Private Sub btnSearch_Click()

    Dim fs As New RECLS_COMLib.FileSearch

    Dim searchRoot As String
    Dim pattern As String
    Dim flags As Long

    Dim srch As Object

    ' Reset the collection
    Set g_entries = New Collection
    g_index = 0

    searchRoot = txtSearchRoot.Text
    pattern = txtPattern.Text
    flags = 0

    If chkRecursive.Value Then
        flags = flags Or RECLS_FLAG.RECLS_F_RECURSIVE
    End If

    If chkDirParts.Value Then
        flags = flags Or RECLS_FLAG.RECLS_F_DIRECTORY_PARTS
    End If

    If rdoBoth.Value = True Then
        flags = flags Or RECLS_FLAG.RECLS_F_FILES
        flags = flags Or RECLS_FLAG.RECLS_F_DIRECTORIES
    ElseIf rdoDirectories = True Then
        flags = flags Or RECLS_FLAG.RECLS_F_DIRECTORIES
    ElseIf rdoFiles = True Then
        flags = flags Or RECLS_FLAG.RECLS_F_FILES
    Else
        flags = flags Or RECLS_FLAG.RECLS_F_FILES
    End If
    

    Set srch = fs.Search(searchRoot, pattern, flags)

    lstFiles.Clear
    lstProperties.Clear
    lstDirectoryParts.Clear
    For Each entry In srch
        lstFiles.AddItem (entry)
        lstFiles.ItemData(lstFiles.NewIndex) = g_index
        
        g_entries.Add entry, CStr(g_index)
        g_index = g_index + 1
    Next

End Sub

Private Sub Form_Load()

    chkRecursive.Value = 1
    rdoFiles.Value = True

End Sub

Private Sub lstFiles_Click()

    Dim entry As RECLS_COMLib.FileEntry
    Dim index As Integer
    Dim dirParts As Object

    index = lstFiles.ItemData(lstFiles.ListIndex)

    Set entry = g_entries.Item(CStr(index))

    ' Do the properties
    lstProperties.Clear
    lstProperties.AddItem ("Drive: " & entry.Drive)
    lstProperties.AddItem ("Directory: " & entry.Directory)
    lstProperties.AddItem ("DirectoryPath: " & entry.DirectoryPath)
    lstProperties.AddItem ("File: " & entry.File)
    lstProperties.AddItem ("ShortFile: " & entry.ShortFile)
    lstProperties.AddItem ("FileName: " & entry.FileName)
    lstProperties.AddItem ("FileExt: " & entry.FileExt)
    lstProperties.AddItem ("CreationTime: " & entry.CreationTime)
    lstProperties.AddItem ("ModificationTime: " & entry.ModificationTime)
    lstProperties.AddItem ("LastAccessTime: " & entry.LastAccessTime)
    lstProperties.AddItem ("LastStatusChangeTime: " & entry.LastStatusChangeTime)
    lstProperties.AddItem ("Size: " & entry.Size)

    ' Do the directory parts
    Set dirParts = entry.DirectoryParts

    lstDirectoryParts.Clear
    For Each dirPart In dirParts
        lstDirectoryParts.AddItem (dirPart)
    Next

End Sub

recls_test_1.d

This program uses the free API functions in the recls/D mapping, implementing a recursive search for a given pattern, and other flags, from a given directory

/* 
 * File:        recls_test_1.d
 *
 * Purpose:     Test program for the D mapping of recls. (Now the std.recls 
 *              module in the D standard library). Test free-functions.
 *
 * Created      24th November 2003
 * Updated:     30th September 2004
 *
 * Status:      Wizard-generated
 *
 * License:     (Licensed under the Synesis Software Open License)
 *
 *              Copyright (C) 2003-2004, Matthew Wilson.
 *              All rights reserved.
 *
 *              www:        http://www.synesis.com.au/software
 *
 *              email:      software@synesis.com.au
 *
 *              This source code is placed into the public domain 2004
 *              by Matthew Wilson. There are no restrictions
 *              whatsoever to your use of the software. 
 *
 *              This source code is provided by Matthew Wilson "as is"
 *              and any warranties, whether expressed or implied, including, but
 *              not limited to, the implied warranties of merchantability and
 *              fitness for a particular purpose are disclaimed. In no event
 *              shall the Matthew Wilson be liable for any direct,
 *              indirect, incidental, special, exemplary, or consequential
 *              damages (including, but not limited to, procurement of
 *              substitute goods or services; loss of use, data, or profits; or
 *              business interruption) however caused and on any theory of
 *              liability, whether in contract, strict liability, or tort
 *              (including negligence or otherwise) arising in any way out of
 *              the use of this software, even if advised of the possibility of
 *              such damage. 
 *
 *              Neither the name of Matthew Wilson nor the names of
 *              any subdivisions, employees or agents of Matthew Wilson, nor the
 *              names of any other contributors to this software
 *              may be used to endorse or promote products derived from this
 *              software without specific prior written permission. 
 *
 * 


import std.recls;
import std.string;
import std.c.stdio;
import std.c.stdlib;

int main(char[][] args)
{
    int                 iRet        =   0;
    int                 i;
    char[]              host        =   null;
    char[]              username    =   null;
    char[]              password    =   null;
    char[]              pattern     =   null;
    char[]              searchRoot  =   null;
    recls_rc_t          rc;
    recls_uint32_t      flags       =   RECLS_FLAG.RECLS_F_RECURSIVE;
    int                 bSuccinct   =   false;

    for(i = 1; i < args.length; ++i)
    {
        char[]  arg = args[i];

        if(arg[0] == '-')
        {
            if(arg[1] == '-')
            {
                /* -- arguments */
            }
            else
            {
                /* - arguments */
                switch(arg[1])
                {
                    case    'd':    /* Find directories */
                        flags |= RECLS_FLAG.RECLS_F_DIRECTORIES;
                        break;
                    case    'f':    /* Find files */
                        flags |= RECLS_FLAG.RECLS_F_FILES;
                        break;
                    case    'p':    /* Show directory parts */
                        flags |= RECLS_FLAG.RECLS_F_DIRECTORY_PARTS;
                        break;
                    case    'R':    /* Do not recurse */
                        flags &= ~(RECLS_FLAG.RECLS_F_RECURSIVE);
                        break;
                    case    's':    /* Show only the full path; WHEREIS functionality */
                        bSuccinct = true;
                        break;
                    case    'H':
                        host = arg[2 .. arg.length];
                        break;
                    case    'U':
                        username = arg[2 .. arg.length];
                        break;
                    case    'P':
                        password = arg[2 .. arg.length];
                        break;
                    default:
                        usage(1);
                        break;
                }
            }
        }
        else
        {
            /* other arguments */
            if(null == pattern)
            {
                pattern = arg;
            }
            else if(null == searchRoot)
            {
                searchRoot = arg;
            }
            else
            {
                usage(1);
            }
        }
    }

    /* Search for files if neither files or directories specified/
     *
     * Even though this is not necessary, because the recls API provides the
     * same interpretation, it's best to be explicit.
     */
    if(0 == (flags & (RECLS_FLAG.RECLS_F_FILES | RECLS_FLAG.RECLS_F_DIRECTORIES)))
    {
        flags |= RECLS_FLAG.RECLS_F_FILES;
    }

    if(null == pattern)
    {
        pattern = "*";

        if(null === host)
        {
            pattern = std.recls.wildcardsAll();
        }
    }

    /* Initiate the search. */
    hrecls_t    hSrch;

    if(null === host)
    {
        if(null == searchRoot)
        {
            searchRoot = ".";
        }

        rc = Search_Create(searchRoot, pattern, flags, hSrch);
    }
    else
    {
        if(null == searchRoot)
        {
            searchRoot = "/";
        }

        rc = Search_CreateFtp(host, username, password, searchRoot, pattern, flags, hSrch);
    }

    if(RECLS_FAILED(rc))
    {
        char[]  err =   Search_GetErrorString(rc);

        fprintf(stderr, "Failed to start search, with pattern \"%.*s\"; recls error: %.*s\n", pattern, err);
    }
    else
    {
        /* Iterate through the items, until done */
        recls_info_t    entry;

        rc = Search_GetEntry(hSrch, entry);

        for(; RECLS_SUCCEEDED(rc); rc = Search_GetNextEntry(hSrch, entry))
        {
            int                 i;
            int                 off;
            int                 extLen;
            int                 cDirParts;
            char[]              path        =   Search_GetEntryPath(entry);
version(Windows)
{
            char                drive       =   Search_GetEntryDrive(entry);

            if('\0' != drive)
            {
                // This complex dance is necessitated because string and ctype seem
                // unable to coexist (with v0.74, anyway)
                if(drive != path[0])
                {
                    char    p0upper = toupper(path[0 .. 1])[0];
                    char    p0lower = tolower(path[0 .. 1])[0];

                    if(drive == p0upper)
                    {
                        drive = p0lower;
                    }
                    else
                    {
                        drive = p0upper;
                    }
                }
            }
}
            char[]              dir         =   Search_GetEntryDirectory(entry);
            char[]              dirPath     =   Search_GetEntryDirectoryPath(entry);
            char[]              file        =   Search_GetEntryFile(entry);
            char[]              fileName    =   Search_GetEntryFileName(entry);
            char[]              fileExt     =   Search_GetEntryFileExt(entry);

            char[]              pathCheck   =   "";
            char[]              dirCheck    =   "";
            char[]              fileCheck;
            recls_filesize_t    size        =   Search_GetEntrySize(entry);

version(Debug)
{
                recls_uint32_t  cBlocks;
                Search_OutstandingEntry(hSrch, &cBlocks);
                printf("\n%d outstanding blocks\n", cBlocks);
}

            printf("  %.*s\n", path);
            if(!bSuccinct)
            {
                printf("  %.*s\n", dirPath);
version(Windows)
{
                if('\0' != drive)
                {
                    printf("  %c\n", drive);
                    pathCheck ~= drive;
                    pathCheck ~= ':';
                }
}
                printf("  %.*s%.*s\n", (drive != '\0') * 2, cast(char*)"  ", dir);

                off = 0;
                if((flags & RECLS_FLAG.RECLS_F_DIRECTORY_PARTS) == RECLS_FLAG.RECLS_F_DIRECTORY_PARTS)
                {
                    char[][]    parts   =   Search_GetEntryDirectoryParts(entry);

                    foreach(char[] part; parts)
                    {
                        printf("    %*s", off, cast(char*)"");
                        printf("%.*s\n", part);
                        off += part.length;

                        pathCheck ~= part;
                        dirCheck ~= part;
                    }
                }
                else
                {
                    off += dir.length;
                    pathCheck ~= dir;
                }

                printf("    %*s%.*s\n", off, cast(char*)"", file);
                printf("    %*s%.*s\n", off, cast(char*)"", fileName);
                off     +=  file.length;
                extLen  =   fileExt.length;
                printf("    %*s%.*s\n", off - extLen, cast(char*)"", fileExt);
                fileCheck = fileName;
                if(0 < extLen)
                {
                    fileCheck ~= '.';
                    fileCheck ~= fileExt;
                }

                pathCheck ~= file;

                /* Now validate the components */
    version(Windows)
    {
                if(path != pathCheck)
                {
                    fprintf(stderr, "Path is different from path components\n\tpath:  %.*s\n\tpathCheck: %.*s\n\n", path, pathCheck);
                }
                assert(path == pathCheck);
    }
    else
    {
                if(path != pathCheck)
                {
                    fprintf(stderr, "Path is different from path components\n\tpath:  %.*s\n\tpathCheck: %.*s\n\n", path, pathCheck);
                }
                assert(path == pathCheck);
    }
    version(Windows)
    {
                if( (   '\0' != drive &&
                        (dirPath[0] != drive ||
                        dir != dirPath[2 .. dirPath.length])) ||
                    (   '\0' == drive &&
                        dirPath != dir))
                {
                    fprintf(stderr, "DirectoryPath is different from Directory\n\tdirPath:  %.*s (%d)\n\tdir:      %c:%.*s (%d)\n\n", dirPath, dirPath.length - 2, drive, dir, dir.length);
                }
                assert( (   '\0' != drive &&
                            dirPath[0] == drive &&
                            dir == dirPath[2 .. dirPath.length]) ||
                        (   '\0' == drive &&
                            dirPath == dir));
    }
    else
    {
                if(dirPath != dir)
                {
                    fprintf(stderr, "DirectoryPath is different from Directory\n\tdirPath:  %.*s\n\tdir: %.*s\n\n", dirPath, dir);
                }
                assert(dirPath == dir);
    }
                if((flags & RECLS_FLAG.RECLS_F_DIRECTORY_PARTS) == RECLS_FLAG.RECLS_F_DIRECTORY_PARTS)
                {
                    if(dir != dirCheck)
                    {
                        fprintf(stderr, "Directory is different from directory components\n\tdir:  %.*s\n\tdirCheck: %.*s\n\n", dir, dirCheck);
                    }
                    assert(dir == dirCheck);
                }
                if(file != fileCheck)
                {
                    fprintf(stderr, "File is different from file components\n\tfile:  %d:%.*s\n\tfileCheck: %d:%.*s\n\n", file.length, file, fileCheck.length, fileCheck);
                }
                assert(file == fileCheck);

                if(Search_IsEntryDirectory(entry))
                {
                    printf("    - Directory\n");
                }
                else
                {
                    printf("    - File\n");
                }
                if(Search_IsEntryReadOnly(entry))
                {
                    printf("    - Read-only\n");
                }
                if(Search_IsEntryLink(entry))
                {
                    printf("    - Link\n");
                }

                printf("    %lu\n", size);
            }

            Search_CloseEntry(entry);
        }

        if(rc != RECLS_RC_NO_MORE_DATA)
        {
            char[]  err =   Search_GetErrorString(rc);

            fprintf(stderr, "Search terminated prematurely; recls error: %.*s\n", err);
        }

        Search_Close(hSrch);
    }

    return iRet;
}

/* 
 * Function implementations
 */

void usage(int bExit)
{
    fprintf(stderr, "recls D Test Program: recls_test_1\n\n");
    fprintf(stderr, "Usage: recls_test_1 [-d] [-f] [-p] [-R] [-s] [-H<host>] [-U<username>] [-P<password>] [<pattern>] [<root-dir>]\n");
    fprintf(stderr, "\t-d               -   search for directories\n");
    fprintf(stderr, "\t-f               -   search for files. (default if neither f or d specified)\n");
    fprintf(stderr, "\t-p               -   include directory parts in search, and display\n");
    fprintf(stderr, "\t-R               -   does not recurse. (recursive search is the default)\n");
    fprintf(stderr, "\t-s               -   succinct; shows only the path\n");
    fprintf(stderr, "\t-H<host>         -   performs an FTP search on the given host\n");
    fprintf(stderr, "\t-U<username>     -   username to use to log on to <host>\n");
    fprintf(stderr, "\t-P<password>     -   password to use to log on to <host>\n");
    fprintf(stderr, "\t<pattern>        -   search pattern, e.g. \"*.cpp\" (default is to search for all files)\n");
    fprintf(stderr, "\t<root-dir>       -   root directory of search; default is current working directory\n");

    if(bExit)
    {
        exit(1);
    }
}

/* 
 * End of file
 */

recls_test_2.d

This program uses the classes in the recls/D mapping, implementing a recursive search for a given pattern, and other flags, from a given directory

/* 
 * File:        recls_test_1.d
 *
 * Purpose:     Test program for the D mapping of recls. (Now the std.recls 
 *              module in the D standard library). Test free-functions.
 *
 * Created      24th November 2003
 * Updated:     30th September 2004
 *
 * Status:      Wizard-generated
 *
 * License:     (Licensed under the Synesis Software Open License)
 *
 *              Copyright (C) 2003-2004, Matthew Wilson.
 *              All rights reserved.
 *
 *              www:        http://www.synesis.com.au/software
 *
 *              email:      software@synesis.com.au
 *
 *              This source code is placed into the public domain 2004
 *              by Matthew Wilson. There are no restrictions
 *              whatsoever to your use of the software. 
 *
 *              This source code is provided by Matthew Wilson "as is"
 *              and any warranties, whether expressed or implied, including, but
 *              not limited to, the implied warranties of merchantability and
 *              fitness for a particular purpose are disclaimed. In no event
 *              shall the Matthew Wilson be liable for any direct,
 *              indirect, incidental, special, exemplary, or consequential
 *              damages (including, but not limited to, procurement of
 *              substitute goods or services; loss of use, data, or profits; or
 *              business interruption) however caused and on any theory of
 *              liability, whether in contract, strict liability, or tort
 *              (including negligence or otherwise) arising in any way out of
 *              the use of this software, even if advised of the possibility of
 *              such damage. 
 *
 *              Neither the name of Matthew Wilson nor the names of
 *              any subdivisions, employees or agents of Matthew Wilson, nor the
 *              names of any other contributors to this software
 *              may be used to endorse or promote products derived from this
 *              software without specific prior written permission. 
 *
 * 


import std.recls;
import std.string;
import std.c.stdio;
import std.c.stdlib;

int main(char[][] args)
{
    int                 iRet        =   0;
    int                 i;
    char[]              host        =   null;
    char[]              username    =   null;
    char[]              password    =   null;
    char[]              pattern     =   null;
    char[]              searchRoot  =   null;
    recls_rc_t          rc;
    recls_uint32_t      flags       =   RECLS_FLAG.RECLS_F_RECURSIVE;
    int                 bSuccinct   =   false;

    for(i = 1; i < args.length; ++i)
    {
        char[]  arg = args[i];

        if(arg[0] == '-')
        {
            if(arg[1] == '-')
            {
                /* -- arguments */
            }
            else
            {
                /* - arguments */
                switch(arg[1])
                {
                    case    'd':    /* Find directories */
                        flags |= RECLS_FLAG.RECLS_F_DIRECTORIES;
                        break;
                    case    'f':    /* Find files */
                        flags |= RECLS_FLAG.RECLS_F_FILES;
                        break;
                    case    'p':    /* Show directory parts */
                        flags |= RECLS_FLAG.RECLS_F_DIRECTORY_PARTS;
                        break;
                    case    'R':    /* Do not recurse */
                        flags &= ~(RECLS_FLAG.RECLS_F_RECURSIVE);
                        break;
                    case    's':    /* Show only the full path; WHEREIS functionality */
                        bSuccinct = true;
                        break;
                    case    'H':
                        host = arg[2 .. arg.length];
                        break;
                    case    'U':
                        username = arg[2 .. arg.length];
                        break;
                    case    'P':
                        password = arg[2 .. arg.length];
                        break;
                    default:
                        usage(1);
                        break;
                }
            }
        }
        else
        {
            /* other arguments */
            if(null == pattern)
            {
                pattern = arg;
            }
            else if(null == searchRoot)
            {
                searchRoot = arg;
            }
            else
            {
                usage(1);
            }
        }
    }

    /* Search for files if neither files or directories specified/
     *
     * Even though this is not necessary, because the recls API provides the
     * same interpretation, it's best to be explicit.
     */
    if(0 == (flags & (RECLS_FLAG.RECLS_F_FILES | RECLS_FLAG.RECLS_F_DIRECTORIES)))
    {
        flags |= RECLS_FLAG.RECLS_F_FILES;
    }

    if(null == pattern)
    {
        pattern = "*";

        if(null === host)
        {
            pattern = std.recls.wildcardsAll();
        }
    }

    /* Initiate the search. */
    hrecls_t    hSrch;

    if(null === host)
    {
        if(null == searchRoot)
        {
            searchRoot = ".";
        }

        rc = Search_Create(searchRoot, pattern, flags, hSrch);
    }
    else
    {
        if(null == searchRoot)
        {
            searchRoot = "/";
        }

        rc = Search_CreateFtp(host, username, password, searchRoot, pattern, flags, hSrch);
    }

    if(RECLS_FAILED(rc))
    {
        char[]  err =   Search_GetErrorString(rc);

        fprintf(stderr, "Failed to start search, with pattern \"%.*s\"; recls error: %.*s\n", pattern, err);
    }
    else
    {
        /* Iterate through the items, until done */
        recls_info_t    entry;

        rc = Search_GetEntry(hSrch, entry);

        for(; RECLS_SUCCEEDED(rc); rc = Search_GetNextEntry(hSrch, entry))
        {
            int                 i;
            int                 off;
            int                 extLen;
            int                 cDirParts;
            char[]              path        =   Search_GetEntryPath(entry);
version(Windows)
{
            char                drive       =   Search_GetEntryDrive(entry);

            if('\0' != drive)
            {
                // This complex dance is necessitated because string and ctype seem
                // unable to coexist (with v0.74, anyway)
                if(drive != path[0])
                {
                    char    p0upper = toupper(path[0 .. 1])[0];
                    char    p0lower = tolower(path[0 .. 1])[0];

                    if(drive == p0upper)
                    {
                        drive = p0lower;
                    }
                    else
                    {
                        drive = p0upper;
                    }
                }
            }
}
            char[]              dir         =   Search_GetEntryDirectory(entry);
            char[]              dirPath     =   Search_GetEntryDirectoryPath(entry);
            char[]              file        =   Search_GetEntryFile(entry);
            char[]              fileName    =   Search_GetEntryFileName(entry);
            char[]              fileExt     =   Search_GetEntryFileExt(entry);

            char[]              pathCheck   =   "";
            char[]              dirCheck    =   "";
            char[]              fileCheck;
            recls_filesize_t    size        =   Search_GetEntrySize(entry);

version(Debug)
{
                recls_uint32_t  cBlocks;
                Search_OutstandingEntry(hSrch, &cBlocks);
                printf("\n%d outstanding blocks\n", cBlocks);
}

            printf("  %.*s\n", path);
            if(!bSuccinct)
            {
                printf("  %.*s\n", dirPath);
version(Windows)
{
                if('\0' != drive)
                {
                    printf("  %c\n", drive);
                    pathCheck ~= drive;
                    pathCheck ~= ':';
                }
}
                printf("  %.*s%.*s\n", (drive != '\0') * 2, cast(char*)"  ", dir);

                off = 0;
                if((flags & RECLS_FLAG.RECLS_F_DIRECTORY_PARTS) == RECLS_FLAG.RECLS_F_DIRECTORY_PARTS)
                {
                    char[][]    parts   =   Search_GetEntryDirectoryParts(entry);

                    foreach(char[] part; parts)
                    {
                        printf("    %*s", off, cast(char*)"");
                        printf("%.*s\n", part);
                        off += part.length;

                        pathCheck ~= part;
                        dirCheck ~= part;
                    }
                }
                else
                {
                    off += dir.length;
                    pathCheck ~= dir;
                }

                printf("    %*s%.*s\n", off, cast(char*)"", file);
                printf("    %*s%.*s\n", off, cast(char*)"", fileName);
                off     +=  file.length;
                extLen  =   fileExt.length;
                printf("    %*s%.*s\n", off - extLen, cast(char*)"", fileExt);
                fileCheck = fileName;
                if(0 < extLen)
                {
                    fileCheck ~= '.';
                    fileCheck ~= fileExt;
                }

                pathCheck ~= file;

                /* Now validate the components */
    version(Windows)
    {
                if(path != pathCheck)
                {
                    fprintf(stderr, "Path is different from path components\n\tpath:  %.*s\n\tpathCheck: %.*s\n\n", path, pathCheck);
                }
                assert(path == pathCheck);
    }
    else
    {
                if(path != pathCheck)
                {
                    fprintf(stderr, "Path is different from path components\n\tpath:  %.*s\n\tpathCheck: %.*s\n\n", path, pathCheck);
                }
                assert(path == pathCheck);
    }
    version(Windows)
    {
                if( (   '\0' != drive &&
                        (dirPath[0] != drive ||
                        dir != dirPath[2 .. dirPath.length])) ||
                    (   '\0' == drive &&
                        dirPath != dir))
                {
                    fprintf(stderr, "DirectoryPath is different from Directory\n\tdirPath:  %.*s (%d)\n\tdir:      %c:%.*s (%d)\n\n", dirPath, dirPath.length - 2, drive, dir, dir.length);
                }
                assert( (   '\0' != drive &&
                            dirPath[0] == drive &&
                            dir == dirPath[2 .. dirPath.length]) ||
                        (   '\0' == drive &&
                            dirPath == dir));
    }
    else
    {
                if(dirPath != dir)
                {
                    fprintf(stderr, "DirectoryPath is different from Directory\n\tdirPath:  %.*s\n\tdir: %.*s\n\n", dirPath, dir);
                }
                assert(dirPath == dir);
    }
                if((flags & RECLS_FLAG.RECLS_F_DIRECTORY_PARTS) == RECLS_FLAG.RECLS_F_DIRECTORY_PARTS)
                {
                    if(dir != dirCheck)
                    {
                        fprintf(stderr, "Directory is different from directory components\n\tdir:  %.*s\n\tdirCheck: %.*s\n\n", dir, dirCheck);
                    }
                    assert(dir == dirCheck);
                }
                if(file != fileCheck)
                {
                    fprintf(stderr, "File is different from file components\n\tfile:  %d:%.*s\n\tfileCheck: %d:%.*s\n\n", file.length, file, fileCheck.length, fileCheck);
                }
                assert(file == fileCheck);

                if(Search_IsEntryDirectory(entry))
                {
                    printf("    - Directory\n");
                }
                else
                {
                    printf("    - File\n");
                }
                if(Search_IsEntryReadOnly(entry))
                {
                    printf("    - Read-only\n");
                }
                if(Search_IsEntryLink(entry))
                {
                    printf("    - Link\n");
                }

                printf("    %lu\n", size);
            }

            Search_CloseEntry(entry);
        }

        if(rc != RECLS_RC_NO_MORE_DATA)
        {
            char[]  err =   Search_GetErrorString(rc);

            fprintf(stderr, "Search terminated prematurely; recls error: %.*s\n", err);
        }

        Search_Close(hSrch);
    }

    return iRet;
}

/* 
 * Function implementations
 */

void usage(int bExit)
{
    fprintf(stderr, "recls D Test Program: recls_test_1\n\n");
    fprintf(stderr, "Usage: recls_test_1 [-d] [-f] [-p] [-R] [-s] [-H<host>] [-U<username>] [-P<password>] [<pattern>] [<root-dir>]\n");
    fprintf(stderr, "\t-d               -   search for directories\n");
    fprintf(stderr, "\t-f               -   search for files. (default if neither f or d specified)\n");
    fprintf(stderr, "\t-p               -   include directory parts in search, and display\n");
    fprintf(stderr, "\t-R               -   does not recurse. (recursive search is the default)\n");
    fprintf(stderr, "\t-s               -   succinct; shows only the path\n");
    fprintf(stderr, "\t-H<host>         -   performs an FTP search on the given host\n");
    fprintf(stderr, "\t-U<username>     -   username to use to log on to <host>\n");
    fprintf(stderr, "\t-P<password>     -   password to use to log on to <host>\n");
    fprintf(stderr, "\t<pattern>        -   search pattern, e.g. \"*.cpp\" (default is to search for all files)\n");
    fprintf(stderr, "\t<root-dir>       -   root directory of search; default is current working directory\n");

    if(bExit)
    {
        exit(1);
    }
}

/* 
 * End of file
 */

recls_test.java

This program uses the classes in the recls/Java mapping, implementing a recursive search for a given pattern, and other flags, from a given directory

/* 
 * File:        recls_test.java
 *
 * Purpose:     Test file for the recls Java mapping.
 *
 * Created:     22nd November 2003
 * Updated:     15th March 2005
 *
 * Status:      Wizard-generated
 *
 * License:     (Licensed under the Synesis Software Open License)
 *
 *              Copyright (C) 1999-2003, Synesis Software Pty Ltd.
 *              All rights reserved.
 *
 *              www:        http://www.synesis.com.au/software
 *
 *              email:      software@synesis.com.au
 *
 *              This source code is placed into the public domain 2003
 *              by Synesis Software Pty Ltd. There are no restrictions
 *              whatsoever to your use of the software. 
 *
 *              This source code is provided by Synesis Software Pty Ltd "as is"
 *              and any warranties, whether expressed or implied, including, but
 *              not limited to, the implied warranties of merchantability and
 *              fitness for a particular purpose are disclaimed. In no event
 *              shall the Synesis Software Pty Ltd be liable for any direct,
 *              indirect, incidental, special, exemplary, or consequential
 *              damages (including, but not limited to, procurement of
 *              substitute goods or services; loss of use, data, or profits; or
 *              business interruption) however caused and on any theory of
 *              liability, whether in contract, strict liability, or tort
 *              (including negligence or otherwise) arising in any way out of
 *              the use of this software, even if advised of the possibility of
 *              such damage. 
 *
 *              Neither the name of Synesis Software Pty Ltd nor the names of
 *              any subdivisions, employees or agents of Synesis Software Pty
 *              Ltd, nor the names of any other contributors to this software
 *              may be used to endorse or promote products derived from this
 *              software without specific prior written permission. 
 *
 */


import org.recls.Entry;
import org.recls.ReclsException;
import org.recls.Search;
import org.recls.FileSearch;
import org.recls.FtpSearch;

import java.util.Enumeration;

public class recls_test
{
    public static void main(String[] args)
    {
        int     i;
        String  host        =   null;
        String  username    =   null;
        String  password    =   null;
        String  pattern     =   null;
        String  rootDir     =   null;
        int     flags       =   Search.RECLS_F_RECURSIVE;
        boolean bSuccinct   =   false;

/*
        for(i = 0; i < args.length; ++i)
        {
            String  arg = args[i];

            System.out.println(i + ": " + arg);
        }
        System.exit(0);
*/

        for(i = 0; i < args.length; ++i)
        {
            String  arg = args[i];

            if(arg.charAt(0) == '-')
            {
                if(arg.charAt(1) == '-')
                {
                    /* -- arguments */
                }
                else
                {
                    /* - arguments */
                    switch(arg.charAt(1))
                    {
                        case    'R':    /* Do not recurse */
                            flags &= ~(Search.RECLS_F_RECURSIVE);
                            break;
                        case    'p':    /* Show directory parts */
                            flags |= Search.RECLS_F_DIRECTORY_PARTS;
                            break;
                        case    'f':    /* Find files */
                            flags |= Search.RECLS_F_FILES;
                            break;
                        case    'd':    /* Find directories */
                            flags |= Search.RECLS_F_DIRECTORIES;
                            break;
                        case    's':    /* Show only the full path; WHEREIS functionality */
                            bSuccinct = true;
                            break;
                        case    'H':
                            host = arg.substring(2);
                            break;
                        default:
                            usage("Unrecognised argument: " + arg);
                            break;
                    }
                }
            }
            else
            {
                /* other arguments */
                if(null == pattern)
                {
                    pattern = arg;
                }
                else if(null == rootDir)
                {
                    rootDir = arg;
                }
                else
                {
                     usage("Unrecognised argument: " + arg);
                }
            }
        }

        /* Search for files if neither files or directories specified/
         *
         * Even though this is not necessary, because the recls API provides the
         * same interpretation, it's best to be explicit.
         */
        if(0 == (flags & (Search.RECLS_F_FILES | Search.RECLS_F_DIRECTORIES)))
        {
            flags |= Search.RECLS_F_FILES;
        }

        Entry local =   FileSearch.Stat(".", 0);

        System.out.println("Local dir: " + local.getPath());

        try
        {
            int     total   =   0;
            Search  search;

            if(null != host)
            {
                search  =   new FtpSearch(host, username, password, rootDir, pattern, flags);
            }
            else
            {
                search  =   new FileSearch(rootDir, pattern, flags);
            }

            for(Enumeration en = search; en.hasMoreElements(); ++total)
            {
                Object  el  =   en.nextElement();

                System.out.println(el);

                if(!bSuccinct)
                {
                    Entry   entry   =   (Entry)el;

                    System.out.println("  Path:                  " + entry.getPath());
                    System.out.println("  Drive:                 " + entry.getDrive());
                    System.out.println("  Directory:             " + entry.getDirectory());
                    System.out.println("  DirectoryPath:         " + entry.getDirectoryPath());
                    System.out.println("  UNCDrive:              " + entry.getUNCDrive());
                    if((flags & Search.RECLS_F_DIRECTORY_PARTS) == Search.RECLS_F_DIRECTORY_PARTS)
                    {
                        String[]    dirParts    =   entry.getDirectoryParts();
                        for(int j = 0; j < dirParts.length; ++j)
                        {
                            System.out.println("    " + dirParts[j]);
                        }
                    }
                    System.out.println("  File:                  " + entry.getFile());
                    System.out.println("  ShortFile:             " + entry.getShortFile());
                    System.out.println("  FileName:              " + entry.getFileName());
                    System.out.println("  FileExt:               " + entry.getFileExt());
                    System.out.println("  Size:                  " + entry.getSize());
                    System.out.println("  CreationTime:          " + entry.getCreationTime());
                    System.out.println("  ModificationTime:      " + entry.getModificationTime());
                    System.out.println("  LastAccessTime:        " + entry.getLastAccessTime());
                    System.out.println("  LastStatusChangeTime:  " + entry.getLastStatusChangeTime());
                    System.out.println("  isReadOnly:            " + entry.isReadOnly());
                    System.out.println("  isDirectory:           " + entry.isDirectory());
                    System.out.println("  isLink:                " + entry.isLink());
                    System.out.println("  isUNC:                 " + entry.isUNC());
                }
            }

            search.close();

            System.out.println("  Total matched: " + total);
        }
        catch(ReclsException x)
        {
            System.out.println(x);
        }
    }

    private static void usage(String message)
    {
        System.err.println("recls Java Test Program: java_test\n");
        System.err.println("");
        if(message != null)
        {
            System.err.println("  Error: " + message);
            System.err.println("");
        }
        System.err.println("Usage: java java_test [-d] [-f] [-d] [-R] [-H<host>] [<pattern>] [<root-dir>]");
        System.err.println("\t-d               -   search for directories");
        System.err.println("\t-f               -   search for files. (default if neither f or d specified)");
        System.err.println("\t-H               -   search for files using FTP on the given <host>");
        System.err.println("\t-p               -   include directory parts in search, and display");
        System.err.println("\t-R               -   does not recurse. (recursive search is the default)");
        System.err.println("\t-s               -   succinct; shows only the path");
        System.err.println("\t<pattern>        -   search pattern, e.g. \"*.cpp\" (default is to search for all files)");
        System.err.println("\t<root-dir>       -   root directory of search; default is current working directory");

        System.exit(1);
    }
}

recls_test.py

This program uses the recls/Python mapping classes, implementing a recursive search for a given pattern, from a given directory

import recls
import string
from sys import exit
import time

def dumpEntry(entry_):
        print "Path:                  " + entry_.path
        print "UNC Drive:             " + entry_.uncDrive
        print "Directory:             " + entry_.directory
        print "DirectoryPath:         " + entry_.directoryPath
        print "Drive:                 " + entry_.drive
        parts           =       entry_.directoryParts
        lenDrive        =       len(entry_.drive)
        lenUNCDrive     =       len(entry_.uncDrive)
        if 0 != lenUNCDrive:
                off = lenUNCDrive
        elif 0 != lenDrive:
                off = 2
        else:
                off = 0
        print "len(drive):    " + str(lenDrive)
        print "len(uncDrive): " + str(lenUNCDrive)
        if parts:
                print "DirectoryParts:"
                for part in parts:
                        print "                     ",
                        print string.rjust("", off),
                        print part
                        off = off + len(part)
        print "Size:                  " + str(entry_.size)
        print "File:                  " + entry_.file
        print "ShortFile:             " + entry_.shortFile
        print "FileName:              " + entry_.fileName
        print "FileExt:               " + entry_.fileExt
        print "Creation Time:         " + time.strftime("%d %b %Y %H:%M:%S", time.gmtime(entry_.creationTime))
        print "Modification Time:     " + time.strftime("%d %b %Y %H:%M:%S", time.gmtime(entry_.modificationTime))
        print "LastAccess Time:       " + time.strftime("%d %b %Y %H:%M:%S", time.gmtime(entry_.lastAccessTime))
        print "LastStatusChange Time: " + time.strftime("%d %b %Y %H:%M:%S", time.gmtime(entry_.lastStatusChangeTime))

# end dumpEntry()


print "recls version:        " + recls.__recls_version__
print "recls/Python version: " + recls.__version__

#dumpEntry(recls.stat("ftp:x"))

rootDir =       "."
pattern =       "*.*"
#rootDir        =       "X:\\"
#rootDir        =       "/freelibs/recls"
#pattern        =       "*.pdf"

print 'Searching: "' + rootDir + '" for "' + pattern + '"'

srch = recls.filesearch(rootDir, pattern, recls.DIRECTORY_PARTS | recls.FILES | recls.RECURSIVE)

print "Search::rootDir:  " + srch.rootDir
print "Search::pattern:  " + srch.pattern
print "Search::flags:    " + hex(srch.flags)

#print "Search:    " + str(srch)

#print "Search::items():  " + str(srch.items())

for entry in srch.items():
#       print "Item: " + entry.path
        dumpEntry(entry)
        print ""

print
print
print

exit(0)

srch = recls.ftpsearch("ftp.digitalmars.com", "anonymous", "a@b.c", "/", "*.zip", recls.DIRECTORY_PARTS | recls.FILES | recls.RECURSIVE)
for entry in srch.items():
#       print "Item: " + entry.path
        dumpEntry(entry)
        print ""



recls_test.rb

This program uses the recls/Ruby mapping classes, implementing a recursive search for a given pattern, from a given directory

################################################################################
# File:     test.rb
#
# Purpose:  Test program for the recls-Ruby mapping
#
# Created:  15th March 2004
# Updated:  12th April 2004
#
# Author:   Matthew Wilson
#
# License:  (Licensed under the Synesis Software Open License)
#
#           Copyright (C) 1999-$$PROJ_YEAR$$, Synesis Software Pty Ltd.
#           All rights reserved.
#
#           www:        http://recls.org
#                       http://synesis.com.au/software
#
#           email:      software@synesis.com.au
#
################################################################################

################################################################################
# Imports

require "recls"

################################################################################
# Functions

# Displays the usage, and optionally aborts the program

def usage(do_abort)
    print "recls Ruby Test Program\n\n"
    print "Usage: test.rb [-d] [-f] [-h] [-p] [-s] [-R] [-H<host>] <pattern> [<root-dir>]\n"
    printf "\t-d               -   search for directories\n"
    printf "\t-f               -   search for files (this is the default, if -d is not specified)\n"
    printf "\t-h               -   search in the roots of all drives on the system. Ignore <root-dir>\n"
    printf "\t-H               -   search the FTP <host>\n"
    printf "\t-p               -   evaluate and display directory parts\n"
    printf "\t-s               -   succinct; shows only the path\n"
    printf "\t-R               -   does not recurse; recursive search is the default\n"
    printf "\t<pattern>        -   search pattern, e.g. \"*.cpp\" (default is to search for all files)\n"
    printf "\t<root-dir>       -   root directory of search; default is current working directory\n"
    if(do_abort)
        abort
    end
end # usage()


# Performs the search, within the given root, according to the given criteria

def doSearch(host, username, password, root, pattern, flags, succinct)

        if host
        fs = Recls::FtpSearch::new(host, username, password, root, pattern, flags)
        else
        fs = Recls::FileSearch::new(root, pattern, flags)
        end

    print "Searching for \"" + pattern + "\" in \"" + root + "\"\n" if !succinct

    # Local function, used to pad the output

    def getPad(len)
        return "".rjust(len)
    end

    # The enumeration of the contents, and their display

    prefix = succinct ? "" : "  ";

    fs.each \
    { |fe| 
        puts prefix + String(fe)
        if !succinct
            puts prefix + fe.directoryPath

            puts prefix + fe.drive

            puts prefix + "  " + fe.directory

            # Directory parts
            dir_off = 2
            fe.directoryParts.each \
            { |dp| 
                puts prefix + getPad(dir_off) + dp
                dir_off = dir_off + dp.length
            }

            # file, shortFile, fileName, fileExt
            file_off = 2 + fe.directory.length
            puts prefix + getPad(file_off) + fe.file
            if fe.shortFile.length > 0
                puts prefix + getPad(file_off) + fe.shortFile
            end
            puts prefix + getPad(file_off) + fe.fileName
            if fe.fileExt.length > 0
                puts prefix + getPad(file_off + fe.fileName.length) + "." + fe.fileExt
            end

            puts prefix + "  " + String(fe.size) + " byte(s)"

            puts prefix + "  " + "Created:            " + fe.creationTime.strftime("%x %X")
            puts prefix + "  " + "Modified:           " + fe.modificationTime.strftime("%x %X")
            puts prefix + "  " + "Last Accessed:      " + fe.lastAccessTime.strftime("%x %X")
            puts prefix + "  " + "Last Status Change: " + fe.lastStatusChangeTime.strftime("%x %X")

            puts prefix + "  " + "Read-only"   if fe.isReadOnly
            puts prefix + "  " + "Directory"   if fe.isDirectory
            puts prefix + "  " + "Link"        if fe.isLink

        end
    }

    # Collecting the names only
#   names = fs.collect { |fe| fe.file }
#   puts "Collected files: "
#   names.each { |name| puts "  " + name }

    # Shows the 'min' and 'max' values
#   puts "'Minimum' item:"
#   puts "  " + fs.min.to_s
#   puts "'Maximum' item:"
#   puts "  " + fs.max.to_s

    # Selecting the read-only items
#   puts "Read-only items:"
#   ro_items = fs.select { |fe| fe.isReadOnly }
#   ro_items.each { |fe| puts "  " + fe.to_s }

    # 'Sorting' the items
#   puts "Sorted items:"
#   sorted_items = fs.sort
#   sorted_items.each { |fe| puts "  " + fe.to_s }

end # doSearch()

################################################################################
# main

flags           =   Recls::RECLS_F_RECURSIVE    # Default is recursive
succinct        =   false                       # Default is verbose
bAllHardDrives  =   false                       # Default is to use a single root

host                    =       nil
username                =       ""
password                =       ""

# Select the options
options     =   ARGV.select do |o|
    o[0, 1] == '-'
end

# Select the arguments
args        =   ARGV.select do |o|
    o[0, 1] != '-'
end

# Process the options
options.each \
{ |arg| 
    succinct = true if arg == "-s"
    flags |= Recls::RECLS_F_FILES           if arg == "-f"
    flags |= Recls::RECLS_F_DIRECTORIES     if arg == "-d"
    flags |= Recls::RECLS_F_DIRECTORY_PARTS if arg == "-p"
    flags &= ~Recls::RECLS_F_RECURSIVE      if arg == "-D"
    bAllHardDrives = true                   if arg == "-h"
        host = arg.slice(2..arg.length)                 if arg.slice(0 .. 1) == "-H"
    if arg == "-?"
        usage(true)
    end
}

usage(true) if 0 == args.length

pattern     =   args.shift
searchRoot  =   args.shift || ""

# Now either process for roots, or the given root

print "recls version: " + Recls::RECLS_VERSION + "\n" if !succinct

if host
                #               searchRoot = "/"
end

if(bAllHardDrives)
    Recls.roots.each \
    { | root |
        doSearch(host, username, password, root, pattern, flags, succinct)
    }
else
    doSearch(host, username, password, searchRoot, pattern, flags, succinct)
end

################################################################################

STL.cpp

This program uses the recls/STL mapping classes, implementing a recursive search for a given pattern, from a given directory


recls Library documentation © Synesis Software Pty Ltd, 2001-2005