本文整理汇总了C#中File.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# File.Delete方法的具体用法?C# File.Delete怎么用?C# File.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File.Delete方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAndSaveLocal
public void CreateAndSaveLocal()
{
IKp2aApp app = new TestKp2aApp();
IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename};
File outputDir = new File(DefaultDirectory);
outputDir.Mkdirs();
File targetFile = new File(ioc.Path);
if (targetFile.Exists())
targetFile.Delete();
bool createSuccesful = false;
//create the task:
CreateDb createDb = new CreateDb(app, Application.Context, ioc, new ActionOnFinish((success, message) =>
{ createSuccesful = success;
if (!success)
Android.Util.Log.Debug("KP2A_Test", message);
}), false);
//run it:
createDb.Run();
//check expectations:
Assert.IsTrue(createSuccesful);
Assert.IsNotNull(app.GetDb());
Assert.IsNotNull(app.GetDb().KpDatabase);
//the create task should create two groups:
Assert.AreEqual(2, app.GetDb().KpDatabase.RootGroup.Groups.Count());
//ensure the the database can be loaded from file:
PwDatabase loadedDb = new PwDatabase();
loadedDb.Open(ioc, new CompositeKey(), null, new KdbxDatabaseFormat(KdbxFormat.Default));
//Check whether the databases are equal
AssertDatabasesAreEqual(loadedDb, app.GetDb().KpDatabase);
}
示例2: clearFilesDir
private void clearFilesDir()
{
File dir = activity.FilesDir;
if(dir == null || !dir.Exists())
return;
string[] children = dir.List();
foreach (string s in children) {
File f = new File(dir, s);
if(f.Name.EndsWith(".note"))
f.Delete();
}
}
示例3: WriteToFile
public void WriteToFile(string fileName, string text)
{
try
{
File file = new File(context.FilesDir.AbsolutePath, fileName);
if (file.Exists())
{
file.Delete();
}
var outputStreamWriter = new OutputStreamWriter(context.OpenFileOutput(fileName, FileCreationMode.Private));
outputStreamWriter.Write(text);
outputStreamWriter.Close();
}
catch (IOException e)
{
Log.Debug("Exception", "File write failed: " + e.ToString());
}
}
示例4: DeleteDir
public static bool DeleteDir(File dir, bool contentsOnly=false)
{
if (dir != null && dir.IsDirectory)
{
String[] children = dir.List();
for (int i = 0; i < children.Length; i++)
{
bool success = DeleteDir(new File(dir, children[i]));
if (!success)
{
return false;
}
}
}
if (contentsOnly)
return true;
// The directory is now empty so delete it
return dir.Delete();
}
示例5: Convert
static public string Convert(File file, Encoding targetEnc)
{
Trace.WriteLine("Converting " + file.Name + file.Extension + " to " + targetEnc.ToString("G"));
// Read in file & formatting
IAudioReader Reader = new DsReader(file.Path);
IntPtr SourceFormat = Reader.ReadFormat();
IntPtr TargetFormat = AudioCompressionManager.GetCompatibleFormat(SourceFormat, AudioCompressionManager.MpegLayer3FormatTag);
// Create new file
byte[] Data = Reader.ReadData();
byte[] Output = AudioCompressionManager.Convert(SourceFormat, TargetFormat, Data, true);
string Filename = Path.GetDirectoryName(file.Path) + "\\" + file.Name + "." + targetEnc.ToString("G").ToLower();
BinaryWriter Writer = new BinaryWriter(System.IO.File.Create(Filename));
Writer.Write(Output, 0, Output.Length);
// Cleanup & remove source
Reader.Close();
Writer.Close();
file.Delete();
return Filename;
}
示例6: deleteNote
private void deleteNote(string guid)
{
try {
File path = new File(Tomdroid.NOTES_PATH + "/" + guid + ".note");
path.Delete();
}
catch (Exception e) {
TLog.e(TAG, "delete from sd card didn't work");
SendMessage(NOTE_DELETE_ERROR);
return;
}
SendMessage(NOTE_DELETED);
}
示例7: DeleteFilesByDirectory
/// <summary>
/// 删除方法 这里只会删除某个文件夹下的文件,如果传入的directory是个文件,将不做处理 * *
/// </summary>
/// <param name="directory">Directory.</param>
private static void DeleteFilesByDirectory(File directory)
{
if (directory != null && directory.IsDirectory) {
string[] childs = directory.List ();
for (int i = 0; i < childs.Length; i++) {
DeleteFilesByDirectory(new File(directory,childs[i]));
}
} else
directory.Delete ();
}
示例8: DeleteFolderFile
/// <summary>
/// 删除指定目录下文件及目录
/// </summary>
/// <param name="filePath">File path.</param>
/// <param name="deleteThisPath">If set to <c>true</c> delete this path.</param>
public static void DeleteFolderFile(string filePath,bool deleteThisPath)
{
try{
if (!TextUtils.IsEmpty (filePath)) {
var file = new File (filePath);
if (file.IsDirectory) {
File[] files = file.ListFiles ();
for (int i = 0; i < files.Length; i++) {
DeleteFolderFile (files [i].AbsolutePath, true);
}
}
if (deleteThisPath) {
if (file.IsFile)
file.Delete ();
else if (file.IsDirectory)
if (file.ListFiles ().Length == 0)
file.Delete ();
}
}
}
catch(Exception ex) {
Log.Error (Tag, ex.Message);
}
}