本文整理汇总了C#中System.IO.DirectoryInfo.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Delete方法的具体用法?C# DirectoryInfo.Delete怎么用?C# DirectoryInfo.Delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了DirectoryInfo.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImportSettings
public void ImportSettings(BuildType buildType)
{
using (new WurmAssistantGateway(AppContext.WaGatewayErrorMessage))
{
using (var tempDirMan = new TempDirManager())
{
var tempDir = tempDirMan.GetHandle();
var dataDir = new DirectoryInfo(DataDirPath);
var tempBackupDir = new DirectoryInfo(Path.Combine(tempDir.FullName, dataDir.Name));
DirectoryEx.DirectoryCopyRecursive(dataDir.FullName, tempBackupDir.FullName);
try
{
dataDir.Delete(true);
var otherBuildDirPath = AppContext.GetDataDir(buildType);
DirectoryEx.DirectoryCopyRecursive(otherBuildDirPath, dataDir.FullName);
}
catch (Exception)
{
TransientHelper.Compensate(() => dataDir.Delete(true),
retryDelay: TimeSpan.FromSeconds(5));
TransientHelper.Compensate(() => DirectoryEx.DirectoryCopyRecursive(tempBackupDir.FullName, dataDir.FullName),
retryDelay: TimeSpan.FromSeconds(5));
throw;
}
}
}
}
示例2: DeleteFolder
/// <summary>
/// Deletes a folder and its children if it exists
/// </summary>
/// <param name="foldername"></param>
public void DeleteFolder()
{
// There has been a bug here where we are trying to delete the current path, strange but sadly true
//So we need to check it and change it
var dirInfo = new DirectoryInfo(FolderPath);
try
{
if (Directory.GetCurrentDirectory().Equals(FolderPath, StringComparison.CurrentCultureIgnoreCase))
{
Directory.SetCurrentDirectory(dirInfo.Parent.FullName);
}
dirInfo.Delete();
}
catch (IOException)
{
//Block here to allow the OS to catch up on all the deletes.
//The user can have the path open in explorer or another process so we need wait for it to be closed
//This is here because of an intermitent bug.
//My best guess is that a subfolder is being held open by explorer or the folder browser preventing it from being closed
//so that it's not deleted and the folder can not be deleted because it's not empty. I can't reproduce it now to comfirm this via procmon
System.Threading.Thread.Sleep(0);
dirInfo.Delete();
}
}
示例3: RunStarted
/// <summary>
/// Runs custom wizard logic at the beginning of a template wizard run.
/// </summary>
/// <param name="automationObject">The automation object being used by the template wizard.</param>
/// <param name="replacementsDictionary">The list of standard parameters to be replaced.</param>
/// <param name="runKind">A <see cref="T:Microsoft.VisualStudio.TemplateWizard.WizardRunKind"/> indicating the type of wizard run.</param>
/// <param name="customParams">The custom parameters with which to perform parameter replacement in the project.</param>
public void RunStarted(object automationObject, Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
{
//if (!new Microsoft.CSharp.CSharpCodeProvider().IsValidIdentifier(replacementsDictionary["$projectname$"]))
// throw new InvalidOperationException("Your chosen project name " + replacementsDictionary["$projectname$"] + " must be a valid C# code identifier.");
var targetDir = new DirectoryInfo(replacementsDictionary["$destinationdirectory$"]);
var extensionsRoot = (from parentDir in TraverseUp(targetDir)
// Lookup the root of the netfx repository
where parentDir.EnumerateFileSystemInfos("netfx.txt").Any()
// Then move down to the Extensions directory where all extensions live
select parentDir.EnumerateDirectories("Extensions").FirstOrDefault())
.FirstOrDefault();
if (extensionsRoot == null)
{
targetDir.Delete(true);
Backout(string.Format(
"Selected target path '{0}' is not located under the root NETFx Extensions repository folder.", targetDir));
}
var pathToRoot = Regex
.Replace(targetDir.FullName, extensionsRoot.FullName.Replace("\\", "\\\\"), "", RegexOptions.IgnoreCase)
.Split(Path.DirectorySeparatorChar)
.Aggregate("..\\", (result, current) => result + "..\\");
var ns = string.Join(".", Regex
// We start from the parent directory, as we'll use the $safeprojectname$ to build the identifier later
.Replace(targetDir.Parent.FullName, extensionsRoot.FullName.Replace("\\", "\\\\"), "", RegexOptions.IgnoreCase)
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries)
.Select(s => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s))
.Concat(new[] { replacementsDictionary["$projectname$"] }));
var identifier = "NetFx." + ns;
var view = new ExtensionInformationView();
view.Model.Identifier = identifier;
view.Model.Title = "NETFx " + ExtensionTitleSuggestion.Suggest(
Regex.Replace(targetDir.Parent.FullName, extensionsRoot.FullName.Replace("\\", "\\\\"), "", RegexOptions.IgnoreCase),
replacementsDictionary["$projectname$"]);
view.Model.PathToRoot = pathToRoot;
view.Model.TargetNamespace = ns.Substring(0, ns.LastIndexOf('.'));
view.Model.Authors = replacementsDictionary["$username$"] + ", Clarius";
view.Model.Tags = "netfx foo bar";
view.Owner = Application.Current.MainWindow;
if (view.ShowDialog().GetValueOrDefault())
{
foreach (var property in typeof(ExtensionInformationModel).GetProperties())
{
CallContext.SetData("$" + property.Name + "$", property.GetValue(view.Model, null).ToString().XmlEncode());
}
}
else
{
targetDir.Delete(true);
throw new WizardBackoutException();
}
}
示例4: moveDatabaseLocations
//[Repeat(3)]
public void moveDatabaseLocations()
{
SessionBase.BaseDatabasePath = "d:/Databases"; // use same as VelocityDbServer.exe.config
DirectoryInfo info = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath, systemDir));
if (info.Exists)
info.Delete(true);
DirectoryInfo newInfo = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath, systemDir + "MovedTo"));
string newPath = newInfo.FullName;
if (newInfo.Exists)
newInfo.Delete(true);
createDatabaseLocations(new SessionNoServer(systemDir));
info.MoveTo(newPath);
moveDatabaseLocations(new SessionNoServer(newPath, 2000, false, false), systemHost, newPath);
verifyDatabaseLocations(new SessionNoServer(newPath));
info.Delete(true);
info = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath, systemDir));
if (info.Exists)
info.Delete(true);
createDatabaseLocations(new ServerClientSession(systemDir));
newPath = Path.Combine(SessionBase.BaseDatabasePath, systemDir + "MovedTo");
info.MoveTo(newPath);
moveDatabaseLocations(new ServerClientSession(newPath, systemHost, 2000, false, false), systemHost, newPath);
verifyDatabaseLocations(new ServerClientSession(newPath, systemHost));
info.Delete(true);
info = new DirectoryInfo(Path.Combine(SessionBase.BaseDatabasePath, systemDir));
if (info.Exists)
info.Delete(true);
string d = SessionBase.BaseDatabasePath;
try
{
SessionBase.BaseDatabasePath = "\\\\" + systemHost2 + "\\Shared";
newPath = Path.Combine(SessionBase.BaseDatabasePath, systemDir);
info = new DirectoryInfo(newPath);
createDatabaseLocations(new ServerClientSession(newPath, systemHost2));
SessionBase.BaseDatabasePath = d;
newPath = Path.Combine(SessionBase.BaseDatabasePath, systemDir + "MovedTo");
string[] files = Directory.GetFiles(info.FullName);
Directory.CreateDirectory(newPath);
foreach (string file in files)
{
string name = Path.GetFileName(file);
string dest = Path.Combine(newPath, name);
File.Copy(file, dest);
}
info.Delete(true);
info = new DirectoryInfo(newPath);
moveDatabaseLocations(new ServerClientSession(newPath, systemHost, 2000, false, false), systemHost, newPath);
verifyDatabaseLocations(new ServerClientSession(newPath));
info.Delete(true);
}
finally
{
SessionBase.BaseDatabasePath = d;
}
}
示例5: Execute
public static int Execute(FileInfo deployFile, string targetName)
{
DirectoryInfo packageDir = new DirectoryInfo(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
if (packageDir.Exists)
{
packageDir.Delete(true);
}
int returnCode = -1;
try
{
packageDir.Create();
Console.WriteLine(string.Format("[ExecutionInfo] Machine : {0} - Username : {1}\\{2} - Time : {3:yyyy-MM-dd HH:mm}", Environment.MachineName, Environment.UserDomainName, Environment.UserName, DateTime.Now));
Console.WriteLine(string.Format("Extracting package {0} into {1}...", deployFile.FullName, packageDir.FullName));
ZipHelper.CheckNAntConsoleVersion(deployFile);
ZipHelper.UnZip(deployFile, packageDir);
Version packageVersion;
if (File.Exists(Path.Combine(packageDir.FullName, EnvIncludeConstants.VERSION_FILENAME)))
{
try
{
packageVersion = new Version(File.ReadAllText(Path.Combine(packageDir.FullName, EnvIncludeConstants.VERSION_FILENAME)));
}
catch
{
}
}
NAntProject nantProject = GetNantProject(packageDir);
returnCode = NAntHelper.ExecuteNant(nantProject, targetName, delegate(NAntExecutionProgressEventArgs progressArgs)
{
Console.WriteLine(progressArgs.Message);
});
}
catch (VersionNotFoundException versionEx)
{
Console.WriteLine(string.Format("Fatal error : {0}.", versionEx));
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Fatal error : {0}.", ex));
}
finally
{
packageDir.Delete(true);
}
return returnCode;
}
示例6: LogBTNDelete_Click
// Deletes a single log file or a directory (NYI)
private void LogBTNDelete_Click(object sender, EventArgs e)
{
FileTreeNode fn = (FileTreeNode)logFilesTreeView.SelectedNode;
DialogResult dr = MessageBox.Show("Do you really want to delete " + fn.Text + "?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
if (dr == DialogResult.No)
return;
if (fn.IsFile)
{
FileInfo fi = new FileInfo(fn.Path);
if (fi.Exists)
{
fi.Delete();
}
}
else
{
DirectoryInfo di = new DirectoryInfo(fn.Path);
if (di.Exists)
{
di.Delete(true);
}
}
logFilesTreeView.Nodes.Remove(logFilesTreeView.SelectedNode);
}
示例7: DeleteDirectory
public static void DeleteDirectory(string directoryPath, bool recursive)
{
if (String.IsNullOrEmpty(directoryPath))
{
return;
}
DirectoryInfo dirInfo = new DirectoryInfo(directoryPath);
if (dirInfo.Exists)
{
// It is a directory...
try
{
dirInfo.Attributes = FileAttributes.Normal;
dirInfo.Delete(recursive);
}
catch (UnauthorizedAccessException)
{
// One possible cause of this is read-only file, so first
// try another method of deleting the directory...
foreach (string file in DirectoryUtils.FindFiles(dirInfo, "*.*",
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
dirInfo.Delete(recursive);
}
}
}
示例8: ExtractArchive
/// <summary>
/// Extracts archive into tempoary location
/// </summary>
/// <param name="filepathFrom"></param>
public void ExtractArchive(string archivePath)
{
Directory.CreateDirectory("TEMP");
DirectoryInfo dinfo = new DirectoryInfo("TEMP");
try
{
Ionic.Zip.ZipFile archive = Ionic.Zip.ZipFile.Read(archivePath);
ReadZip(archive, dinfo);
MoveFilesToSingleFolder(dinfo, "All");
archive.Dispose();
dinfo = null;
}
catch (IOException) { dinfo.Delete(true); }
catch (Exception) { dinfo.Delete(true); }
}
示例9: createTempDirectory
public static DirectoryInfo createTempDirectory(Boolean export)
{
errorMessage = "";
DirectoryInfo tmpDirectory;
String tmpDir;
try
{
if(export)
tmpDir = Export.exportDirectory + DateTime.Now.ToString("yyyyMMdd_HHmmss");
else
tmpDir = Export.importDirectory + DateTime.Now.ToString("yyyyMMdd_HHmmss");
tmpDirectory = new DirectoryInfo(Path.Combine(Path.GetTempPath(), tmpDir));
if(tmpDirectory.Exists)
tmpDirectory.Delete(true);
tmpDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), tmpDir));
Directory.CreateDirectory(Path.Combine(tmpDirectory.FullName, resourceDirectory));
}
catch (Exception e)
{
errorMessage += Director.Properties.Resources.ExportProcessTempDirEx + e.Message;
return null;
}
return tmpDirectory;
}
示例10: DeleteDir
/// <summary>
/// Helper method to delete the cache dir. This method deals
/// with a bug that occurs when pdb files are marked read-only.
/// </summary>
/// <param name="cacheDir"></param>
public static void DeleteDir( DirectoryInfo cacheDir )
{
if(cacheDir.Exists)
{
foreach( DirectoryInfo dirInfo in cacheDir.GetDirectories() )
{
dirInfo.Attributes &= ~FileAttributes.ReadOnly;
DeleteDir( dirInfo );
}
foreach( FileInfo fileInfo in cacheDir.GetFiles() )
{
fileInfo.Attributes &= ~FileAttributes.ReadOnly;
}
try
{
cacheDir.Delete(true);
}
catch
{
//Do Nothing
}
}
}
示例11: DeleteIfNotRelevant
public void DeleteIfNotRelevant(DirectoryInfo subdirectory)
{
String name = subdirectory.Name;
if( IsCurrentConfiguration(name) ) return;
DirectoryInfo di = new DirectoryInfo( GetPlannedRouteLocalPath(name) );
di.Delete(true);
}
示例12: SetUp
public void SetUp()
{
var di = new DirectoryInfo(AppDomain.CurrentDomain.GetData("DataDirectory") as string ??
(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data"));
if (di.Exists) di.Delete(true);
di.Create();
}
示例13: RemoveIfEmpty
static bool RemoveIfEmpty(DirectoryInfo Dir)
{
bool r = false;
DirectoryInfo[] Dirs = Dir.GetDirectories();
int n = Dirs.Length;
if (n != 0)
{
for (int i = 0; i < n; i++)
{
RemoveIfEmpty(Dirs[i]);
}
}
if (Dir.GetFiles().Length == 0 && Dir.GetDirectories().Length == 0)
{
Dir.Delete();
Console.WriteLine("Removing the Empty Directory [" + Dir.FullName + "]");
r = true;
}
else
Console.WriteLine("Skipping the Empty Directory [" + Dir.FullName + "]");
return r;
}
示例14: Render
/// <summary>
/// Generates SriptSharp files
/// </summary>
/// <param name="entries">List of jQueryUI entries.</param>
public void Render(IList<Entry> entries)
{
if (entries == null) {
return;
}
DirectoryInfo destination = new DirectoryInfo(DestinationPath);
if (destination.Exists) {
destination.Delete(true);
}
foreach (Entry entry in entries.Where(e => e.Type != "selector" && e.Name != "jQuery.ui.mouse" && e.Name != "jQuery.widget")) {
Messages.WriteLine("Generating " + Path.Combine(DestinationPath, Utils.PascalCase(entry.Name)));
RenderEntry(entry);
}
Messages.WriteLine("Generating jQueryUI base files.");
RenderEventHandler();
RenderBox();
RenderSize();
RenderEffectExtensionMethods(entries.Where(e => e.Type == "effect"));
RenderInteractionOrWidgetExtensionMethods("Interaction", entries.Where(e => e.Categories.Contains("interactions") && e.Name != "jQuery.ui.mouse"));
RenderInteractionOrWidgetExtensionMethods("Widget", entries.Where(e => e.Categories.Contains("widgets") && e.Name != "jQuery.Widget"));
RenderExtensionMethods(entries.Where(e => e.Type == "method"));
}
示例15: DeleteDirectory
public void DeleteDirectory(string relativePath)
{
string path = Combine(root, relativePath);
var dir = new DirectoryInfo(path);
if (dir.Exists)
dir.Delete();
}