本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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();
}
示例5: Delete
private void Delete(FileSystemInfo file)
{
try
{
file.Delete();
}
catch (Exception)
{
logger.Error("Could not delete " + file.Name);
throw;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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);
}
}
}
}
}
示例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);
}
}
示例13: Delete
private static void Delete(FileSystemInfo f)
{
f.Delete();
}
示例14: RemoveLocalItem
/// <summary>
/// Remove local item
/// </summary>
private bool RemoveLocalItem(FileSystemInfo item)
{
item.Delete();
return true;
}
示例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();
}
}