Questions tagged [dirent.h]

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

176 questions
30
votes
3 answers

Members of Dirent structure

I have started working with dirent.h library and I came across a very useful member of "struct dirent" structer which struct dirent *p->d_name in my book. But unfortunatly it doesn't states any other members of this structure; I was wondering what…
Naruto
  • 1,710
  • 7
  • 28
  • 39
13
votes
4 answers

Checking if a dir. entry returned by readdir is a directory, link or file. dent->d_type isn't showing the type

I am making a program which is run in a Linux shell, and accepts an argument (a directory), and displays all the files in the directory, along with their type. Output should be like this: << ./Program testDirectory Dir directory1 lnk…
Barney Chambers
  • 2,720
  • 6
  • 42
  • 78
13
votes
1 answer

Cross platform way of testing whether a file is a directory

Currently I have some code like (condensed and removed a bunch of error checking): dp = readdir(dir); if (dp->d_type == DT_DIR) { } This works swimmingly on my Linux machine. However on another machine (looks like SunOS, sparc): SunOS HOST 5.10…
Alex Gaynor
  • 14,353
  • 9
  • 63
  • 113
7
votes
2 answers

readdir() 32/64 compatibility issues

I'm trying to get some old legacy code working on new 64-bit systems, and I'm currently stuck. Below is a small C file I'm using to test functionality that exists in the actual program that is currently breaking. #define _POSIX_SOURCE #include…
PKFiyah
  • 81
  • 6
7
votes
2 answers

What does DT_WHT means in /usr/include/dirent.h ?

I am reading the source code of the dirent.h there's a enum enum { DT_UNKNOWN = 0, // unknown type #define DT_UNKNOWN DT_UNKNOWN DT_FIFO = 1, // a named pipe, or FIFO #define DT_FIFO DT_FIFO DT_CHR = 2, // a character…
user1570120
  • 87
  • 1
  • 6
6
votes
3 answers

Why does it say "We must not include limits.h!" in dirent.h?

When we include and to a c file, dirent structs' d_name variable shows We must not include limits.h! in the variable description in the ide. When I look at the file /usr/include/x86_64-linux-gnu/bits/dirent.h it contains the…
sipihr
  • 148
  • 6
6
votes
6 answers

How do i check if a file is a regular file?

How do i check in C++ if a file is a regular file (and is not a directory, a pipe, etc.)? I need a function isFile(). DIR *dp; struct dirent *dirp; while ((dirp = readdir(dp)) != NULL) { if ( isFile(dirp)) { cout << "IS A FILE!" <<…
Emilio
  • 3,901
  • 11
  • 44
  • 50
5
votes
3 answers

why does the C readdir man page say to not call free on the static allocated result struct

$ uname -a Linux crowsnest 2.6.32-28-generic #55-Ubuntu SMP Mon Jan 10 23:42:43 UTC 2011 x86_64 GNU/Linux $ man readdir: DESCRIPTION The readdir() function returns a pointer to a dirent structure representing the next directory entry in the…
Fire Crow
  • 7,499
  • 4
  • 36
  • 35
5
votes
3 answers

c++, List all files, dirent.h on Windows

in C++, what would be the best way to list all files of a directory on Windows? On Linux or on Windows using gcc (e.g. MingW) this is easy possible with dirent.h, but what's the best way to do it on Windows when dirent.h is not available (e.g.…
blubberbernd
  • 3,641
  • 8
  • 35
  • 46
5
votes
1 answer

can't compare dirent->d_type to DT_DIR

I am trying to do a simple comparison to be able to do something if the file type read is a directory. Sample code : int main() { DIR *dir = opendir("."); struct dirent *dirent = readdir(dir); if (dirent->d_type == DT_DIR) //do something …
raiskader
  • 89
  • 4
  • 16
5
votes
1 answer

Cross compile openssl on bare metal

I'm trying to cross compile openssl using the corresponding gcc (arm-none-eabi-5_4-2016q2) for a cortex m3 machine. The machine should have the ability to do TCP request and we'd like to do HTTPS at the end of the day. During the cross compiling, at…
andrew
  • 129
  • 1
  • 10
5
votes
5 answers

Can't find mkdir() function in dirent.h for windows

I am using dirent.h 1.20 (source) for windows in VC2013. I can't find mkdir() in it. How am I supposed to use it? Or can I create a directory somehow only using dirent.h?
Rakesh Malik
  • 607
  • 1
  • 6
  • 27
4
votes
1 answer

Navigating through files using dirent.h?

I would like to know how I can navigate and edit folders and files through code in C. I have looked up the library dirent.h but I'm not sure which functions are used for traversing through directories. Am I even using the right library for this…
Duncan
  • 43
  • 1
  • 3
4
votes
6 answers

How can I get only txt files from directory in c?

I would like to get names of only *.txt files in given directory, sth like this: #include #include #include #include #include int main(int argc, char **argv) { char *dirFilename = "dir"; …
Katie
  • 3,517
  • 11
  • 36
  • 49
3
votes
1 answer

Best Way To Work With FileSystems?

What's the best way to work with file systems in C? There is of course dirent.h , but from what I've heard it isn't completely guaranteed to be available on all platforms and compilers, for example the Microsoft Visual C++ compiler, for one,…
ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153
1
2 3
11 12