public override void Delete() { if (IsHardLink) { JunctionPoint.Delete(Path); } else { LongPathDirectory.Delete(Path, true); } }
public static void Delete(string path) { if (path.Length < MAX_PATH) { System.IO.Directory.Delete(path, true); } else { // NOTE: recursive isn't available on the longpath yet, so we only do this if we have to //TODO: implement the recursive stuff ourself LongPathDirectory.Delete(path); } }
void IDirectoryAdapter.Delete(string path) { AssertAllowed(path); #if !MONO var mTx = CurrentTransaction(); if (mTx.HasValue) { ((IDirectoryAdapter)mTx.Value).Delete(path); return; } #endif LongPathDirectory.Delete(path); }
/// <summary> /// Deletes a junction point at the specified source directory along with the directory itself. /// Does nothing if the junction point does not exist. /// </summary> /// <remarks> /// Only works on NTFS. /// </remarks> /// <param name = "junctionPoint">The junction point path</param> public static void Delete(Path junctionPoint) { if (!LongPathDirectory.Exists(junctionPoint)) { if (LongPathFile.Exists(junctionPoint)) { throw new IOException("Path is not a junction point."); } return; } using (var handle = OpenReparsePoint(junctionPoint, EFileAccess.GenericWrite)) { var reparseDataBuffer = new REPARSE_DATA_BUFFER(); reparseDataBuffer.ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; reparseDataBuffer.ReparseDataLength = 0; reparseDataBuffer.PathBuffer = new byte[0x3ff0]; var inBufferSize = Marshal.SizeOf(reparseDataBuffer); var inBuffer = Marshal.AllocHGlobal(inBufferSize); try { Marshal.StructureToPtr(reparseDataBuffer, inBuffer, false); int bytesReturned; var result = DeviceIoControl(handle.DangerousGetHandle(), FSCTL_DELETE_REPARSE_POINT, inBuffer, 8, IntPtr.Zero, 0, out bytesReturned, IntPtr.Zero); if (!result) { ThrowLastWin32Error("Unable to delete junction point."); } } finally { Marshal.FreeHGlobal(inBuffer); } try { LongPathDirectory.Delete(junctionPoint); } catch (IOException ex) { throw new IOException("Unable to delete junction point.", ex); } } }
public override void DeleteDirectory(string directoryPath) { foreach (string subdirectoryPathToDelete in EnumerateDirectories(directoryPath)) { DeleteDirectory(subdirectoryPathToDelete); } foreach (string filePathToDelete in EnumerateFiles(directoryPath)) { DeleteFile(filePathToDelete); } LongPathDirectory.Delete(directoryPath); }
/// <summary> /// Delete non empty directory tree /// </summary> private void DeleteDirectory(string target_dir) { string[] files = Directory.GetFiles(target_dir); string[] dirs = Directory.GetDirectories(target_dir); foreach (string file in files) { try { File.SetAttributes(file, FileAttributes.Normal); File.Delete(file); } catch (PathTooLongException) { LongPathFile.Delete(file); } } foreach (string dir in dirs) { // Only recurse into "normal" directories if ((File.GetAttributes(dir) & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint) { try { Directory.Delete(dir, false); } catch (PathTooLongException) { LongPathDirectory.Delete(dir); } } else { DeleteDirectory(dir); } } try { Directory.Delete(target_dir, false); } catch (PathTooLongException) { LongPathDirectory.Delete(target_dir); } }
bool IDirectoryAdapter.Delete(string path, bool recursively) { AssertAllowed(path); #if !MONO var mTx = CurrentTransaction(); if (mTx.HasValue) { return(((IDirectoryAdapter)mTx.Value).Delete(path, recursively)); } #endif // because of http://stackoverflow.com/questions/3764072/c-win32-how-to-wait-for-a-pending-delete-to-complete var target = Path.GetRandomFileName(); LongPathDirectory.Move(path, target); LongPathDirectory.Delete(target, recursively); return(true); }
private void OnDeleteButtonClick(object sender, EventArgs e) { string selectedPath = (string)fileSystemEntriesListBox.SelectedItem; try { if (LongPathDirectory.Exists(selectedPath)) { LongPathDirectory.Delete(selectedPath); } else { LongPathFile.Delete(selectedPath); } } catch (IOException ex) { ShowError(ex); } catch (UnauthorizedAccessException ex) { ShowError(ex); } RefreshFileList(); }
/// <summary> /// Deletes this instance of a <see cref="LongPathDirectoryInfo"/>, specifying whether to delete subdirectories and files. /// </summary> /// <param name="recursive"><see langword="true"/> to remove directories, subdirectories, and files in path; otherwise, <see langword="false"/>.</param> /// <exception cref="UnauthorizedAccessException">The directory contains a read-only file.</exception> /// <exception cref="DirectoryNotFoundException">The directory described by this <see cref="LongPathDirectoryInfo"/> object does not exist or could not be found.</exception> /// <exception cref="IOException"> /// The directory is read-only. /// <para>-or-</para> /// The directory contains one or more files or subdirectories and <paramref name="recursive"/> is <see langword="false"/>. /// <para>-or-</para> /// The directory is the application's current working directory. /// <para>-or-</para> /// There is an open handle on the directory, and the operating system is Windows XP or earlier. /// </exception> /// <exception cref="SecurityException">The caller does not have the required permission.</exception> public void Delete(bool recursive) { LongPathDirectory.Delete(this.NormalizedPath, recursive); this.Refresh(); }