Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

"Recursive" C wildcards under NT

Posted on 2004-08-01
6
Medium Priority
?
482 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 75 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 300 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 86

Accepted Solution

by:
jkr earned 300 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Suggested Courses

885 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