Yamur
Yamur

Reputation: 339

WIN32_FIND_DATA equivalent in Linux C++

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

Upvotes: 1

Views: 1594

Answers (2)

Samer Tufail
Samer Tufail

Reputation: 1894

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.

Upvotes: 1

Eelke
Eelke

Reputation: 22003

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.

Upvotes: 2

Related Questions