?? try_dir.c
字號:
#include "stdio.h"
#include "stdlib.h"
#include "dir.h"
#include "string.h"
#include "dos.h"
/*This function is for dir browse. And it is based on turbo C.
The first parameter is the direct which is to be browsed. For example: "c:\turboc\11\".
The second parameter is the special file require. For example: "*.txt".
This function browse all files in this dir, including subdir.
The last but six line is make dir in the current dir.
If want to get current dir, you can use the getcurdir(0,buf) function.
*/
int BrowseDir(const char *dir,const char *filespec)
{
struct ffblk *fileinfo;
char filename[MAXPATH];
int count = 0;
int dircount = 0;
char *buf;
char *subdir;
buf = (char *) malloc(40);
strcpy(buf, dir);
/* printf("%s\n",buf);*/
/*chdir(buf);*/
/*printf("%s\n",buf);*/
fileinfo = (struct ffblk *)malloc(sizeof(struct ffblk));
strcat(buf, filespec);
/* printf("%s\n",buf);*/
if ((findfirst(buf, fileinfo, FA_ARCH)) == 0)
{
do
{
/* printf("fileinfo.ff_attrib is : %s\n", fileinfo->ff_attrib); */
/* printf("fileinfo.ff_name is : %s\n", fileinfo->ff_name); */
if ((fileinfo->ff_attrib & FA_ARCH)) /* if it is file */
{
count++;
printf("fileinfo.ff_attrib is : %s\n", fileinfo->ff_attrib);
printf("fileinfo.ff_name is : %s\n", fileinfo->ff_name);
/************ file open code add here! ************/
}
} while (findnext(fileinfo) == 0);
}
printf("number of txt is: %d\n", count);
count = 0;
dircount = 0;
free(fileinfo);
fileinfo = (struct ffblk *)malloc(sizeof(struct ffblk));
free(buf);
buf = (char *)malloc(40);
strcpy(buf,dir);
strcat(buf,"*.*");
if ((findfirst(buf, fileinfo, FA_DIREC)) == 0)
{
do
{
if ((fileinfo->ff_attrib & FA_DIREC)) /* if it is subdir */
{
if((strcmp(fileinfo->ff_name, ".") != 0)&&(strcmp(fileinfo->ff_name, "..") != 0))
/* if the name of subdir is not "." or "..", because this is the hidden file */
{
printf("fileinfo.ff_attrib is : %s\n", fileinfo->ff_attrib);
printf("fileinfo.ff_name is : %s\n", fileinfo->ff_name);
dircount++;
subdir = (char *) malloc( MAXPATH * sizeof(char));
strcpy(subdir, dir);
strcat(subdir, fileinfo->ff_name);
strcat(subdir, "\\");
BrowseDir(subdir,filespec);
}
}
} while (findnext(fileinfo) == 0);
}
printf("number of dir in %s is: %d\n", dir, dircount);
}
main()
{
char *buf;
buf = (char *)malloc(40);
strcpy(buf,"c:\\turboc2\\11\\");
/*getcurdir(0,buf);
printf("%s\n",buf);*/
BrowseDir(buf,"*.txt");
/* strcat(buf,"\\data");
if(mkdir(buf) != 0)
{
printf("mkdir is error!\n");
}
*/
getch();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -