当前位置: 首页>>代码示例>>C#>>正文


C# FileSystemInfo.Delete方法代码示例

本文整理汇总了C#中System.IO.FileSystemInfo.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# FileSystemInfo.Delete方法的具体用法?C# FileSystemInfo.Delete怎么用?C# FileSystemInfo.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileSystemInfo的用法示例。


在下文中一共展示了FileSystemInfo.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryDelete

        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;
        }
开发者ID:robocoder,项目名称:phpvh,代码行数:30,代码来源:FileSystemInfoHelper.cs

示例2: RecreateTestDb

 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();
 }
开发者ID:aduggleby,项目名称:dragon,代码行数:11,代码来源:IntegrationTestInitializer.cs

示例3: DeleteFileSystemInfo

        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();
        }
开发者ID:flyrev,项目名称:Smeedee_git_plugin,代码行数:11,代码来源:GitSharpTestFunctions.cs

示例4: DeletePlatformItem

        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();
        }
开发者ID:ZeoAlliance,项目名称:ApplicationInsights-dotnet,代码行数:12,代码来源:FileSystemTest.cs

示例5: Delete

 private void Delete(FileSystemInfo file)
 {
     try
     {
         file.Delete();
     }
     catch (Exception)
     {
         logger.Error("Could not delete " + file.Name);
         throw;
     }
 }
开发者ID:chandmk,项目名称:esddd,代码行数:12,代码来源:UploadDirectoryScanner.cs

示例6: Delete

        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();
        }
开发者ID:philcockfield,项目名称:Open.TestHarness.SL,代码行数:12,代码来源:CopyItem.cs

示例7: Delete

        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();
        }
开发者ID:roguesupport,项目名称:ControlCenter,代码行数:14,代码来源:DirectoryExt.cs

示例8: DeleteFileSystemInfo

        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();
        }
开发者ID:davidd2k,项目名称:OctoDB,代码行数:14,代码来源:StorageFixture.cs

示例9: DeleteFileSystemInfo

        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();
        }
开发者ID:FerdinandOlivier,项目名称:Warewolf-ESB,代码行数:15,代码来源:DirectoryHelper.cs

示例10: Apply

 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);
     }
 }
开发者ID:sri-n,项目名称:RecursiveCleaner,代码行数:19,代码来源:DeleteRule.cs

示例11: RemoveFileSystemItem

 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);
                 }
             }
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:86,代码来源:FileSystemProvider.cs

示例12: CleanLog

 /// <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);
     }
 }
开发者ID:snowsnail,项目名称:fog-client,代码行数:16,代码来源:Log.cs

示例13: Delete

 private static void Delete(FileSystemInfo f)
 {
     f.Delete();
 }
开发者ID:jagregory,项目名称:GitSharp,代码行数:4,代码来源:T0007_Index.cs

示例14: RemoveLocalItem

        /// <summary>
        /// Remove local item
        /// </summary>
        private bool RemoveLocalItem(FileSystemInfo item)
        {
            item.Delete();

            return true;
        }
开发者ID:wholroyd,项目名称:ShareFile-PowerShell,代码行数:9,代码来源:SyncSfItem.cs

示例15: DeleteFileIfExists

		protected void DeleteFileIfExists(FileSystemInfo file) {
			if (file.Exists){
				Report("Deleting " + file.FullName);
				if (file is DirectoryInfo)
					((DirectoryInfo)file).Delete(true);
				else
					file.Delete();
			}
		}
开发者ID:jhogan,项目名称:qed,代码行数:9,代码来源:Roller.cs


注:本文中的System.IO.FileSystemInfo.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。