Questions tagged [dirent.h]

header file for POSIX C containing directory-related functions and types.

176 questions
3
votes
3 answers

Using C, how can I know when a file is created?

I'm making a program in C for linux that scans a directory every x seconds during a time period for modifications, but I'm having trouble finding out when a file or directory is created. Here are a few options I considered: Using the stat struct,…
Mr eskimo
  • 41
  • 1
3
votes
1 answer

c programming - directory name from DIR* struct

from dirent.h we can see that DIR struct is struct DIR { struct dirent ent; struct _WDIR *wdirp; }; and dirent struct is struct dirent { /* Always zero */ long d_ino; /* File position within stream */ long d_off; …
Phiber
  • 1,041
  • 5
  • 17
  • 40
3
votes
1 answer

c++ dirent.h and syntax for getting absolute path

I am learning to use dirent.h. While the process is fascinating and interesting, I have ran into a problem with using d_name. I want to do two things using d_name. recursively search through the sub-directories. To this, when I encounter DT_DIR…
Ishiro Kusabi
  • 211
  • 2
  • 6
  • 13
3
votes
1 answer

struct dirent does not have de_type in header file

So I have a project where I need to build a small simple text shell that can run, edit, and read files from a directory. I have a small prototype that should work, except when I compile, I receive an error about d_type not found within the struct…
JustaRedShirt
  • 185
  • 1
  • 8
3
votes
1 answer

Delete old files using C++

I have to delete all files older than n days in a given directory using c++. FYI, I am using "dirent" for certain file operation like list all files in given directory, but not sure how to check date attributes and apply math to delete files older…
user1908860
  • 509
  • 1
  • 9
  • 19
3
votes
2 answers

Gettling a list of files within a directory

I am working on a C project where I need to get the list of files that are within a directory. I am using dirent.h but am having some problems getting it to work, I am building the program under Linux. When I try and build the program I get the…
Boardy
  • 35,417
  • 104
  • 256
  • 447
2
votes
1 answer

using ((entry = readdir(folder)) != NULL) in multiple loops C

I am working on directories using dirent.h in c and I want to use a couple of loop with ((entry = readdir(folder)) != NULL) as a condition. my question is, do I need to somehow reset it to the starting point of he directory again after the loop, and…
2
votes
2 answers

Getting size of files in a directory

I trying to get size of files in a directory by using dirent.h headers. However stat(ent->d_name, &statbuf) returns always -1 and I can't get the size properly. What could be the reason?
thetux4
  • 1,583
  • 10
  • 25
  • 38
2
votes
1 answer

struct dirent in C d_name[256] and NAME_MAX definition

I am confused by the use of d_name[256] and NAME_MAX in struct dirent definition. Does d_name[256] mean that the filename length can be atmost 256 character? Then it also mentions NAME_MAX (quoted in the bottom). So, my question is how NAME_MAX…
hi15
  • 2,113
  • 6
  • 28
  • 51
2
votes
1 answer

Check if item on directory is folder in C

i'd like to check when I go over all files on directory, if one of the files/items on the directory is folder (another directory) code I have started from (using dirent.h): DIR *dir; struct dirent *ent; if ((dir = opendir ("c:\\src\\")) != NULL) { …
Raz Omry
  • 255
  • 1
  • 6
  • 18
2
votes
0 answers

XCode is missing headers for dirent.h

i have a problem with xcode and dirent.h. I have to include dirent.h for my program but it says that im missing the header windef.h, i downloaded it and then it says it needs winnt.h and so on.. How do i solve this issue with and the missing…
Schbabako
  • 113
  • 11
2
votes
0 answers

How can DIR* get EBADF error?

I have some code that I have inherited which is part of a class for iterating, accessing the directory content and uses boost::filesystem::path. The code reads in part: struct directory_iterator_impl { private: void skip_dots(const path& p, const…
WilliamKF
  • 41,123
  • 68
  • 193
  • 295
2
votes
4 answers

How to copy a char into a char* vector

I am using dirent to read filenames from a specific folder, and I want to save the names in a char* vector. It seems that it's copying some weird symbols instead of copying the filenames. This is what I tried so far: std::vector
CristianLuca
  • 111
  • 2
  • 10
2
votes
2 answers

Unable to sort dirent with qsort in C

I am having trouble sorting a dirent struct in C. I have tried everything and cannot get the values of my struct array to appear in my comparison. My code looks like this: void printSortedNames(){ struct dirent **file_list = (dirent**)malloc(5…
VMA92
  • 469
  • 2
  • 8
  • 19
2
votes
2 answers

How are dirent entries ordered?

I am at a loss as to how dirent entries are ordered. For example, if I had the code DIR* dir = opendir("/some/directory"); struct dirent* entry; while ((entry = readdir(dir)) printf("%s\n", entry->d_name); This may output something like the…
Levi
  • 1,921
  • 1
  • 14
  • 18
1
2
3
11 12