473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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 2105
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ken | last post by:
I currently have a set of documents in a directory that i need to list in a html table. Is there any way to generate the table with the documents listed instead of having to update the table...
11
by: Madison Kelly | last post by:
Hi all, I am new to the list and I didn't want to seem rude at all so I wanted to ask if this was okay first. I have a program I have written in perl which uses a postgresSQL database as the...
18
by: UJ | last post by:
Folks, We provide custom content for our customers. Currently we put the files on our server and people have a program we provide that will download the files. These files are usually SWF, HTML or...
4
by: thoseion | last post by:
Hi, I am trying to get a program working whereby directory and file names are read into a list. I have been given the original list structure - it appears that the directory names should be added...
96
by: zzbbaadd | last post by:
What's with the index() function of lists throwing an exception on not found? Let's hope this is rectified in Python 3. If nothing else, add a function that doesn't throw an exception. There are a...
6
by: tgnelson85 | last post by:
Hello, C question here (running on Linux, though there should be no platform specific code). After reading through a few examples, and following one in a book, for linked lists i thought i would...
3
by: froditus | last post by:
Hello everyone, is it possible to list files from directory other than in apache web directory? my web folder is placed on c:/ and i put my files in windows directory "d:/files/images/". I...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
1
by: Trevor17 | last post by:
Hello All, I am currently in a Perl programming class and our assignment was: Create a filehandle with the open function that uses a pipe to list all the files in your current directory and...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.