2017-10-12 28 views
1

Linux C++でWIN32_FIND_DATAと同等のものは何ですか?LinuxのC++でWIN32_FIND_DATAに相当する

WIN32_FIND_DATA fileInfo; 

WIN32_FIND_DATAはWindows仕様のデータ型です。

C++ 11でLinux Centos 7に変更すると、WIN32_FIND_DATAのいくつかのメソッドがLinuxのようにサポートされていないため、同等のものを見つける必要があります。

fileInfo.cFileName 
+0

[Cプログラムのディレクトリにファイルをリストする方法](https://stackoverflow.com/questions/4204666/how-to-list-files-in-a-directory-in-ac) -プログラム) – vasek

答えて

1

のように定義stat構造体:(必要なものに最も近い)

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 */ 
}; 

そうでなければ、最初からそれを構築し、GNU Core Utilsは助けることができる持っています。

2

C++ 17は、filesystemである。

例:あなたは、古いコンパイラでそれを使用できるよう

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

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

    return 0; 
} 

これは、Boostライブラリからファイルシステムの機能に基づいています。