Solved

"Recursive" C wildcards under NT

Posted on 2004-08-01
6
473 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
[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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why debugging a macro i s difficult 10 41
Which version of C should I use when Perl is too slow? 13 187
why "." vs "->" 23 120
Problem to ASCII 1 215
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

735 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