How can i read a directory listing into an array

V

Vasilis Serghi

I would like to make a call to the OS to give me a listing of the files in
the current directory. How can i do this in a console environment?

I have tried system("dir");, but I'm not sure how to get that info into an
array. I could pipe the info into a file like this system: ("dir >
file.txt");, but I want to avoid creating files if possible.

I am a newbie, so excuse me if this is a simple question.
 
J

Joona I Palaste

Vasilis Serghi said:
I would like to make a call to the OS to give me a listing of the files in
the current directory. How can i do this in a console environment?
I have tried system("dir");, but I'm not sure how to get that info into an
array. I could pipe the info into a file like this system: ("dir >
file.txt");, but I want to avoid creating files if possible.
I am a newbie, so excuse me if this is a simple question.

The only way in ISO standard C is to do the piping you describe above.
For more operation-system-friendly approaches, consult a newsgroup
dedicated to your own implementation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top