Solved

Listing files

Posted on 2004-04-07
4
336 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
4 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 62 total points
Comment Utility
In windows you can use the following functions:

FindFirstFile
FindNextFile
FindClose

0
 
LVL 16

Expert Comment

by:nonubik
Comment Utility
0
 
LVL 12

Accepted Solution

by:
stefan73 earned 63 total points
Comment Utility
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
Comment Utility
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now