怎么用C统计电脑中的文件个数

来源:百度知道 编辑:UC知道 时间:2024/06/05 06:21:48
可以的话给个程序看看

1 最简单的利用dir 命令
#include<stdio.h>
int main(void)
{

char *filepath = "c:";/* 这里为你要设置的绝对路径 */
char f[400] = "dir ";
strcat(f,filepath);
system(f);
system("pause");
return 0;
}

2---
#include <stdio.h>
#include <io.h>
//节点
typedef struct FileName
{
char Name[500];//定义文件名上限为500
struct FileName *next;
}node;
//链表头指针
node *Head = NULL;
//释放函数
int Free()
{
int count = 0;
node *NowNode = Head;
while(NowNode->next)
{
Head = Head->next;
free(NowNode);
NowNode = Head;
count++;
}
free(Head);
Head = NULL;
count++;
return count;