Open txt files one by one from directory

Hi everyone,

I have a directory that have 100s of txt files. (Folder is Data_Sets_30)

I want to open txt files one by one and get values and close the file and open next txt file get values and close the file and continue like that.

I started to code but I don't know exactly how to do it.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <dirent.h>
struct dirent *entry;
DIR *dp;
dp = opendir("C:/Users/acer/Documents/Visual Studio 2010/Projects/DevC++30/DevC++/Data_Sets_30");
if (dp == NULL)
{
    perror("Error Occurred");
    return -1;
}
while((entry = readdir(dp)))
{
... I don't know that part
} 
You can get a list of solutions if you google it with, say, "read all files in directory c++".

For future reference:
What if we don't know how to do some low level (compared with applications) stuff with directory, file system, hard disk, etc?

One possible source is opensource operating systems.

For this particualr example, if you check out the source code for ls command in Linux, you may search for option -a to quickly locate the part of code that list all directory items. Then just follow the program control flow and see how people do the task.

Hope it helps.
thank you for your advice actually I searched a lot but I did not find reasonable solution or the codes gave an error :(
Last edited on
Topic archived. No new replies allowed.