Solved

"Recursive" C wildcards under NT

Posted on 2004-08-01
6
472 Views
Last Modified: 2010-04-15
Hello Experts.

I have a program for win XP, whos syntax is something like

lcfs [options] <indir> <files..>

Where the "files" things are multiple wildcard strings.
Now most Unix Shells would replace "*.bmp" in the files section with all files matching this, but NT doesnt seemt to do so.

But IF it would, what I read will work is you link a certain file or something, I'd have problems with my recursive option(which would, of course, search subdirectorys, too), and the shell wouldnt do that, right?

I thought I'd do something like

main(..) {
listfunction(argv[<indir>])
}

listfunction {
 _findfirst(*)
 while ..{
 if(file is a direcory) listfunction(directoryname)
 else if(filename matches wildcard from <files>) ..
 _findnext..
 }
..
}

But I dont know how to do check if a string matches a wildcard, any suggestions or a better way to accomplish this?

Thanks in advance,

Lord.
0
Comment
Question by:LordTTSeven
  • 3
  • 2
6 Comments
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 25 total points
ID: 11688172
In windows environment you can use FindFirstFile(), FindNextFile() functions
Take a look at:
http://www.codeguru.com/Cpp/W-P/files/comments.php/c4479?thread=52622
http://www.codeproject.com/cpp/recursedir.asp 
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 100 total points
ID: 11689031
See e.g. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/listing_the_files_in_a_directory.asp ("Listing the Files in a Directory") which uses the aforementioned functions in C code.
0
 

Author Comment

by:LordTTSeven
ID: 11692353
It seems you got me wrong.

>http://www.codeguru.com/Cpp/W-P/files/comments.php/c4479?thread=52622
doesnt really help.

>http://www.codeproject.com/cpp/recursedir.asp
is c++

>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/listing_the_files_in_a_directory.asp
is not recursive?

It would be easiest if you could give me something that can check if a string matches a wildcard, I think.

Lord.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 11693970
>>is not recursive?

No, but it shows which way to go. To make it recursive, you'd use

void MyFindFunc ( char* pszPath, char* pszWildcard) {

//...

if ( FILE_ATTRIBUTE_DIRECTORY & GetFileAttributes(FindFileData.cFileName))
    MyFindFunc(pszPath, pszWildcard);

}
0
 

Author Comment

by:LordTTSeven
ID: 11694442
I am aware of the way how to make it recursive.

The problem is, that want to search _ALL_ directorys for _SPECIAL_ files(some wildcard).

But if I got you correctly, findfirst/netxfile with wildcard such as "*.extention" will find _ANY_ directorys, too? Or will I have to do a "*" search, check if I have a directory, and do a second search for files with my *.extention wildcard(and another one for the subsub directorys) for each directory I find(Why didnt this idea fly to me earlier)?

If thats the case, everything I did was in vain. Oh well.

Thanks,

Lord.
0
 

Author Comment

by:LordTTSeven
ID: 11694535
[What I forgott in the above Post, sorry for double]

Why I posted this, so you might understand me :)
I thought it would be easiest just run one search with the wildcard "*", call the function recursive if it was a directory other then . and .. ,
and if it was a file manually do a wildcard match on the finddata_thing.name with my wildcard(s) given by the user.

Cheers,

Lord.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which version of C should I use when Perl is too slow? 13 183
Why does module make constant click noise ? 9 135
Need example 5 122
Fill Null values 5 28
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

856 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