testdir.c

来自「一个操作系统源代码 用于嵌入式设备 在Vc++环境下仿真 成功移植到多款处理器上」· C语言 代码 · 共 78 行

C
78
字号
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <testdir.h>

void InitFileSystem( void )
{
}

long GetFileLength( FILE *fp )
{
	return filelength( fileno( fp ) );
}

int freaddir( char *path, DIRINFO_S *dirinfo )
{
	FILE *fp;
	int count=0;
	int i;
	char strtemp[100]; 
	char dirpath1[100]="dir /AD /b /O config\\file";
	char dirpath2[100]="dir /A /b /O  config\\file";
	char tttt1[]=">d:\\temp1.txt";
	char tttt2[]=">d:\\temp2.txt";
	
	strcat(dirpath1, path );
	strcat(dirpath2, path );
	strcat(dirpath1, tttt1 );
	strcat(dirpath2, tttt2 );
	
	system( dirpath1 );
	system( dirpath2 );

	
	fp = fopen( "d:\\temp1.txt", "r" );
	while( !feof( fp ) ){
		fgets( dirinfo->siminfo[count].name, 100, fp );
		dirinfo->siminfo[count].type = 2;
		count++;
	}
	count--;
	memset( &dirinfo->siminfo[count], 0, sizeof(SIMPLE_INFO) );
	fclose( fp );
	
	fp = fopen( "d:\\temp2.txt", "r" );

	for(i = 0; i < count; i++ )
		fgets( strtemp, 100, fp );

	while( !feof( fp ) ){
		fgets( dirinfo->siminfo[count].name, 100, fp );
		dirinfo->siminfo[count].type = 1;
		count++;
	}
	count--;
	memset( &dirinfo->siminfo[count], 0, sizeof(SIMPLE_INFO) );
	dirinfo->allnum = count;
	fclose( fp );
#if 0	
	printf("Current Direcory List: \n");
	for (i=0; i<count; i++)
		printf( "%s <%d>\n" , dirinfo->siminfo[i].name, dirinfo->siminfo[i].type );
#endif

	return 0;
}

#if 0
void main()
{
	DIRINFO_S		*dirinfo;
	dirinfo = (DIRINFO_S *)malloc(sizeof(DIRINFO_S));
	memset( dirinfo, 0, sizeof(DIRINFO_S) );

	freaddir( ".\\debug", dirinfo );
	
}
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?