您好,欢迎访问一九零五行业门户网

列出目录中的所有文件和子目录的C程序

在这里,我们得到了一个目录。我们的任务是创建一个 c 程序来列出目录中的所有文件和子目录。
目录是一个地方/区域/位置,其中一组文件( s) 将被存储。
子目录是根目录中的一个目录,反过来,它可以有另一个子目录。
在c 编程语言可以轻松列出目录中的所有文件和子目录。下面的程序将说明如何列出目录中的所有文件和子目录。
//列出目录中所有文件和子目录的c程序
示例 h2> 现场演示
#include <stdio.h>#include <dirent.h>int main(void){ struct dirent *files; dir *dir = opendir("."); if (dir == null){ printf("directory cannot be opened!" ); return 0; } while ((files = readdir(dir)) != null) printf("%s
", files->d_name); closedir(dir); return 0;}
输出cprograms..prog1.cprog2.cprog3.c...prog41.cthis will return all files and sub-directory of the current directory.
以上就是列出目录中的所有文件和子目录的c程序的详细内容。
其它类似信息

推荐信息