Solved

Listing files

Posted on 2004-04-07
4
343 Views
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 > tmp.ls" 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);

Regards,
/Bronk
0
Comment
Question by:bronkbronk
[X]
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
4 Comments
 
LVL 48

Assisted Solution

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

FindFirstFile
FindNextFile
FindClose

0
 
LVL 16

Expert Comment

by:nonubik
ID: 10772717
0
 
LVL 12

Accepted Solution

by:
stefan73 earned 63 total points
ID: 10772870
Hi bronkbronk,
> I understand that the solution may differ between the platforms.
Depends. If you use cygwin (http://www.cygwin.com), 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;

    dir=opendir("your_dir");
    if(!dir) [error...]

    while(curr_ent=readdir(dir)){
        printf("Offset: %lld Inode: %ld File Name: %s\n",curr_ent->d_off,curr_ent->d_ino,curr_ent->d_name);
    }

    closedir(dir);
}


Cheers,
Stefan
0
 
LVL 3

Expert Comment

by:akalmani
ID: 10773444
0

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