LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   finding files in C++ (https://www.linuxquestions.org/questions/programming-9/finding-files-in-c-202883/)

poeta_boy 07-09-2004 12:09 AM

finding files in C++
 
Hello:

I have a question I hope someone could help me :(

Is there a way to know which files are there in the directory where a exe is? I mean, I have my.exe and I wrote in c++. I want it to be able to see all the files in that dir and choose only those with extension *.txt let's say...

If there's a way to find out the info about the files, I can manage to choose only those I want........ is there a command or a sentence for that?

I have another newbie question.... that very same program reads files in order to work, and if it doesn't have any parameters in command line, I want it to do as I stated above.... however, if I do pass it a parameter I want it to read the file I pass:

my.exe thisFile.txt b.txt c.txt

And that does work, it reads all the parameters... however, if I pass too many parameters:

my.exe a.txt b.txt c.txt d.txt e.txt f.txt g.txt h.txt

it just reads like the first 5 or something and then hangs.... inside there's just a for loop that keeps reading the files, is there a problem about passing too many parameters? too long the command instruction maybe? any work around?

Thanks for your help and your time.

poeta

gizmo_thunder 07-09-2004 01:39 AM

There are a few system calls in windows which will help you browse the
directory structure.. i mean to find the files in the directory. Check out the
online MSDN for those system calls

shrey_j 07-11-2004 01:25 AM

hi poeta_boy,

I'll try and answer with whatevr I know!

Firstly, talking about Linux, there is a structutre called stat in linux/stat.h (i presume, i cannot crosscheck right now). This stat stores all the info about a file, and even a directory is a file. there is an element which stores all the included files to which a directory is linked. try that out

Also there is no problem with number of parameter, as every thing is stored in the argv[][] array, and can be addressed simply by an integer. There must be some problem in array traversing from you side.

I hope it works


All times are GMT -5. The time now is 03:12 PM.