c++, 在 Windows 上列出所有文件,dirent.h

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5840616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 16:45:30  来源:igfitidea点击:

c++, List all files, dirent.h on Windows

c++windowslistfiledirent.h

提问by blubberbernd

in C++, what would be the best way to list all files of a directory on Windows?

在 C++ 中,在 Windows 上列出目录的所有文件的最佳方法是什么?

On Linux or on Windows using gcc (e.g. MingW) this is easy possible with dirent.h, but what's the best way to do it on Windows when dirent.h is not available (e.g. Visual Studio)?

在 Linux 或使用 gcc(例如 MingW)的 Windows 上,使用 dirent.h 很容易做到这一点,但是当 dirent.h 不可用(例如 Visual Studio)时,在 Windows 上执行此操作的最佳方法是什么?

Should I force people do add a freely available implementation of dirent.h to their Visual Studio? Or should I write an alternative code for reading the files? If this, what would be the best code to do so?

我应该强迫人们向他们的 Visual Studio 添加一个免费可用的 dirent.h 实现吗?或者我应该写一个替代代码来读取文件?如果是这样,这样做的最佳代码是什么?

Thanks.

谢谢。

采纳答案by jonsca

Something like Boost Filesystemwould work across all of those situations.

Boost Filesystem这样的东西可以在所有这些情况下工作。

回答by Ignacio Vazquez-Abrams

dirent.his a POSIX header. On Windows you use the Find*File*()functions in the Win32 API.

dirent.h是一个 POSIX 标头。在 Windows 上,您使用Find*File*()Win32 API 中的函数。

回答by codiddle

To add to the answer above, Windows API is accessed via the windows.h header file included.

为了补充上面的答案,Windows API 是通过包含的 windows.h 头文件访问的。