470,833 Members | 1,939 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,833 developers. It's quick & easy.

How do you get a list of files currently in a directory??

I have a program which saves time stamped files into time stamped
directories.

When I want to read these files, I get the current date and check for the
existence of the directory using....

while (!(_chdir(dirname)) == 0)
{reduce the directory name (time) and check again}

This method quickly finds the last directory but I don't know anything about
the contents of the directory.

I thought it would be easy to load the contents of this directory into a
list which could be used to open files.
I have been using dir command for years and took it for granted that there
is a function to read directory contents but I can't seem to find any easy
way to do this.

How can directory contents be read?
Is there a function or class?
The only thing I can think of is to write the filenames to a database as
they are being written and then check for their existence in a directory.

Any ideas would be appreciated.
Bob
Feb 28 '06 #1
2 1954
Rob_S wrote:
I have a program which saves time stamped files into time stamped
directories.

When I want to read these files, I get the current date and check for the
existence of the directory using....

while (!(_chdir(dirname)) == 0)
{reduce the directory name (time) and check again}

This method quickly finds the last directory but I don't know anything
about the contents of the directory.

I thought it would be easy to load the contents of this directory into a
list which could be used to open files.
I have been using dir command for years and took it for granted that there
is a function to read directory contents but I can't seem to find any easy
way to do this.

How can directory contents be read?
Is there a function or class?


Not in standard C++. The _chdir() function you're using above isn't a
standard C++ function either. So you have to resort to system-specific
functions (For a POSIX compliant system, they would e.g. be opendir(),
readdir(), closedir()), which are best discussed in a newsgroup about the
operating system/compiler/library you are using.

Feb 28 '06 #2

Rolf Magnus wrote:
Rob_S wrote:

How can directory contents be read?
Is there a function or class?


Not in standard C++. The _chdir() function you're using above isn't a
standard C++ function either. So you have to resort to system-specific
functions


Or a portable library, like boost::filesystem. (Which is mostly
off-topic here,
but www.boost.org has enough documentation).
See also the FAQ about the standard library and non-standard libraries.

HTH,
Michiel Salters

Mar 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by UJ | last post: by
4 posts views Thread by thoseion | last post: by
96 posts views Thread by zzbbaadd | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.