LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Reading files in C++, using *. (https://www.linuxquestions.org/questions/programming-9/reading-files-in-c-using-%2A-201914/)

poeta_boy 07-06-2004 05:30 PM

Reading files in C++, using *.
 
Hello:

I have a question and I hope you'd be so kind to help me:

I have this program, let's call it myProgram.exe, I wrote it under c++.
Now this program reads a file and processes it, the file that's gonna be read will be specified as a parameter in command line:

myProgram thisThing.h

so it will read the file thisThing.h . I want it to be able to accept several files:

myProgram a.h b.h c.h

And read and processes them all. I have managed to do that, but I'd like to use the *.h and make it read all .h files there are in the directory, is that possible?

myProgram *.h

how can I get a list of the files that are in the directory and then choose those with .h ???

thanks a lot in advance for your time and your help

Poeta

---- Almost to newbie to funcion :cry: ------

itsme86 07-06-2004 05:54 PM

The shell handles filename expansion for you. Here's a little example program I wrote to show you:
Code:

#include <stdio.h>

int main(int argc, char *argv[])
{
  int i;

  printf("Number of files: %d\n", argc-1);

  for(i = 1;i < argc;++i)
    puts(argv[i]);

  return 0;
}

This is the output of the program when I run it (bar.exe *.c):
Number of files: 2
bar.c
foo.c

And as it turns out, those are the only files in that directory that end with .c ;)

poeta_boy 07-06-2004 06:23 PM

thanks a lot! I thought I had to manage that

Thanks thanks!

poeta_boy 07-07-2004 04:59 PM

hello again:

I couldnt do what you said... does it matter if I'm using windows? I did this:

vector<string> comandos;
for(int i = 1; i < argc ; i++)
comandos.push_back(argv[i]);

and when I call: me.exe *.h it says:

*. file cant be found

I dunno what happens?

poeta_boy 07-08-2004 01:01 AM

sorry.... doublr posted so I erase this one.

please help :cry:


All times are GMT -5. The time now is 05:46 AM.