开发者

Determining files in a directory

开发者 https://www.devze.com 2022-12-22 14:47 出处:网络
I come from a C# background and I am working on a C++ project.I need to open files in a directory, then process that data in the files.The problem is on my target environment (Greenhills Integrity), I

I come from a C# background and I am working on a C++ project. I need to open files in a directory, then process that data in the files. The problem is on my target environment (Greenhills Integrity), I cannot access a "directory". It seems C++ does not have a concept of a directory. Why not? This problem is simple in C#. I cannot 开发者_开发知识库link to any big library(BOOST or dirent) to get the files. I can open a file using fopen, but I won't always know the file names, so I have to "strcat" the directory to each filename in order to "fopen" the files.

I need a way to just get the file names in a directory without using an external API. Is that possible?


The major C++ APIs have directories. Start with readdir on POSIX or FindFirstFile() on Windows. Greenhills seems to support POSIX.


No, it's not possible. C++ has no "built-in" directory functionality - you need to use a library of some sort.


Check with your operating system. Directory handling is different for each. You will have to use the Windows 32 API if you want to list/query directories on Microsoft Windows, and the Linux API (e.g. opendir/stat) if you want to list/query directories on Linux.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号