473,766 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(dirna me)) == 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 2117
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(dirna me)) == 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::filesyst em. (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
2771
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 manually everytime a new document is added to the list. Thanks Ken
11
2291
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 backend. The program works but the performance is really bad. I have been reading as much as I can on optimizing performance but still it isn't very reasonable. At one point I had my program able to process 175,000 records in 16min 10sec on a...
18
2303
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 JPG files. The problem as I see it - if you know the name of the file, you could download it off the server (currently we are using an HTTP/Get but I'm going to be using WebClient in the new version.) If there any way to password protect the...
4
2116
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 to the list, then the filenames added to another separate but connected list within each directory node. So far I have the program working in that the directory and file names are all added to the list, i.e. it currently doesn't distinguish...
96
4605
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 million situations where you can have an item not be in a list and it is not an exception situation.
6
4158
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 try my own small program. The problem is, I seem to be having trouble with memory, i.e. sometimes my program will work and display the correct output, and sometimes it will not and display garbage (in a printf call) so i assume i have been using...
3
2626
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 want those files to be able to view in client browser. when i tested using server computer it succeed. but from client computer i got nothing. I checked the html sources and the files is directly loaded from "d:/
0
30244
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 a comprehensive list of all autostart locations for Windows OSes: NOTE : These are some abbreviations used in this list. Please note them carefully: HKCU = HKEY_CURRENT_USER HKLM = HKEY_LOCAL_MACHINE
1
2963
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 will print only those files that are readable text files. Use the die function to quit if the open fails. After several hours, i have completed a program that does find all of the readable files in the current directory however I could not figure...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7381
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.