本文整理汇总了C#中System.IO.DirectoryInfo.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.DirectoryInfo.Delete方法的具体用法?C# System.IO.DirectoryInfo.Delete怎么用?C# System.IO.DirectoryInfo.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.DirectoryInfo
的用法示例。
在下文中一共展示了System.IO.DirectoryInfo.Delete方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: delete_btn_Click
private void delete_btn_Click(object sender, EventArgs e) {
if (dataGridView1.Rows.Count > 0) {
int currentRow = dataGridView1.CurrentCell.RowIndex;
DialogResult result = MessageBox.Show("本当に削除してもよろしいですか?",
"確認",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button2);
//何が選択されたか調べる
if (result == DialogResult.OK) {
//OKが選択された時
string id = (string)dataGridView1.CurrentRow.Cells[0].Value;
_db.DeleteRecord(int.Parse(id));
RefreshDGV();
SelectRow(currentRow - 1);
//ディレクトリのユーザー用データ構造を削除
System.IO.DirectoryInfo delDir = new System.IO.DirectoryInfo(_rootDir + id);
// ディレクトリの削除
delDir.Delete(true);
}
}
}
示例2: cleanTempFolder
private void cleanTempFolder( System.Object value )
{
try {
if ( value!=null ) {
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo (value.ToString());
dir.Delete(true);
dir=null;
}
} catch( System.Exception ) {
}
}
示例3: cleanTempFolder
private void cleanTempFolder( System.Object value )
{
try {
if ( value!=null ) {
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo (value.ToString());
if ( dir.Exists )
dir.Delete(true);
dir=null;
}
} catch( System.Exception e ) {
if ( log.IsErrorEnabled )
log.Error("Error cleanling up dir", e);
}
}
示例4: RemoveFolder
/// <summary>
/// 删除整个目录和文件
/// </summary>
/// <param name="folderPathName">目录名称</param>
/// <returns>bool</returns>
public static bool RemoveFolder(string folderPathName)
{
try
{
System.IO.DirectoryInfo delFolder = new System.IO.DirectoryInfo(folderPathName);
if (delFolder.Exists)
{
delFolder.Delete();
}
return true;
}
catch
{
return false;
}
}
示例5: GV_Result_RowCommand
protected void GV_Result_RowCommand(Object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Approved")
{
int newindex = Convert.ToInt32(e.CommandArgument);
string quoteid = GV_Result.Rows[newindex].Cells[2].Text;
string tourid = GV_Result.Rows[newindex].Cells[3].Text;
string usrid = Session["usersid"].ToString();
DataSet ds = objfitquote.fetchallData("FETCH_DATA_FOR_ALL_QUOTED_FIT_QUOTES", usrid);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (quoteid == ds.Tables[0].Rows[i]["QUOTE_ID"].ToString() && tourid == ds.Tables[0].Rows[i]["TOUR_ID"].ToString())
{
Session["editorderstatus"] = ds.Tables[0].Rows[i]["ORDER_STATUS"].ToString();
}
}
Response.Redirect("~/Views/FIT/AdminBookingFit.aspx?TOURID=" + tourid + ""EID=" + quoteid);
}
else if (e.CommandName == "Disapproved")
{
int newindex = Convert.ToInt32(e.CommandArgument);
string quoteid = GV_Result.Rows[newindex].Cells[2].Text;
objfitquote.DeleteQuote(quoteid);
System.IO.DirectoryInfo thisFolder = new System.IO.DirectoryInfo(Server.MapPath("~/Views/FIT/Quotes/" + quoteid.ToString()));
foreach (System.IO.FileInfo file in thisFolder.GetFiles())
{
file.Delete();
}
if (thisFolder.Exists)
{
thisFolder.Delete();
}
DataSet ds = objfitquote.fetchallData("FETCH_DATA_FOR_ALL_QUOTED_FIT_QUOTES", Session["usersid"].ToString());
if (ds.Tables[0].Rows.Count == 0)
{
}
else
{
GV_Result.DataSource = ds;
GV_Result.DataBind();
}
Updateconfirm.Update();
Master.DisplayMessage("Quote Deleted Successfully.", "successMessage", 8000);
}
}
示例6: DeletePrintFolder
private void DeletePrintFolder()
{
var folderInfo = new System.IO.DirectoryInfo(FullPrintJobFolder);
if (folderInfo.Exists)
{
folderInfo.Delete(true);
}
}
示例7: ReleaseUnmanagedResources
private void ReleaseUnmanagedResources()
{
var di = new System.IO.DirectoryInfo(_sandboxPath);
if (di.Exists)
{
di.Delete(true);
}
}
示例8: StartMinecraft
public void StartMinecraft()
{
SetProgress();
SetStatus("Cleaning up...");
var tmpdir = new System.IO.DirectoryInfo(System.IO.Path.Combine(App.GamePath, "tmp"));
if (tmpdir.Exists)
tmpdir.Delete(true);
tmpdir.Create();
SetStatus("Starting client...");
var javaw = JavaPath.CreateJava(new[] {
"-Xmx" + config.MaximalRam.ToMegabytes() + "M",
"-Xincgc",
/*Environment.Is64BitProcess*/ IntPtr.Size == 8 ? "-d64" : "-d32",
"-Djava.library.path=" + App.StartupLibrarypath,
"-Djava.io.tmpdir=" + System.IO.Path.Combine(App.GamePath, "tmp"),
"-cp", App.StartupClasspath,
"net.minecraft.client.Minecraft",
l.CaseCorrectUsername,
l.SessionId,
"minas.mc.modernminas.de:25565"
});
javaw.StartInfo.WorkingDirectory = App.GamePath;
if (javaw.StartInfo.EnvironmentVariables.ContainsKey("APPDATA"))
javaw.StartInfo.EnvironmentVariables["APPDATA"] = App.GamePath;
else
javaw.StartInfo.EnvironmentVariables.Add("APPDATA", App.GamePath);
if (javaw.StartInfo.EnvironmentVariables.ContainsKey("HOME"))
javaw.StartInfo.EnvironmentVariables["HOME"] = App.GamePath;
else
javaw.StartInfo.EnvironmentVariables.Add("HOME", App.GamePath);
javaw.StartInfo.RedirectStandardError = true;
javaw.StartInfo.RedirectStandardOutput = true;
javaw.StartInfo.CreateNoWindow = true;
Debug.WriteLine(string.Format("Starting minecraft, arguments: {0}", javaw.StartInfo.Arguments));
javaw.Start();
SetError(null);
this.Dispatcher.Invoke(new Action(() =>
{
this.Hide();
}));
#if STATUS_WINDOW
#warning Status window eats a high amount of CPU on a single core. Not recommended for release.
// Status window
System.Threading.Tasks.Task.Factory.StartNew(
() =>
{
this.Dispatcher.Invoke(new Action(w.Show));
while (!javaw.HasExited)
{
RefreshStatusWindowPos();
System.Threading.Thread.Sleep(750); // Slow refresh if visible
}
this.Dispatcher.Invoke(new Action(w.Close));
});
#endif
// STDERR
System.Threading.Tasks.Task.Factory.StartNew(
() =>
{
string lastError = null;
while (!javaw.HasExited)
{
lastError = javaw.StandardError.ReadLine();
if (lastError != null) lastError = lastError.Trim();
Debug.WriteLine(string.Format("[Minecraft] STDERR: {0}", lastError));
if (lastError == null)
continue;
#if STATUS_WINDOW
if (lastError.Contains("early MinecraftForge initialization"))
this.Dispatcher.Invoke(new Action(() => { w.Show(); w.Fade(1.0, null, 250); }));
else if (lastError.Contains("/panorama"))
this.Dispatcher.Invoke(new Action(() => w.Fade(0.0, null, 10, (EventHandler)((sender, e) => { w.Hide(); }))));
#endif
lastError = string.Join(" ", lastError.Split(' ').Skip(3).ToArray());
#if STATUS_WINDOW
// loading text
Match m;
if ((m = Regex.Match(lastError, "setupTexture: \"(.+)\"")).Success)
lastError = "Loading texture: " + m.Groups[1].Value;
//lastError = "Loading textures...";
else if (lastError.Contains("[STDOUT] Checking for new version"))
lastError = "Checking for Optifine updates...";
else if (lastError.Contains("Connecting"))
lastError = "Connecting to the server...";
else if ((m = Regex.Match(lastError, "TextureFX registered: (.+)")).Success)
lastError = "Loading texture effects...";
else if ((m = Regex.Match(lastError, "TextureFX removed: (.+)")).Success)
lastError = "Unloading texture effects...";
else if ((m = Regex.Match(lastError, "Loading custom colors: (.+)")).Success)
lastError = "Loading custom colors...";
else if ((m = Regex.Match(lastError, "\\[(.+)\\] (Initializing|Starting|Loading|Attempting|Config) ([^\\s]+) .*")).Success)
//.........这里部分代码省略.........
示例9: Main
static void Main()
{
// Delete a file by using File class static method...
if(System.IO.File.Exists(@"C:\Users\Public\DeleteTest\test.txt"))
{
// Use a try block to catch IOExceptions, to
// handle the case of the file already being
// opened by another process.
try
{
System.IO.File.Delete(@"C:\Users\Public\DeleteTest\test.txt");
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
return;
}
}
// ...or by using FileInfo instance method.
System.IO.FileInfo fi = new System.IO.FileInfo(@"C:\Users\Public\DeleteTest\test2.txt");
try
{
fi.Delete();
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
// Delete a directory. Must be writable or empty.
try
{
System.IO.Directory.Delete(@"C:\Users\Public\DeleteTest");
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
// Delete a directory and all subdirectories with Directory static method...
if(System.IO.Directory.Exists(@"C:\Users\Public\DeleteTest"))
{
try
{
System.IO.Directory.Delete(@"C:\Users\Public\DeleteTest", true);
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
}
// ...or with DirectoryInfo instance method.
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:\Users\Public\public");
// Delete this dir and all subdirs.
try
{
di.Delete(true);
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
}
}
开发者ID:terryjintry,项目名称:OLSource1,代码行数:65,代码来源:how-to--copy--delete--and-move-files-and-folders--csharp-programming-guide-_3.cs
示例10: deleteFileGeodatabaseWorkspace
/*
* A utility class to delete a File Geodatabase (FGDB).
*/
public static bool deleteFileGeodatabaseWorkspace(ref log4net.ILog log, string workspaceDirectory, string workspaceFolderName)
{
// attempt to delete the referenced File Geodatabase (FGDB)
log.Debug("Attempting to delete the referenced File Geodatabase (FGDB).");
log.Debug("workspaceDirectory: " + workspaceDirectory);
log.Debug("workspaceFolderName: " + workspaceFolderName);
try
{
// verify the workspace does already exist
log.Debug("Verifying if the File Geodatabase exists.");
if (!System.IO.Directory.Exists(workspaceDirectory + "\\" + workspaceFolderName))
{
// the File Geodatabase does not exist
log.Warn("File Geodatabase does not exist. Unable to delete.");
throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_deleteFileGeodatabaseWorkspace_notfound);
}
else
{
// File Geodatabase exists, create a new DirecotryInfo object to represent the <name>.gdb
log.Debug("File Geodatabase exists, creating a new DirectoryInfo object to represent the .gdb.");
System.IO.DirectoryInfo dinfo = new System.IO.DirectoryInfo(workspaceDirectory + "\\" + workspaceFolderName);
// once again, verifying the folder itself exists
log.Debug("Checking again to see if the folder itself exists.");
if (dinfo.Exists)
{
// the File Geodatabase folder exists. Attempt to delete it.
log.Debug("File Geodatabase folder exists, attempt to delete it.");
dinfo.Delete(true);
// return true
log.Debug("Returning true/successful.");
return true;
}
else
{
// the <name>.gdb folder does not exist, return false
log.Debug("File Geodatabase folder does not exist, return false.");
return false;
}
}
}
catch (System.Exception ex)
{
// an unknown error occured, log and throw
log.Error(ex);
throw new System.Exception(Properties.Resources.fgdb_GeodatabaseUtilities_deleteFileGeodatabaseWorkspace_unknown);
}
}
示例11: EmptyFolder
public static void EmptyFolder(string sourceFolder)
{
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(sourceFolder);
foreach (System.IO.FileInfo file in directory.GetFiles())
{
file.Delete();
}
foreach (System.IO.DirectoryInfo dir in directory.GetDirectories())
{
dir.Delete(true);
}
directory.Delete();
}
示例12: CleanDirectoryAndFiles
internal void CleanDirectoryAndFiles(string Path)
{
System.IO.DirectoryInfo _directory = new System.IO.DirectoryInfo(Path);
foreach ( System.IO.DirectoryInfo _childDirectory in _directory.GetDirectories())
{
CleanDirectoryAndFiles(_childDirectory.FullName);
}
System.IO.FileInfo[] _files = _directory.GetFiles();
foreach (System.IO.FileInfo _file in _files)
{
_file.Delete();
}
_directory.Delete();
}
示例13: cleanupTempDirectories
public static void cleanupTempDirectories()
{
string mainPath = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string func = mainPath + "\\RmrsRasterUtilityHelp\\func";
string mos = mainPath + "\\RmrsRasterUtilityHelp\\mosaic";
string conv = mainPath + "\\RmrsRasterUtilityHelp\\conv";
string[] dirs = {func,mos,conv};
foreach (string s in dirs)
{
try
{
System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(s);
if(dInfo.Exists) dInfo.Delete(true);
}
catch
{
}
}
}
示例14: Main
//.........这里部分代码省略.........
outFile.WriteLine ("Name: " + tempPath);
outFile.WriteLine ("Func: " + "System.IO.Directory.SetCurrentDirectory(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + "");
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
now = System.DateTime.Now;
System.IO.Directory.Move (tempPath + "\\TestDir1", tempPath + "\\TestDir2");
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\TestDir1");
outFile.WriteLine ("Func: " + "System.IO.Directory.Move(String, String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
//---
outFile.WriteLine ("Name: " + tempPath + "\\TestDir2");
outFile.WriteLine ("Func: " + "System.IO.Directory.Move(String, String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + "");
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
now = System.DateTime.Now;
System.IO.Directory.Delete (tempPath + "\\TestDir1");
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\TestDir1");
outFile.WriteLine ("Func: " + "System.IO.Directory.Delete(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + "");
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
try {
exc = null;
now = System.DateTime.Now;
System.IO.Directory.Delete (tempPath + "\\TestDir2");
} catch (Exception e) {
exc = e;
} finally {
outFile.WriteLine ("Name: " + tempPath + "\\TestDir2");
outFile.WriteLine ("Func: " + "System.IO.Directory.Delete(String)");
outFile.WriteLine ("Proc: " + System.Diagnostics.Process.GetCurrentProcess ().Id);
outFile.WriteLine ("Time: " + GetTime (now));
outFile.WriteLine ("Retv: " + "");
outFile.WriteLine ("Errc: " + "");
outFile.WriteLine ("Exce: " + GetException (exc));
}
} catch (Exception) {
}
try {
di = null;
di = new System.IO.DirectoryInfo (tempPath);