private void delete_entry(FileInfoEx entry) { /* * We first try to delete directory (if set flag DeleteEmptyDirectories) * if it is link, DeleteFile finction deletes link, not target, even if target not empty * and return. * If flag DeleteEmptyDirectories not setted, we check LinkInformation and * if it not null (that is entry is soft link) -> return, else * remove its contains. */ int win_err = 0; int res = 0; if (abort) { return; } if (!check_readonly(entry)) { return; } if (entry.Directory) { if (!check_readonly(entry)) { return; } //first try to delete dir, assume it is empty if ((opts & DeleteFileOptions.DeleteEmptyDirectories) == DeleteFileOptions.DeleteEmptyDirectories) { res = WinApiFS.RemoveDirectory(entry.FullName); if (res == 0) { win_err = Marshal.GetLastWin32Error(); if (win_err == WinApiFS.ERROR_DIR_NOT_EMPTY) { //directory not empty if ((opts & DeleteFileOptions.RecursiveDeleteFiles) == DeleteFileOptions.RecursiveDeleteFiles) { //recursive delete needed FileInfoExEnumerable dir_enum = new FileInfoExEnumerable (Path.Combine(entry.FullName, "*"), false, false, false, true); try { foreach (FileInfoEx info in dir_enum) { delete_entry(info); } } catch (Exception ex) { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), ex); } }//end of dir enum //now dir probably empty res = WinApiFS.RemoveDirectory(entry.FullName); if (res == 0) { //not success win_err = Marshal.GetLastWin32Error(); if (win_err != WinApiFS.ERROR_DIR_NOT_EMPTY) //supress -> when delete on mask, //dir may be not empty { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), new Win32Exception(win_err)); } } }//end of dir not empty else { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), new Win32Exception(win_err)); } }//end of error process } else { //not to delete empty dirs //recursive delete needed (if not link) but directory not will remove //check reparse tag if ((opts & DeleteFileOptions.RecursiveDeleteFiles) == DeleteFileOptions.RecursiveDeleteFiles) { if (entry.LinkInformation == null) { FileInfoExEnumerable dir_enum = new FileInfoExEnumerable (Path.Combine(entry.FullName, "*"), false, false, false, true); try { foreach (FileInfoEx info in dir_enum) { delete_entry(info); } } catch (Exception ex) { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), ex); } } } } }//end of if(entry.Directory) else { //entry is file //check mask if (Wildcard.Match(delete_mask, entry.FileName, false)) { if (check_readonly(entry)) { if (main_window != null) { main_window.NotifyLongOperation (string.Format(Options.GetLiteral(Options.LANG_DELETE_NOW_0), entry.FullName), true); } res = WinApiFS.DeleteFile(entry.FullName); if (res == 0) { abort = !process_errors (string.Format(Options.GetLiteral(Options.LANG_CANNOT_DELETE_0), entry.FullName), new Win32Exception(Marshal.GetLastWin32Error())); } } } } }