Delete() 공개 추상적인 메소드

public abstract Delete ( ) : void
리턴 void
예제 #1
0
        public static bool TryDelete(FileSystemInfo info)
        {
            if (!info.Exists)
            {
                return false;
            }

            var success = true;
            var dir = info as DirectoryInfo;

            if (dir != null)
            {
                var children = dir
                    .GetFiles()
                    .OfType<FileSystemInfo>()
                    .Concat(dir.GetDirectories());

                foreach (var f in children)
                {
                    if (!TryDelete(f))
                    {
                        success = false;
                    }
                }
            }

            info.Delete();

            return success;
        }
 private static void RecreateTestDb(string testDbName, SqlConnection conn, FileSystemInfo mdfFile, FileSystemInfo ldfFile,
     string path)
 {
     new SqlCommand(string.Format(
         "IF EXISTS(SELECT name FROM sys.databases WHERE name = '{0}') DROP DATABASE {0}", testDbName), conn)
         .ExecuteNonQuery();
     if (mdfFile.Exists) mdfFile.Delete();
     if (ldfFile.Exists) ldfFile.Delete();
     new SqlCommand(string.Format("CREATE DATABASE {1} ON PRIMARY (Name={1}, filename = '{0}{1}.mdf')",
         path, testDbName), conn).ExecuteNonQuery();
 }
        protected static void DeleteFileSystemInfo(FileSystemInfo fsi)
        {
            fsi.Attributes = FileAttributes.Normal;
            var di = fsi as DirectoryInfo;

            if (di != null)
                foreach (var dirInfo in di.GetFileSystemInfos())
                    DeleteFileSystemInfo(dirInfo);

            fsi.Delete();
        }
        protected static void DeletePlatformItem(FileSystemInfo platformItem)
        {
            // If platformItem is a directory, then force delete its subdirectories
            var directory = platformItem as DirectoryInfo;
            if (directory != null)
            {
                directory.Delete(true);
                return;
            }

            platformItem.Delete();
        }
예제 #5
0
 private void Delete(FileSystemInfo file)
 {
     try
     {
         file.Delete();
     }
     catch (Exception)
     {
         logger.Error("Could not delete " + file.Name);
         throw;
     }
 }
예제 #6
0
        private static void Delete(FileSystemInfo file)
        {
            // Setup initial conditions.
            if (!file.Exists) return;
            var path = file.FullName;

            // Remove the read-only attribute.
            if (File.GetAttributes(path) == FileAttributes.ReadOnly) File.SetAttributes(path, FileAttributes.Normal);

            // Finish up.
            file.Delete();
        }
예제 #7
0
        public static void Delete(FileSystemInfo fileSystemInfo)
        {
            DirectoryInfo Dir = fileSystemInfo as DirectoryInfo;
            if (Dir != null)
            {
                foreach (FileSystemInfo Child in Dir.GetFileSystemInfos())
                {
                    Delete(Child);
                }
            }

            // Delete the root info
            fileSystemInfo.Delete();
        }
예제 #8
0
        private static void DeleteFileSystemInfo(FileSystemInfo fileSystemInfo)
        {
            var directoryInfo = fileSystemInfo as DirectoryInfo;
            if (directoryInfo != null)
            {
                foreach (var childInfo in directoryInfo.GetFileSystemInfos())
                {
                    DeleteFileSystemInfo(childInfo);
                }
            }

            fileSystemInfo.Attributes = FileAttributes.Normal;
            fileSystemInfo.Delete();
        }
        private static void DeleteFileSystemInfo(FileSystemInfo fsi)
        {
            CheckIfDeleteIsValid(fsi);
            fsi.Attributes = FileAttributes.Normal;
            var di = fsi as DirectoryInfo;

            if (di != null)
            {
                foreach (FileSystemInfo dirInfo in di.GetFileSystemInfos())
                {
                    DeleteFileSystemInfo(dirInfo);
                }
            }
            fsi.Delete();
        }
예제 #10
0
 public override void Apply(FileSystemInfo fsi, Environment environment)
 {
     if (!environment.IsSimulating)
     {
         try
         {
             fsi.Delete();
             Log.Info("Delete {0}... OK", fsi.FullName);
         }
         catch (Exception e)
         {
             Log.Warning("Delete {0}... {1}", fsi.FullName, e.Message);
         }
     }
     else
     {
         Log.Info("Delete {0}", fsi.FullName);
     }
 }
        public static void Delete(FileSystemInfo fileSystemInfo)
        {
            DirectoryInfo Dir = fileSystemInfo as DirectoryInfo;

            if (Dir != null && Dir.Exists)
            {
                foreach (FileSystemInfo Child in Dir.GetFileSystemInfos())
                {
                    Delete(Child);
                    System.Threading.Thread.Sleep(2);
                }
            }

            // Delete the root info
            if (fileSystemInfo.Exists)
            {
                fileSystemInfo.Attributes = FileAttributes.Normal;
                fileSystemInfo.Delete();
            }
        }
예제 #12
0
파일: Log.cs 프로젝트: snowsnail/fog-client
 /// <summary>
 ///     Wipe the log
 /// </summary>
 /// <param name="logFile"></param>
 private static void CleanLog(FileSystemInfo logFile)
 {
     try
     {
         logFile.Delete();
     }
     catch (Exception ex)
     {
         Error(LogName, "Failed to delete log file");
         Error(LogName, ex.Message);
     }
 }
예제 #13
0
 private static void DeleteLocalItemRecursive(FileSystemInfo source)
 {
     if (source is DirectoryInfo)
     {
         foreach (var child in (source as DirectoryInfo).EnumerateFileSystemInfos())
         {
             DeleteLocalItemRecursive(child);
         }
     }
    
     source.Delete();
 }
예제 #14
0
        /// <summary>
        /// Remove local item
        /// </summary>
        private bool RemoveLocalItem(FileSystemInfo item)
        {
            item.Delete();

            return true;
        }
예제 #15
0
 private static void Delete(FileSystemInfo f)
 {
     f.Delete();
 }
예제 #16
0
        void DeleteRecursive(FileSystemInfo fsi)
        {
            fsi.Attributes = FileAttributes.Normal;
            var di = fsi as DirectoryInfo;

            if (di != null)
            {
                foreach (var dirInfo in di.GetFileSystemInfos())
                {
                    DeleteRecursive(dirInfo);
                }
            }
            fsi.Delete();
        }
예제 #17
0
파일: Roller.cs 프로젝트: jhogan/qed
		protected void DeleteFileIfExists(FileSystemInfo file) {
			if (file.Exists){
				Report("Deleting " + file.FullName);
				if (file is DirectoryInfo)
					((DirectoryInfo)file).Delete(true);
				else
					file.Delete();
			}
		}
예제 #18
0
        } // RemoveFileInfoItem

        /// <summary>
        /// Removes the file system object from the file system.
        /// </summary>
        /// 
        /// <param name="fileSystemInfo">
        /// The FileSystemInfo object representing the file or directory to be removed.
        /// </param>
        /// 
        /// <param name="force">
        /// If true, the readonly and hidden attributes will be masked off in the case of
        /// an error, and the removal will be attempted again. If false, exceptions are
        /// written to the error pipeline.
        /// </param>
        /// 
        private void RemoveFileSystemItem(FileSystemInfo fileSystemInfo, bool force)
        {
            Dbg.Diagnostics.Assert(
                fileSystemInfo != null,
                "Caller should always check fileSystemInfo");

            //First check if we can delete this file when force is not specified.
            if (!Force &&
                (fileSystemInfo.Attributes & (FileAttributes.Hidden | FileAttributes.System | FileAttributes.ReadOnly)) != 0)
            {
                String error = StringUtil.Format(FileSystemProviderStrings.PermissionError);
                Exception e = new IOException(error);

                ErrorDetails errorDetails =
                    new ErrorDetails(this, "FileSystemProviderStrings",
                        "CannotRemoveItem",
                        fileSystemInfo.FullName,
                        e.Message);

                ErrorRecord errorRecord = new ErrorRecord(e, "RemoveFileSystemItemUnAuthorizedAccess", ErrorCategory.PermissionDenied, fileSystemInfo);
                errorRecord.ErrorDetails = errorDetails;

                WriteError(errorRecord);
                return;
            }

            // Store the old attributes in case we fail to delete
            FileAttributes oldAttributes = fileSystemInfo.Attributes;
            bool attributeRecoveryRequired = false;

            try
            {
                // Try to delete the item.  Strip any problematic attributes
                // if they've specified force.
                if (force)
                {
                    fileSystemInfo.Attributes = fileSystemInfo.Attributes & ~(FileAttributes.Hidden | FileAttributes.ReadOnly | FileAttributes.System);
                    attributeRecoveryRequired = true;
                }

                fileSystemInfo.Delete();

                if (force)
                {
                    attributeRecoveryRequired = false;
                }
            }
            catch (Exception fsException)
            {
                CommandProcessorBase.CheckForSevereException(fsException);

                ErrorDetails errorDetails =
                    new ErrorDetails(this, "FileSystemProviderStrings",
                        "CannotRemoveItem",
                        fileSystemInfo.FullName,
                        fsException.Message);

                if ((fsException is System.Security.SecurityException) ||
                    (fsException is UnauthorizedAccessException))
                {
                    ErrorRecord errorRecord = new ErrorRecord(fsException, "RemoveFileSystemItemUnAuthorizedAccess", ErrorCategory.PermissionDenied, fileSystemInfo);
                    errorRecord.ErrorDetails = errorDetails;

                    WriteError(errorRecord);
                }
                else if (fsException is ArgumentException)
                {
                    ErrorRecord errorRecord = new ErrorRecord(fsException, "RemoveFileSystemItemArgumentError", ErrorCategory.InvalidArgument, fileSystemInfo);
                    errorRecord.ErrorDetails = errorDetails;

                    WriteError(errorRecord);
                }
                else if ((fsException is IOException) ||
                    (fsException is FileNotFoundException) ||
                    (fsException is DirectoryNotFoundException))
                {
                    ErrorRecord errorRecord = new ErrorRecord(fsException, "RemoveFileSystemItemIOError", ErrorCategory.WriteError, fileSystemInfo);
                    errorRecord.ErrorDetails = errorDetails;

                    WriteError(errorRecord);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                if (attributeRecoveryRequired)
                {
                    try
                    {
                        if (fileSystemInfo.Exists)
                        {
                            fileSystemInfo.Attributes = oldAttributes;
                        }
                    }
                    catch (Exception attributeException)
                    {
                        CommandProcessorBase.CheckForSevereException(attributeException);

                        if ((attributeException is System.IO.DirectoryNotFoundException) ||
                            (attributeException is System.Security.SecurityException) ||
                            (attributeException is System.ArgumentException) ||
                            (attributeException is System.IO.FileNotFoundException) ||
                            (attributeException is System.IO.IOException))
                        {
                            ErrorDetails attributeDetails = new ErrorDetails(
                                this, "FileSystemProviderStrings",
                                    "CannotRestoreAttributes",
                                    fileSystemInfo.FullName,
                                    attributeException.Message);

                            ErrorRecord errorRecord = new ErrorRecord(attributeException, "RemoveFileSystemItemCannotRestoreAttributes", ErrorCategory.PermissionDenied, fileSystemInfo);
                            errorRecord.ErrorDetails = attributeDetails;

                            WriteError(errorRecord);
                        }
                        else
                            throw;
                    }
                }
            }
        } // RemoveFileSystemItem
예제 #19
0
 private void RemoveFileSystemItem(FileSystemInfo fileSystemInfo, bool force)
 {
     if ((base.Force == 0) && ((fileSystemInfo.Attributes & (System.IO.FileAttributes.System | System.IO.FileAttributes.Hidden | System.IO.FileAttributes.ReadOnly)) != 0))
     {
         Exception exception = new IOException(StringUtil.Format(FileSystemProviderStrings.PermissionError, new object[0]));
         ErrorDetails details = new ErrorDetails(this, "FileSystemProviderStrings", "CannotRemoveItem", new object[] { fileSystemInfo.FullName, exception.Message });
         ErrorRecord errorRecord = new ErrorRecord(exception, "RemoveFileSystemItemUnAuthorizedAccess", ErrorCategory.PermissionDenied, fileSystemInfo) {
             ErrorDetails = details
         };
         base.WriteError(errorRecord);
     }
     else
     {
         System.IO.FileAttributes attributes = fileSystemInfo.Attributes;
         bool flag = false;
         try
         {
             if (force)
             {
                 fileSystemInfo.Attributes &= ~(System.IO.FileAttributes.System | System.IO.FileAttributes.Hidden | System.IO.FileAttributes.ReadOnly);
                 flag = true;
             }
             fileSystemInfo.Delete();
             if (force)
             {
                 flag = false;
             }
         }
         catch (Exception exception2)
         {
             CommandProcessorBase.CheckForSevereException(exception2);
             ErrorDetails details2 = new ErrorDetails(this, "FileSystemProviderStrings", "CannotRemoveItem", new object[] { fileSystemInfo.FullName, exception2.Message });
             if ((exception2 is SecurityException) || (exception2 is UnauthorizedAccessException))
             {
                 ErrorRecord record2 = new ErrorRecord(exception2, "RemoveFileSystemItemUnAuthorizedAccess", ErrorCategory.PermissionDenied, fileSystemInfo) {
                     ErrorDetails = details2
                 };
                 base.WriteError(record2);
             }
             else if (exception2 is ArgumentException)
             {
                 ErrorRecord record3 = new ErrorRecord(exception2, "RemoveFileSystemItemArgumentError", ErrorCategory.InvalidArgument, fileSystemInfo) {
                     ErrorDetails = details2
                 };
                 base.WriteError(record3);
             }
             else
             {
                 if ((!(exception2 is IOException) && !(exception2 is FileNotFoundException)) && !(exception2 is DirectoryNotFoundException))
                 {
                     throw;
                 }
                 ErrorRecord record4 = new ErrorRecord(exception2, "RemoveFileSystemItemIOError", ErrorCategory.WriteError, fileSystemInfo) {
                     ErrorDetails = details2
                 };
                 base.WriteError(record4);
             }
         }
         finally
         {
             if (flag)
             {
                 try
                 {
                     if (fileSystemInfo.Exists)
                     {
                         fileSystemInfo.Attributes = attributes;
                     }
                 }
                 catch (Exception exception3)
                 {
                     CommandProcessorBase.CheckForSevereException(exception3);
                     if ((!(exception3 is DirectoryNotFoundException) && !(exception3 is SecurityException)) && ((!(exception3 is ArgumentException) && !(exception3 is FileNotFoundException)) && !(exception3 is IOException)))
                     {
                         throw;
                     }
                     ErrorDetails details3 = new ErrorDetails(this, "FileSystemProviderStrings", "CannotRestoreAttributes", new object[] { fileSystemInfo.FullName, exception3.Message });
                     ErrorRecord record5 = new ErrorRecord(exception3, "RemoveFileSystemItemCannotRestoreAttributes", ErrorCategory.PermissionDenied, fileSystemInfo) {
                         ErrorDetails = details3
                     };
                     base.WriteError(record5);
                 }
             }
         }
     }
 }
예제 #20
0
파일: Reducing.cs 프로젝트: udoliess/baco
 static void Delete(FileSystemInfo fileSystemInfo)
 {
     if ((fileSystemInfo.Attributes & FileAttributes.ReparsePoint) == 0)
     {
         var di = fileSystemInfo as DirectoryInfo;
         if (di != null)
             foreach (var fsi in di.EnumerateFileSystemInfos("*", SearchOption.TopDirectoryOnly))
                 Delete(fsi);
     }
     fileSystemInfo.Attributes = FileAttributes.Normal;
     fileSystemInfo.Delete();
 }
예제 #21
0
 private void DeleteFile(FileSystemInfo file)
 {
     file.Attributes = FileAttributes.Normal;
     file.Delete();
 }
예제 #22
0
        private static void DeleteFileSystemInfo(FileSystemInfo fileSystemInfo)
        {
            var directoryInfo = fileSystemInfo as DirectoryInfo;
            if (directoryInfo != null)
            {
                foreach (var childInfo in directoryInfo.GetFileSystemInfos())
                {
                    DeleteFileSystemInfo(childInfo);
                }
            }

            fileSystemInfo.Attributes = FileAttributes.Normal; // thumbnails can be intentionally readonly (when they are created by hand)
            fileSystemInfo.Delete();
        }
예제 #23
0
        public void DeleteFileSystemObject(FileSystemInfo fsi)
        {
            try
            {
                if (fsi.Exists)
                {
                    DirectoryInfo di = fsi as DirectoryInfo;
                    if (di != null)
                    {
                        PathUtils.DeleteFolderTree(fsi.FullName);

                        // File system changed => refresh will be required
                        this.RequiresRefresh = true;

                        return;
                    }

                    fsi.Attributes ^= fsi.Attributes;
                    fsi.Delete();

                    // File system changed => refresh will be required
                    this.RequiresRefresh = true;
                }
            }
            catch (Exception ex)
            {
                _task.AddToErrorMap(fsi.FullName, ex.Message);
            }
        }
예제 #24
0
 private void DeleteFileSystemInfo(FileSystemInfo fsi)
 {
     if (this.dryRun)
         fsi.Attributes = FileAttributes.Normal;
     var di = fsi as DirectoryInfo;
     this.deletedFiles++;
     if (di != null)
         foreach (var dirInfo in di.GetFileSystemInfos())
             DeleteFileSystemInfo(dirInfo);
     if (!this.dryRun)
         fsi.Delete();
 }
예제 #25
0
 /// <summary>
 /// Deletes the file or directory if it exists.
 /// </summary>
 /// <param name="info">FileInfo or DirectoryInfo instance</param>
 public void Delete(FileSystemInfo info)
 {
     if (info.Exists)
     info.Delete();
      info.Refresh();
 }
예제 #26
0
파일: Program.cs 프로젝트: CarlosVV/mediavf
        /// <summary>
        /// Delete file or directory
        /// </summary>
        /// <param name="fsi"></param>
        private static void DeleteFileSystemInfo(FileSystemInfo fileSystemInfo)
        {
            // ensure not read-only
            fileSystemInfo.Attributes = FileAttributes.Normal;

            // loop through children, if directory
            if (fileSystemInfo is DirectoryInfo)
                foreach (var childFileSystemInfo in ((DirectoryInfo)fileSystemInfo).GetFileSystemInfos())
                    DeleteFileSystemInfo(childFileSystemInfo);

            // delete
            fileSystemInfo.Delete();
        }
예제 #27
0
 private void DeleteFileSystemInfo(FileSystemInfo info)
 {
     info.CreationTime = info.LastWriteTime = info.LastAccessTime = MinTimestamp;
        info.Attributes = FileAttributes.Normal;
        info.Attributes = FileAttributes.NotContentIndexed;
        for (int i = 0, tries = 0; i < FileNameErasePasses; ++tries)
        {
     string newPath = GenerateRandomFileName(info.GetParent(), info.Name.Length);
     try
     {
      info.MoveTo(newPath);
      ++i;
     }
     catch (IOException e)
     {
      switch (System.Runtime.InteropServices.Marshal.GetLastWin32Error())
      {
       case Win32ErrorCode.AccessDenied:
        throw new UnauthorizedAccessException(S._("The file {0} could not " +
     "be erased because the file's permissions prevent access to the file.",
     info.FullName));
       case Win32ErrorCode.SharingViolation:
        if (tries > FileNameEraseTries)
     throw new IOException(S._("The file {0} is currently in use and " +
      "cannot be removed.", info.FullName), e);
        Thread.Sleep(100);
        break;
       default:
        throw;
      }
     }
        }
        for (int i = 0; i < FileNameEraseTries; ++i)
     try
     {
      info.Delete();
      break;
     }
     catch (IOException e)
     {
      switch (System.Runtime.InteropServices.Marshal.GetLastWin32Error())
      {
       case Win32ErrorCode.AccessDenied:
        throw new UnauthorizedAccessException(S._("The file {0} could not " +
     "be erased because the file's permissions prevent access to the file.",
     info.FullName), e);
       case Win32ErrorCode.SharingViolation:
        if (i > FileNameEraseTries)
     throw new IOException(S._("The file {0} is currently in use and " +
      "cannot be removed.", info.FullName), e);
        Thread.Sleep(100);
        break;
       default:
        throw;
      }
     }
 }
예제 #28
0
파일: Log.cs 프로젝트: FOGProject/zazzles
        /// <summary>
        ///     Wipe the log
        /// </summary>
        /// <param name="logFile"></param>
        private static void CleanLog(FileSystemInfo logFile)
        {
            if (logFile == null)
                throw new ArgumentNullException(nameof(logFile));

            try
            {
                logFile.Delete();
            }
            catch (Exception ex)
            {
                Error(LogName, "Failed to delete log file");
                Error(LogName, ex.Message);
            }
        }