Listing files

Posted on 2004-04-07
Last Modified: 2010-04-01

I have a need to retrieve a list of files matching a search regular expression. The platform is either Visual C++ 6.0 on win32 or gcc 3.3 on Solaris 8. I understand that the solution may differ between the platforms.

Currently I'm using the system() function call to call "dir /B searchpattern > tmp.dir" or "ls -1 searchpattern >" and then read and delete the resulting file (e.g.: "dir /B ..\wnp*.log > tmp.dir"). However, I'm not at all satisfied with:
a: having to create a temporary file;
b: having to perform file access to get my system question anwered.

Does there exist some other mean, maybe even something like:

GetFileList(pattern, &resultContainer);

Question by:bronkbronk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 48

Assisted Solution

AlexFM earned 62 total points
ID: 10772613
In windows you can use the following functions:


LVL 16

Expert Comment

ID: 10772717
LVL 12

Accepted Solution

stefan73 earned 63 total points
ID: 10772870
Hi bronkbronk,
> I understand that the solution may differ between the platforms.
Depends. If you use cygwin (, you'll have executables on Windows which will (almost) completely use the same source. You can use gcc, awk, sed, bash... and tons of other tools.

Regarding the Solaris/cygwin solution for the directory, this would be done with opendir():

#include <sys/types.h>
#include <dirent.h>

int main(){
    DIR* dir;
    struct dirent *curr_ent;

    if(!dir) [error...]

        printf("Offset: %lld Inode: %ld File Name: %s\n",curr_ent->d_off,curr_ent->d_ino,curr_ent->d_name);



Expert Comment

ID: 10773444

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question