21xrx.com
2024-04-23 23:19:18 Tuesday
登录
文章检索 我的文章 写文章
C程序列出目录中的文件
2021-07-07 10:08:55 深夜i     --     --
C

C 程序来列出目录/文件夹中存在的所有文件,其中存在其可执行文件。 例如,如果可执行文件存在于 C:\\TC\\BIN 中,那么它将列出 C:\\TC\\BIN 中存在的所有文件。

C 程序(仅限 Turbo C 编译器)

#include <stdio.h>
#include <conio.h>
#include <dir.h>


int main()
{
   int done;
   struct ffblk a;

   printf("Press any key to view the files in the current directory\n");

   getch();

   done = findfirst("*.*", &a, 0); // The first '*' is for all file names and the second one is for all file extensions

   while(!done)
   {
      printf("%s\n", a.ff_name);
      done = findnext(&a);
   }

   getch();
   return 0;
}

当您在计算机上执行程序时,您将获得不同的输出。

  
  
下一篇: C程序删除文件

评论区

{{item['qq_nickname']}}
()
回复
回复