static void tree_rmdir_cmd (WTree *tree) { off_t count = 0; double bytes = 0; FileOpContext *ctx; if (!tree->selected_ptr) return; if (confirm_delete) { char *buf; int result; buf = g_strdup_printf (_(" Delete %s? "), tree->selected_ptr->name); result = query_dialog (_(" Delete "), buf, 3, 2, _("&Yes"), _("&No")); g_free (buf); if (result != 0) return; } ctx = file_op_context_new (OP_DELETE); file_op_context_create_ui (ctx, FALSE); if (erase_dir (ctx, tree->selected_ptr->name, &count, &bytes) == FILE_CONT) tree_forget_cmd (tree); file_op_context_destroy (ctx); }
static void tree_rmdir (void *data) { WTree *tree = data; file_op_context_t *ctx; file_op_total_context_t *tctx; if (!tree->selected_ptr) return; if (confirm_delete) { char *buf; int result; buf = g_strdup_printf (_("Delete %s?"), vfs_path_as_str (tree->selected_ptr->name)); result = query_dialog (Q_ ("DialogTitle|Delete"), buf, D_ERROR, 2, _("&Yes"), _("&No")); g_free (buf); if (result != 0) return; } ctx = file_op_context_new (OP_DELETE); tctx = file_op_total_context_new (); file_op_context_create_ui (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM); if (erase_dir (tctx, ctx, tree->selected_ptr->name) == FILE_CONT) tree_forget (tree); file_op_total_context_destroy (tctx); file_op_context_destroy (ctx); }
int erase_dir( const char* path, bool rm_cur ) { #ifdef _WIN32 char buf[_MAX_PATH]; dir_cat( path, "*.*", buf, ELEMENTS(buf) ); struct _finddata_t fileinfo; intptr_t hfind = _findfirst( buf, &fileinfo ); if( hfind==-1 ){ errno = ENOENT; return -1; } do{ char path_file[_MAX_PATH]; dir_cat( path, fileinfo.name, path_file, ELEMENTS(path_file) ); if( fileinfo.attrib & FILE_ATTRIBUTE_DIRECTORY ){ if( strcmp(fileinfo.name,".")!=0 && strcmp(fileinfo.name, "..")!=0 ){ if( erase_dir( path_file, true )!=0 ){ //clear the children path _findclose( hfind ); return -1; } } }else{ if( remove(path_file)!=0 ){ _findclose( hfind ); return -1; } } }while( _findnext( hfind, &fileinfo )==0 ); _findclose( hfind ); #else DIR* dirp = opendir(path); if( dirp==NULL ){ errno = ENOENT; return -1; } struct dirent * dp = readdir(dirp); while( dp ){ char path_file[_MAX_PATH]; dir_cat( path, dp->d_name, path_file, ELEMENTS(path_file) ); if( IsDirExist(path_file) ){ if( strcmp(dp->d_name, ".")!=0 && strcmp(dp->d_name, "..")!=0 ){ if( erase_dir( path_file, true )!=0 ){ closedir(dirp); return -1; } } }else{ if( remove(path_file)!=0 ){ closedir(dirp); return -1; } } dp = readdir(dirp); } closedir(dirp); #endif if( rm_cur ){ return rmdir( path ); } return 0; }