Solved

Listing files

Posted on 2004-04-07
4
339 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

776 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