Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-09-2004, 01:09 AM   #1
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
finding files in C++


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.

Old 07-09-2004, 02:39 AM   #2
Registered: Apr 2004
Posts: 101

Rep: Reputation: 15
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
Old 07-11-2004, 02:25 AM   #3
Registered: Jul 2004
Location: Delhi
Distribution: FC3, RH 9.0
Posts: 39

Rep: Reputation: 16
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


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
Finding Files Through Urpmi ??? ddrfreak Mandriva 8 12-12-2004 12:00 PM
Finding six month old files arockia Linux - Software 11 09-01-2004 10:37 AM
Finding files brentos Linux - General 3 03-22-2004 09:24 PM
Finding files Nicksan Linux - Software 3 06-30-2003 08:16 PM
Finding files question... tarballed Linux - General 1 03-05-2003 02:01 PM > Forums > Non-*NIX Forums > Programming

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

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