【007】【列目录.c】利用tree.exe
截图:无
【源代码】
#include<stdio.h>
#include<Windows.h>
/*利用cmd命令,也就是带参数执行 system32下的tree.exe*/
int main()
{
char path[MAX_PATH]={0},info[MAX_PATH+10]={0};
int type;
printf("\n\n\t\t【目录树形图】\n\n\n");
printf("请输入路径名:");
gets(path);
printf("请选择:\n\n1.列目录\n2.列目录与文件\n\n选择:");
scanf("%d",&type);
if(type==1){
sprintf(info,"tree %s >tree_info.txt",path);
}
else{
sprintf(info,"tree %s /f >tree_info.txt",path);
}
printf("正在处理,请稍等:");
system(info);
system("tree_info.txt");
printf("完成!");
getchar();
return 0;
}
