Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将当前目录中的所有文件添加到我实现的存档中。我可以使用哪些功能来访问所有这些文件?在网上和手册页做了一些研究之后,我发现的只是简单的 I/O,比如读、写、关闭等。
你可以试试这个。
main() { DIR *d; struct dirent *e; e=malloc(sizeof(struct dirent)); d=opendir("<your_directory_name>"); while ((e = readdir(d)) != NULL) { printf("%d %s\n", e->d_type, e->d_name); } closedir(d); }
这个网页似乎有你想要的。
http://www.gnu.org/software/libc/manual/html_mono/libc.html#Opening-a-Directory
在 Unix 中,readdir;在 Windows 中,请参阅此处了解 FindFirstFile()。然后在一个循环中逐个文件地执行您想要的操作。