![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
File Input Problem
Hello, I have recently started working on a project which needs to read in all the .txt files in a folder. Currently the way it works is incredibly inefficient. The files are all saved in 'endresults-YEAR-MM-DD_HH-MM-SS.txt' format where YEAR is the year, MM the month, DD the day, HH the hour, MM the minute, and SS the second is the exact time you quit the program. Unfortunately the program doesn't know exactly what files to look for, so it iterates a loop for every second between 2004 and 2006. I never let this run to completion, but it would take around I day I would estimate - rending the program useless.
If someone could think of a more efficient way to check every combination it would be appreciated, or better yet if someone could tell me how to get all of the contents of a folder in C++ I think that would be the best route to go. |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Straight from my C for Dummies book:
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>
int main() {
DIR *dir_handle;
struct dirent *dir_record;
dir_handle = opendir("."); // enter the directory you want to open here
if (dir_handle == NULL) {
printf("Error opening directory.\n");
return 1;
}
while ((dir_record = readdir(dir_handle)) != NULL) {
// dir_record->d_name contains the file name
printf("%s\n", dir_record->d_name);
}
closedir(dir_handle);
return 0;
} |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
dirent.h, no such file or directory
any ideas? thanks for trying though |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
What compiler are you using?
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
Just to bring closure to this thread I use Visual Studio .NET 03.
I found that FindFirstFile and FindNextFile works great for this. |
|
|
|
|
|
#6 |
|
Expert Programmer
|
Those functions should work, be aware they are part of the Windows API so you are now compiling a dependancy for Windows. If this is assignment or something your school may not be too fond of that
![]()
__________________
Clifford Matthew Roche <geek@cliffordroche.com> Web Hosting: http://www.crd-hosting.com Consulting: http://www.crdev-consulting.com |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|