Beispiel #1
0
        public static void SafeDeleteDirectory(
            string folderPath)
        {
#if WANT_TRACE
            Trace.TraceInformation(@"About to safe-delete directory '{0}'.", folderPath);
#endif

            if (!string.IsNullOrEmpty(folderPath) && SafeDirectoryExists(folderPath))
            {
                try
                {
                    ZlpIOHelper.DeleteDirectory(folderPath, true);
                }
                catch (Win32Exception x)
                {
                    var newFilePath = $@"{folderPath}.{Guid.NewGuid():B}.deleted";

#if WANT_TRACE
                    Trace.TraceWarning(@"Caught IOException while deleting directory '{0}'. " +
                                       @"Renaming now to '{1}'. {2}", folderPath, newFilePath, x.Message);
#endif

                    try
                    {
                        ZlpIOHelper.MoveDirectory(
                            folderPath,
                            newFilePath);
                    }
                    catch (Win32Exception x2)
                    {
#if WANT_TRACE
                        Trace.TraceWarning(@"Caught IOException while renaming upon failed deleting directory '{0}'. " +
                                           @"Renaming now to '{1}'. {2}", folderPath, newFilePath, x2.Message);
#endif
                    }
                }
            }
            else
            {
#if WANT_TRACE
                Trace.TraceInformation(@"Not safe-deleting directory '{0}', " +
                                       @"because the directory does not exist.", folderPath);
#endif
            }
        }
Beispiel #2
0
 public void Delete(bool recursive)
 {
     ZlpIOHelper.DeleteDirectory(FullName, recursive);
 }
Beispiel #3
0
 public void Delete(bool recursive)
 {
     ZlpIOHelper.DeleteDirectory(_path, recursive);
 }