-2

I'm looking to list and store the contents of a directory in a struct using C on Windows.

I got a problem with stat(), I don't really understand this line

if (statut.st_mode & S_IFDIR)

So I want to understand how it works for checking if it's a directory or a file?

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
sam
  • 1
  • 1

1 Answers1

0

stat() retrieves a block of information describing the specified file. Directories are also files. A directory can be thought of as a file that contains other files.

So, in the file's st_mode, you can see whether the current file is actually a directory by checking for the presence of the S_IFDIR bit.

Gil Hamilton
  • 11,973
  • 28
  • 51
  • but when it's not a directory, it writes _not a directory_ and i dont want that , because i want to manipulate the files inside the directory. – sam Mar 09 '15 at 12:19
  • 1
    ?? "It" (stat / S_IFDIR) doesn't write anything. If *your program* doesn't do what you want it to do, change it. – Gil Hamilton Mar 09 '15 at 12:40