1

What is the equivalent for WIN32_FIND_DATA in Linux C++?

WIN32_FIND_DATA fileInfo;

WIN32_FIND_DATA is a datatype for Windows specification.

When I change to Linux Centos 7 with C++11 then I need to find the equivalent to it because there are several method in WIN32_FIND_DATA do not support in Linux like.

fileInfo.cFileName
Yamur
  • 339
  • 6
  • 20
  • Possible duplicate of [How to list files in a directory in a C program?](https://stackoverflow.com/questions/4204666/how-to-list-files-in-a-directory-in-a-c-program) – vasek Oct 12 '17 at 08:34

2 Answers2

2

C++17 has filesystem.

Example:

#include <filesystem>
namespace fs = std::filesystem;

int main()
{
    fs::path p { "/usr/lib/" };
    for (auto& entry : p)
    {
        // do something with entry
    }

    return 0;
}

It is based on the file system functionality from the Boost library so you could use that with older compilers.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Eelke
  • 20,897
  • 4
  • 50
  • 76
1

The stat struct defined as: (its the closest to what you require)

struct stat {
    dev_t     st_dev;     /* ID of device containing file */
    ino_t     st_ino;     /* inode number */
    mode_t    st_mode;    /* protection */
    nlink_t   st_nlink;   /* number of hard links */
    uid_t     st_uid;     /* user ID of owner */
    gid_t     st_gid;     /* group ID of owner */
    dev_t     st_rdev;    /* device ID (if special file) */
    off_t     st_size;    /* total size, in bytes */
    blksize_t st_blksize; /* blocksize for file system I/O */
    blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */
};

Otherwise you have to build it from scratch and GNU Core Utils can help.

Azeem
  • 11,148
  • 4
  • 27
  • 40
Samer Tufail
  • 1,835
  • 15
  • 25