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


C# File.Delete方法代码示例

本文整理汇总了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);
        }
开发者ID:pythe,项目名称:wristpass,代码行数:35,代码来源:TestCreateDb.cs

示例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();
     }
 }
开发者ID:decriptor,项目名称:tomdroid,代码行数:12,代码来源:Send.cs

示例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());
            }
        }
开发者ID:pgrzmil,项目名称:XamarinResearch,代码行数:19,代码来源:FileAccessTestService.cs

示例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();
        }
开发者ID:pythe,项目名称:wristpass,代码行数:21,代码来源:IoUtil.cs

示例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;
    }
开发者ID:hannuraina,项目名称:tag,代码行数:23,代码来源:AudioConverter.cs

示例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);
 }
开发者ID:decriptor,项目名称:tomdroid,代码行数:13,代码来源:SdCardSyncService.cs

示例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 ();
		}
开发者ID:lq-ever,项目名称:EldYoungAndroidApp,代码行数:14,代码来源:DeleteCleanCacheManager.cs

示例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);
			}

		}
开发者ID:lq-ever,项目名称:EldYoungAndroidApp,代码行数:30,代码来源:DeleteCleanCacheManager.cs


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