🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5755

Re: Read all dirs (with wildcards)

#5755
From: Ed Mulroy
Date: Mon, 11 Jul 2005 14:32
67 lines
3052 bytes
> dir *soft

So that would include all directories whose name includes "soft" which have 
either a string terminator, a '\0' or a period, a '.', following the 't'.

You can search by using the Windows API functions FindFirstFile, 
FindNextFile and FindClose.  It is convenient to put the list of names found 
into a vector of strings.

This is written to look in the root of C: and should be close.  Untested.

--------------------
#include <windows.h>
#include <vector>

typedef std::vector<std::string> string_vector;

bool FindSofts(string_vector & results)
    {
    WIN32_FIND_DATA wfd;
    char *fname = wfd.cFileName;
    char  low_name[MAX_PATH];
    HANDLE find_hand = FindFirstFile("c:\\*.*", &wfd);

    results.clear(); // empty the directories list

    if (find_hand != INVALID_HANDLE_VALUE)
        {
        do // loop to find directories
          {
          if (!(attribs & FILE_ATTRIBUTE_DIRECTORY)
              {
              continue; // if not a directory, skip to find next one
              }

          strcpy(low_name, fname); // make copy of name
          strlwr(low_name); // force copy to lower case

          char *found = strstr(low_name, "soft"); // find "soft" in name

          // if something was found
          // and the word "soft" is the end of the name
          // or "soft" followed by a period
          if (found && (!found[5] || !strcmp(found, "soft.")))
              {
              results.push_back(fname); // add the name to the list
              }
          } while (FindNextFile(find_hand, &wfd));

        FindClose(find_hand); // close file search handle
        }

    return results.size() > 0; // return true/false on if any were found
    }
--------------------

.  Ed

> Jason wrote in message
> news:42d27bfe$1@newsgroups.borland.com...
>
> I want to see all directories in that contains the word "soft" on the end 
> something like
>
> dir *soft
>
> how can I get this with code?
Technical Details
Message-ID: <42d282ec@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!atl-c07.usenetserver.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42d27bfe$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fcae796750f56a3e
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ed Mulroy" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <42d27bfe$1@newsgroups.borland.com>
Subject: Re: Read all dirs (with wildcards)
Date: Mon, 11 Jul 2005 10:32:08 -0400
Lines: 69
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 4.238.209.75
Message-ID: <42d282ec@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1121092332 4.238.209.75 (11 Jul 2005 07:32:12 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!atl-c02.usenetserver.com!atl-c07.usenetserver.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail