Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 16th, 2005, 1:21 AM   #1
HelloWorld
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 HelloWorld is on a distinguished road
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.
HelloWorld is offline   Reply With Quote
Old Mar 16th, 2005, 10:44 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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;
 }
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 16th, 2005, 11:34 PM   #3
HelloWorld
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 HelloWorld is on a distinguished road
dirent.h, no such file or directory

any ideas? thanks for trying though
HelloWorld is offline   Reply With Quote
Old Mar 17th, 2005, 11:38 AM   #4
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
What compiler are you using?
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Mar 19th, 2005, 2:09 PM   #5
HelloWorld
Newbie
 
Join Date: Mar 2005
Posts: 4
Rep Power: 0 HelloWorld is on a distinguished road
Just to bring closure to this thread I use Visual Studio .NET 03.

I found that FindFirstFile and FindNextFile works great for this.
HelloWorld is offline   Reply With Quote
Old Mar 19th, 2005, 5:17 PM   #6
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
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 &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC