LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2004, 06:30 PM   #1
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
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 ------
 
Old 07-06-2004, 06:54 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
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
 
Old 07-06-2004, 07:23 PM   #3
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
thanks a lot! I thought I had to manage that

Thanks thanks!
 
Old 07-07-2004, 05:59 PM   #4
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
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?
 
Old 07-08-2004, 02:01 AM   #5
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Original Poster
Rep: Reputation: 31
sorry.... doublr posted so I erase this one.

please help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading WPS files TazG Linux - Software 0 06-12-2004 06:25 PM
reading files over the network derfaust Linux - Software 7 06-08-2004 03:39 PM
Reading Files clowns119 Programming 12 09-23-2003 07:06 PM
reading files MrGardenHoseMan Linux - Newbie 2 07-06-2003 06:58 PM
Not reading all files on CDRom AnthonyM Linux - Newbie 2 03-26-2002 10:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration