Пример #1
0
void sbt_file_test(){

	int       file_num = 0;
	files_st* p_file_list;
	int i;

	file_num = get_file_num("src/");
	p_file_list = (files_st*)malloc( sizeof(files_st)*file_num );
	get_file_name_list( "src/", p_file_list );
	for( i=0;i<file_num;i++ ){
		LOGD( "file name=%s", p_file_list[i].name );
	}
}
Пример #2
0
void compress( const char *archive_name, const char *_file, bool bpath, bool brecurse )
{
	char path[MAX_PATH];
	char file[MAX_PATH];

	split_path( _file, path, file );

	/// create a lzo archive
	lzo_archive *archive = lzo_create_archive( archive_name );
	
	/// get a file list in the specidied directory
	file_name *file_list = get_file_name_list( path, file, brecurse, bpath );

	/// add file list into the archive
	add_file_list( archive, file_list );

	/// save the archive
	lzo_save_archive( archive );

	/// ok, just free resources
	lzo_destroy_archive( archive );
	free_file_name_list( file_list );

}
Пример #3
0
file_name *get_file_name_list( const char *path, const char *_file, bool recurse, bool bpath )
{
	const char *file = "*.*";
	char full_path[MAX_PATH];
	file_name *header = 0;

	/// it works on Windows
	WIN32_FIND_DATA file_data;
	HANDLE file_handle;

	construct_file_name( full_path, path, file, true );

	file_handle = FindFirstFile( full_path, &file_data );
	if( file_handle == INVALID_HANDLE_VALUE )
	{
		return 0;
	}

	/// igone '.' and '..' files
	while( strcmp( file_data.cFileName, "." ) == 0 || strcmp( file_data.cFileName, ".." ) == 0 )
	{
		if( !FindNextFile( file_handle, &file_data ) )
		{
			return 0;
		}
	}

	/// deal with sub directory
	if( recurse && file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
	{
		char subpath[MAX_PATH];
		construct_file_name( subpath, path, file_data.cFileName, true );
		header = get_file_name_list( subpath, _file, true, bpath );
	}
	else if( !( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
		compare_postfix( file_data.cFileName, _file ) )
	{
		file_name *filename = (file_name*) malloc( sizeof( file_name ) );
		construct_file_name( filename->name, path, file_data.cFileName, bpath );
		construct_file_name( filename->file, path, file_data.cFileName, true );

		if( strcmp( get_self_name(), filename->file ) != 0 &&
			strcmp( get_self_log_name(), filename->file ) != 0 )
		{
			filename->next = header;
			header = filename;
		}
		else
		{
			free( filename );
		}
	}

	/// deal with others
	while( FindNextFile( file_handle, &file_data ) )
	{
		if( recurse && file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
		{
			char subpath[MAX_PATH];
			construct_file_name( subpath, path, file_data.cFileName, true );
			file_name *sub_list = get_file_name_list( subpath, _file, true, bpath );
			if( sub_list != 0 )
			{
				file_name *tail = get_tail( sub_list );
				tail->next = header;
				header = sub_list;
			}
		}
		else if( !( file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
			compare_postfix( file_data.cFileName, _file ) )
		{
			file_name *new_file = (file_name*) malloc( sizeof( file_name ) );
			construct_file_name( new_file->name, path, file_data.cFileName, bpath );
			construct_file_name( new_file->file, path, file_data.cFileName, true );

			if( strcmp( get_self_name(), new_file->file ) != 0 &&
				strcmp( get_self_log_name(), new_file->file ) != 0 )
			{
				new_file->next = header;
				header = new_file;
			}
			else
			{
				free( new_file );
			}
		}
	}

	return header;
}