Exemplo n.º 1
0
static INT64_T chirp_fs_local_rmdir(const char *path)
{
	struct chirp_dir *dir;
	struct chirp_dirent *d;
	int empty = 1;

	dir = chirp_fs_local_opendir(path);
	if(dir) {
		while((d = chirp_fs_local_readdir(dir))) {
			if(!strcmp(d->name, "."))
				continue;
			if(!strcmp(d->name, ".."))
				continue;
			if(!strncmp(d->name, ".__", 3))
				continue;
			empty = 0;
			break;
		}
		chirp_fs_local_closedir(dir);

		if(empty) {
			return delete_dir(path);
		} else {
			errno = ENOTEMPTY;
			return -1;
		}
	} else {
		return -1;
	}
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: wtaysom/tau
int rmv (char *name)
{
	char	key[1024];
	// This is kind of dangerous.  Should make a separate copy
	// of the name.  Actually, shouldn't pass back pointers.
	strcpy(key, name);
	return delete_dir(key);
}
Exemplo n.º 3
0
Arquivo: main.c Projeto: wtaysom/tau
int rmv_percent (char *name, void *p)
{
	int	x = *(int *)p;

	if (random_percent(x)) {
		return delete_dir(name);
	}
	return 0;
}
Exemplo n.º 4
0
/* Delete file function:
 *    Delete a file
 * Parameter(s):
 *    symbolic_file_name: a file name to be deleted.
 * Return:
 *    Return 0 with success
 *    Return -1 with error (ie. No such file).
 */
int FileSystem53::deleteFile(string fileName)
{
	int desc_index = search_dir(0, fileName);

	if ( desc_index == -1 ) {
		cout << "[email protected](): No such file" << endl;
		return -1;
	}

	// check oft to see wheter it is opened
	for (int i = 1; i < MAX_OPEN_FILE+1; i++)
	{
		if ( oft[i][0] != 0 && oft[i][0] == desc_index )
		{
			close(i);
		}
	}

	// find the descriptor and mark the bytemap
	for (int i = 1; i < DESCR_SIZE; i++)
	{
		int block_index = desc_table[desc_index][i];
		if ( block_index != 0 && block_index > 6 )
		{
			desc_table[0][block_index] = 0;
		}
	}
	clear_descriptor(desc_index);

	// delecte the filename and related information from directory
	int cursor = oft[0][OFT_CURRENT_POSITION_INDEX];
	int start_pos = cursor;
	int length = oft[0][1];
	while ( cursor < (length+6) )
	{
		// filename's length
		int desc_index = oft[0][cursor];
		cursor++;
		int nlength = oft[0][cursor];
		//char buffer[nlength];
		cursor++;
		string name_buffer = "";
		for (int i = 0; i < nlength; i++)
		{
			name_buffer += oft[0][cursor+i];
			//buffer[i] = oft[index][cursor+i];
		}
		
		if ( fileName.compare(name_buffer) == 0 )
			delete_dir(0, start_pos, nlength);

		cursor += nlength-1;	
	}

	return 0;
}
Exemplo n.º 5
0
static void delete_file(const char *path, int recurse) {
  if (unlink(path) < 0 && errno != ENOENT) {
    if (errno == EISDIR) {
      delete_dir(path, 1);
    } else {
      fprintf(stderr, "Cannot create file %s (already exists)\n", path);
      perror("unlink");
    }
  }
}
Exemplo n.º 6
0
void run_test(int x)
{
	int output=0;
	int y= 0;
	char message[200];
	message[0]='\0';

	yaffs_mkdir(TEST_DIR,S_IWRITE | S_IREAD);
	yaffs_set_error(0);	/*reset the last error to 0 */
	//printf("foo exists %d\n",test_yaffs_open());
	sprintf(message,"\nrunning test: %s \n",test_list[x].name_of_test);
	print_message(message,3);
	output=test_list[x].p_function();	/*run test*/
	if (output>=0){
		/*test has passed*/
		sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test);
		print_message(message,3); 
		num_of_tests_pass++;
	} else {
		/*test is assumed to have failed*/
		printf("test failed\n");
		sprintf(message,"test: %s failed\n",test_list[x].name_of_test);
		print_message(message,1);		
		num_of_tests_failed ++;	
	
		get_error();
		print_message("\n\n",1);
		if (get_exit_on_error()){	
			quit_quick_tests(1);
		}
	}
	output=0;
	output=test_list[x].p_function_clean();	/*clean the test*/
	if (output <0){
		/* if the test failed to clean it's self then */
		sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test);
		print_message(message,1);		
		num_of_tests_failed ++;	
		num_of_tests_pass--;
		get_error();
		printf("\n\n");
		if (get_exit_on_error()){
			quit_quick_tests(1);
		}
		
	} else {
		sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
		print_message(message,3);
	}
	/* close all open handles */
	for (y=0; y<100;y++){
		yaffs_close(y);
	}
	delete_dir(TEST_DIR);
}
Exemplo n.º 7
0
Arquivo: main.c Projeto: wtaysom/tau
int dp (int argc, char *argv[])
{
	int	i;
	int	rc;

	for (i = 1; i < argc; ++i) {
		rc = delete_dir(argv[i]);
		if (rc != 0) {
			return rc;
		}
	}
	return 0;
}
Exemplo n.º 8
0
int delete_dir(char * dirname)
{
	space ++;
	int i;
	char chBuf[256];
	DIR * dir = NULL;
	struct dirent *ptr;
	int ret = 0;

	dir = opendir(dirname);
	if(NULL == dir){
		return -1;
	}
	while((ptr = readdir(dir)) != NULL){
		ret = strcmp(ptr->d_name, ".");
		if(0 == ret){
			continue;
		}
		ret = strcmp(ptr->d_name, "..");
		if(0 == ret){
			continue;
		}
		snprintf(chBuf, 256, "%s/%s", dirname, ptr->d_name);
		ret = is_dir(chBuf);
		if(0 == ret){
			for(i=0;i<space;i++){printf("\t");}
			printf("Delete dir %s\n", chBuf);
			ret = delete_dir(chBuf);
			if(0 != ret){
				return -1;
			}
		}
		else if(1 == ret){
			for(i=0;i<space;i++){printf("\t");}
			printf("Delete file %s\n", chBuf);
			ret = remove(chBuf);
			if(0 != ret){
				return -1;
			}
		}
	}
	(void)closedir(dir);

	ret = remove(dirname);
	if(0 != ret){
		return -1;
	}
	space --;
	return 0;
}
Exemplo n.º 9
0
/******************************************************************************
* 函数名称:delete_dir
*
* 输入参数:char *dir_name
*
* 返 回 值:成功:0; 失败:-1
* 修改记录:
* 其他说明:
********************************************************************************/
int delete_dir(char *dir_name)
{
	int ret;
	DIR *dir;
	struct stat buf;
	struct dirent *ptr;
	char file_name[MAX_PATH];

	stat(dir_name,&buf);
	
	if (S_ISDIR(buf.st_mode))
	{
		dir = opendir(dir_name);
		while ((ptr = readdir(dir)) != NULL)
		{
			if (strcmp(ptr->d_name,".") == 0 
				|| strcmp(ptr->d_name,"..") == 0)
			{
				continue;
			}

			sprintf(file_name, "%s/%s", dir_name, ptr->d_name);
			stat(file_name, &buf);

			if (S_ISDIR(buf.st_mode))
			{
				delete_dir(file_name);
			}
			else
			{
				remove(file_name);
			}
		}
		closedir(dir);
		ret = remove(dir_name);
	        printf("starting delete director 2 %s \n", file_name);
	}
	else
	{
		ret = remove(dir_name);
	}

	return ret;
}
Exemplo n.º 10
0
void work_queue_process_delete( struct work_queue_process *p )
{
	if(p->task) work_queue_task_delete(p->task);

	if(p->output_fd) {
		close(p->output_fd);
	}

	if(p->output_file_name) {
		unlink(p->output_file_name);
		free(p->output_file_name);
	}

	if(p->sandbox) {
		delete_dir(p->sandbox);
		free(p->sandbox);
	}

	free(p);
}
Exemplo n.º 11
0
int delete_dir(const char *dirname)
{
	char subdir[PATH_MAX];
	int result = 0;
	struct dirent *d;
	DIR *dir;

	dir = opendir(dirname);
	if(!dir) {
		if(errno == ENOTDIR) 
			return unlink(dirname);
		else if(errno == ENOENT) {
			/* 
			 ENOENT also signals a dangling symlink. So call unlink anyway to
			 remove any dangling symlinks. If not a dangling symlink, unlink
			 will fail and keep errno set to ENOENT. We always return success. 
			*/
			unlink(dirname); 			
			return 0;
		}	
		else 
			return -1;
	}

	while((d = readdir(dir))) {
		if(!strcmp(d->d_name, "."))
			continue;
		if(!strcmp(d->d_name, ".."))
			continue;
		sprintf(subdir, "%s/%s", dirname, d->d_name);
		result = delete_dir(subdir);
	}

	closedir(dir);

	if(rmdir(dirname) != 0) {
		result = -1;
	}

	return result;
}
Exemplo n.º 12
0
int delete_dir_contents(const char *dirname) {
	char subdir[PATH_MAX];
	struct dirent *d;
	DIR *dir;

	int result = 0;

	dir = opendir(dirname);
	if (!dir) {
		return -1;	
	}
		
	while ((d = readdir(dir))) {
		if ((strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) != 0) {
			sprintf(subdir, "%s/%s", dirname, d->d_name);
			if (delete_dir(subdir) != 0) {
				result = -1;
			}	
		}	
	}
		
	closedir(dir);
	return result;
}
Exemplo n.º 13
0
int main(int argc, char **argv)
{
    debug_config(progname);

    // By default, turn on fast abort option since we know each job is of very similar size (in terms of runtime).
    // One can also set the fast_abort_multiplier by the '-f' option.
    wq_option_fast_abort_multiplier = 10;

    get_options(argc, argv, progname);

    outfile = fopen(outfilename, "a+");
    if(!outfile) {
        fprintf(stderr, "%s: couldn't open %s: %s\n", progname, outfilename, strerror(errno));
        exit(1);
    }

    if(!find_executable(filter_program_name, "PATH", filter_program_path, sizeof(filter_program_path))) {
        fprintf(stderr, "%s: couldn't find %s in your PATH.\n", progname, filter_program_path);
        exit(1);
    }

    if(work_queue_master_mode == WORK_QUEUE_MASTER_MODE_CATALOG && !project) {
        fprintf(stderr, "sand_filter: sand filter master running in catalog mode. Please use '-N' option to specify the name of this project.\n");
        fprintf(stderr, "sand_filter: Run \"%s -h\" for help with options.\n", argv[0]);
        return 1;
    }

    q = work_queue_create(port);
    if(!q) {
        fprintf(stderr, "%s: couldn't listen on port %d: %s\n", progname, port, strerror(errno));
        exit(1);
    }

    port = work_queue_port(q);

    if(port_file) {
        opts_write_port_file(port_file,port);
    }

    // advanced work queue options
    work_queue_specify_master_mode(q, work_queue_master_mode);
    work_queue_specify_name(q, project);
    work_queue_specify_priority(q, priority);

    load_sequences(sequence_filename);
    debug(D_DEBUG, "Sequence loaded.\n", curr_rect_y, curr_rect_x);

    init_checkpoint();

    start_time = time(0);

    int curr_start_x = 0, curr_start_y = 0, curr_rect_x = 0, curr_rect_y = 0;

    while(1) {
        while(work_queue_hungry(q)) {
            if(curr_start_y >= num_seqs)
                break;

            display_progress();

            if(checkpoint[curr_rect_y][curr_rect_x] != CHECKPOINT_STATUS_SUCCESS)
                task_submit(q, curr_rect_x, curr_rect_y);

            // Increment the x rectangle
            curr_rect_x++;
            curr_start_x += rectangle_size;

            // If we've reached the end of a row, move to the
            // next row by incrementing the y rectangle.
            if(curr_start_x >= num_seqs) {
                curr_rect_y++;
                curr_start_y += rectangle_size;
                curr_rect_x = curr_rect_y;
                curr_start_x = curr_rect_x * rectangle_size;
            }
        }

        if(work_queue_empty(q) && curr_start_y >= num_seqs)
            break;

        struct work_queue_task *t = work_queue_wait(q, 5);
        if(t)
            task_complete(t);

        display_progress();
    }

    printf("%s: candidates generated: %lu\n", progname, cand_count);

    if(checkpoint_file) {
        fclose(checkpoint_file);
    }

    fprintf(outfile, "EOF\n");
    fclose(outfile);

    work_queue_delete(q);

    if(!do_not_unlink)
        delete_dir(outdirname);

    return 0;
}
Exemplo n.º 14
0
/******************************************************************************
* 函数名称:del_oldest_file_fun
* 功能描述:以天为单位删除最老的录像文件(线程实现函数)
*
*
*
* 修改记录:
* 其他说明:
********************************************************************************/
int del_oldest_file_fun()
{
	int  i,j;
	int  ret;
	int  year,month,day;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year   = get_year();	//获取当前时间-
	cur_month  = get_month();	//获取当前时间-
	cur_day    = get_day();		//获取当前时间-

	do
	{
		ret = get_oldest_date(&year, &month, &day);
		if (ret != 0)
		{
			printf("get_oldest_date: Failed!\n");
			del_file_status = -1;
			break;
		}

		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 )
		{
			del_file_status = -2;
			break;
		}

		//
		if (year == cur_year && month == cur_month && day == cur_day )
		{
			del_file_status = -3;
			break;
		}

#ifdef SD_STORAGE
		disk_num = 1;
#else
		//
		disk_num = get_hard_disk_num();
#endif
		
		for (i=0; i<disk_num; i++)
		{
#ifdef SD_STORAGE

#else
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}
#endif

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d",i,0,j,year,month,day);
				printf("Delete the oldest file: %s\n", dir_name);
				delete_dir(dir_name);
			}
		}
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	//pthread_exit(NULL);

	return 0;
}
Exemplo n.º 15
0
int del_oldest_file_ext_fun()
{
	int i = 0;
	int j = 0;
	int ret = 0;
	int year = 0;
	int month = 0;
	int day = 0;
	int hour = 0;
	char dir_name[MAX_PATH];
	int  cur_year, cur_month, cur_day, cur_hour;
	int  disk_num;
	int  channel_num = get_av_channel_num();

	cur_year = get_year();		//获取当前时间-
	cur_month = get_month();	//获取当前时间-
	cur_day = get_day();		//获取当前时间-
	cur_hour = get_hour();

	do
	{
#ifdef SD_STORAGE
		
#endif

#if 1
		ret = get_oldest_time(&year, &month, &day, &hour);
		if (ret != 0)
		{
			del_file_status = -1;
			break;
		}
#endif		
		printf("the old time: %d %d %d %d\n", year, month, day, hour);
		//
		if (year < 1970 || year >2100 || month < 1 || month > 12 || day < 1 || day >31 || hour<0 || hour>=24)
		{
			del_file_status = -2;
			break;
		}
		/*
		//
		if (year == cur_year && month == cur_month && day == cur_day && hour == cur_hour)
		{
			del_file_status = -3;
			break;
		}
		*/

#ifdef SD_STORAGE
		for (j=0; j<channel_num; j++)
		{
			sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
			//printf("Delete: %s\n", dir_name);
			delete_dir(dir_name);
		}
#else
		//
		disk_num = get_hard_disk_num();
		
		for (i=0; i<disk_num; i++)
		{
			//
			if (hd_get_mount_flag(i, 0) != 1)
			{
				continue;
			}

			//
			for (j=0; j<channel_num; j++)
			{
				sprintf(dir_name,"/record/hd%02d/%02d/ch%02d/%04d-%02d-%02d/%02d",i,0,j,year,month,day,hour);
				delete_dir(dir_name);
			}
		}
#endif
	}while(0);

	if (del_file_status == 1)
	{
		del_file_status = 0;
	}

	return 0;
}
Exemplo n.º 16
0
Arquivo: main.c Projeto: vbmacher/qsOS
int main()
{
  int key;
  int sel, old_sel;

  printf("\nLoading...");

  Init_PHY();
  Init_LOG();
  Init_APP();

  sel = 0;
  old_sel = 0;
start:
  mainmenu(sel);

  // kbhit
  fflush(stdin);
  key = 0;
  asm {
    mov ax, 0x0305
    xor bx, bx
    int 0x16
  }
key_loop:
  while (!kbhit()) ;
  asm {
    xor ah, ah
    int 0x16
    mov byte ptr [key], ah // scan kod
  }

  switch (key) {
    case 0x50: // dole
      old_sel = sel;
      sel++;
      if (sel == menu_count) sel = 0;
      sel_item(sel,old_sel);
      goto key_loop;
    case 0x48: // hore
      old_sel = sel;
      if (!sel) sel = menu_count;
      sel--;
      sel_item(sel, old_sel);
      goto key_loop;
    case 0xE0:
    case 0x1C: // enter
      break;
    default:
      goto key_loop;
  }

  draw_window();
  switch (sel) {
    case CREATE_FILE:
      create_file(NULL);
      break;
    case DELETE_FILE:
      delete_file(NULL);
      break;
    case WRITE_FILE:
      write_file(NULL,NULL,0,0,1);
      cprintf("\n\rPress ENTER");
      cgets(NULL);
      break;
    case READ_FILE:
      read_file(NULL,NULL,0,0,1);
      cprintf("\n\rPress ENTER");
      cgets(NULL);
      break;
    case CREATE_DIR:
      create_dir(NULL);
      break;
    case DELETE_DIR:
      delete_dir(NULL);
      break;
    case SHOW_DIR:
      show_dir();
      break;
    case SET_PATH:
      set_path(NULL);
      break;
    case DISK_INFO:
      disk_info();
      break;
    case FORMAT_FDD:
      format_fdd();
      break;
    case FDD_TEST:
      dotest_fdd();
      break;
    case ABOUT:
      about();
      break;
    case EXIT:
      goto ext;
  }

  textattr(BORDER);
  cprintf("\n\r\n\rPress any key to continue...");
  getchar();
  goto start;

ext:
  window(1,1,80,25);
  textattr(0x07);
  clrscr();

  Destroy_APP();
  Destroy_LOG();
  Destroy_PHY();

  return 0;
}
Exemplo n.º 17
0
static void cmd_RMD_func(ClientInfo *client)
{
	char dest_path[PATH_MAX];
	gen_filepath(client, dest_path);
	delete_dir(client, dest_path);
}
Exemplo n.º 18
0
static bool delete_db(char *database_name) {
    if (0 == delete_dir(database_name)) {
        return false;
    }
    return true;
}
Exemplo n.º 19
0
/**
 *删除日志
 */
void delete_log(void) {
    if(!delete_log_file(modifyFileName)) {
        int i = 0;
        int k = 0;
        short hasDoublePoint = 0;//是否有冒号,用于判断是否点击第二层目录
        int first = 0;//第一层
        int second = 0;//第二层
        int temp = 0;  //计算当前权数
        int nums = 0;//当前数的位数-1
        char *catalogFileStr = NULL; //目录文件字符串
        char *deleteDir = NULL;//如果是删除第一层,则连文件夹一起删除

        for(i=0 ; i<strlen(selectedTreeIndexStr) ; i++) {
            if(selectedTreeIndexStr[i] == ':') {
                hasDoublePoint = 1;
                nums = 0;
            } else {
                if(!hasDoublePoint) { //正在读一级目录序
                    temp = 0;
                    for(k=0 ; k<nums ; k++) {
                        temp = temp*10;
                    }

                    if(temp==0)
                        first += selectedTreeIndexStr[i]-48;
                    else
                        first += ((selectedTreeIndexStr[i]-48)*temp);

                    nums++;
                } else { //正在读二级目录序
                    temp = 0;
                    for(k=0 ; k<nums ; k++) {
                        temp = temp*10;
                    }

                    if(temp==0)
                        second += selectedTreeIndexStr[i]-48;
                    else
                        second += ((selectedTreeIndexStr[i]-48)*temp);
                    nums++;
                }
            }
        }

        //***********START 删除目录**************
        //FILE_CATALOG *fileCatalogInUi
        FILE_CATALOG *tfc = fileCatalogInUi;
        FILE_CATALOG *ttffcc = NULL;
        for(i=0 ; i<first ; i++)
            tfc = tfc->brother;

        FILE_DETAIL_CATALOG *tfdc = tfc->headChild;
        FILE_DETAIL_CATALOG *ttffddcc = NULL;
        for(i=0 ;; i++) {
            if(i == second) {
                if(second==0) {
                    if(tfdc->brother == NULL) { //如果是第一个且没有下一个,则连第一层一起删除
                        if(first==0) { //删除第一层的第一个
                            tfc = fileCatalogInUi->brother;
                            deleteDir = (char *)malloc(strlen(fileCatalogInUi->catalog_name)+8);
                            memset(deleteDir,0x00,strlen(fileCatalogInUi->catalog_name)+8);
                            strcpy(deleteDir,"./data/");
                            strcat(deleteDir,fileCatalogInUi->catalog_name);
                            free(fileCatalogInUi);
                            fileCatalogInUi = tfc;
                            fprintf(stderr,"删除第一层第一个\n");
                        } else {
                            tfc = fileCatalogInUi;
                            for(k=0 ; tfc!=NULL ; k++) {
                                if(k == first-1) {
                                    ttffcc = tfc->brother;
                                    tfc->brother = ttffcc->brother;
                                    deleteDir = (char *)malloc(strlen(fileCatalogInUi->catalog_name)+8);
                                    memset(deleteDir,0x00,strlen(ttffcc->catalog_name)+8);
                                    strcpy(deleteDir,"./data/");
                                    strcat(deleteDir,ttffcc->catalog_name);
                                    free(ttffcc);
                                    fprintf(stderr,"去掉非第一个的第一层\n");
                                }
                                tfc = tfc->brother;
                            }
                        }
                    } else { //改变头结点
                        tfc->headChild = tfdc->brother;
                        free(tfdc);
                        fprintf(stderr,"改变头子结点\n");
                    }
                } else {
                    for(k=0 ;; k++) {
                        if(k == (second-1)) {
                            ttffddcc = tfdc->brother;
                            tfdc->brother = ttffddcc->brother;
                            free(ttffddcc);
                            fprintf(stderr,"第二层非第一个去掉\n");
                            break;
                        }
                        tfdc = tfdc->brother;
                    }
                }
                //tfdc = tfdc->brother;
                break;
            }
        }
        //**********END***************

        catalogFileStr = convert_file_to_str_catalog(fileCatalogInUi,NULL,NULL);
        fprintf(stderr,"劲测试目录:%s\n",catalogFileStr);
        //更新目录
        if(!save_or_modify_catalog_file(catalogFileStr)) {
            init_right_main_view_hide_all("日志删除成功");
            if(deleteDir != NULL)
                delete_dir(deleteDir); //删除文件夹
            init_tree_view_catalog();//刷新树
        } else {
            init_right_main_view_hide_all("日志删除失败");
        }

        free(catalogFileStr);
    } else {
        init_right_main_view_hide_all("日志删除失败");
    }
}
Exemplo n.º 20
0
static int get_oldest_time(int *year, int *month, int *day, int *hour)
{
	int i,j,k,total;
	struct dirent **namelist;
	char path_name[MAX_PATH];
	char dir_name[24];
	int  disk_num;
	int channel_num = 0;

	memset(dir_name, 0xFF, sizeof(dir_name));

	// 遍历所有硬盘的所有分区 
#ifdef SD_STORAGE
	disk_num = 1;
#else
	disk_num = get_hard_disk_num();
#endif

	channel_num = get_av_channel_num();
	
	for (i=0; i<disk_num; i++)
	{
#ifndef SD_STORAGE
		if (hd_get_mount_flag(i,0) != 1) 		// 只搜寻数据分区 
		{
			continue;
		}
#endif

		for (j=0; j<channel_num; j++)
		{
			sprintf(path_name,"/record/hd%02d/%02d/ch%02d", i, 0, j);
			// 按过虑条件搜索文件夹,
			total = scandir(path_name, &namelist, filter, alphasort);
	               //  printf(" total = %d\n", total);
			if (total > 1)
			{
				if (strcmp(dir_name,namelist[0]->d_name) > 0)
				{
					printf("dir_name = %s\n", dir_name);
					strcpy(dir_name,namelist[0]->d_name);
				}

				for (k=0; k<total; k++)
				{
					if (namelist[k] != NULL)
					{
 						free(namelist[k]);
                                                namelist[k] = NULL;
					}
				}

				if (namelist != NULL)
				{
					free(namelist);
					namelist = NULL;
					
				}
			}
			else{
				memset(dir_name, 0, 24);
				//printf("dir_name = %d\n",strlen( dir_name));

			}
			//usleep(500*1000);
		}
	}

	if (strlen(dir_name) > 0)
	{

		sscanf(dir_name, "%d-%d-%d", year, month, day);

		strcat(path_name, "/");
		strcat(path_name, dir_name);
		total = scandir(path_name, &namelist, filter_ext, alphasort);
		if (total > 0)
		{
			//printf(" namelist[0]->d_name = %s\n", namelist[0]->d_name);
			sscanf(namelist[0]->d_name, "%d", hour);

			for (k=0; k<total; k++)
			{
				if (namelist[k] != NULL)
				{
 					free(namelist[k]);
				}
			}

			if (namelist != NULL)
			{
				free(namelist);
			}
		}
		else
		{
			delete_dir(path_name);
			//printf("delete_dir scussed %s!!!\n\n", path_name);
		}
		//printf("############################total = %d path_name = %s\n dir_name= %s  \n", path_name,dir_name);
		return 0;
	}
	else
	{
		return -1;
	}
}