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


C# FilePath.Delete方法代码示例

本文整理汇总了C#中Sharpen.FilePath.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# FilePath.Delete方法的具体用法?C# FilePath.Delete怎么用?C# FilePath.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sharpen.FilePath的用法示例。


在下文中一共展示了FilePath.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteRecursive

		public static bool DeleteRecursive(FilePath fileOrDirectory)
		{
			if (fileOrDirectory.IsDirectory())
			{
				foreach (FilePath child in fileOrDirectory.ListFiles())
				{
					DeleteRecursive(child);
				}
			}
			bool result = fileOrDirectory.Delete() || !fileOrDirectory.Exists();
			return result;
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:12,代码来源:FileDirUtils.cs

示例2: TestUpgradeOldDatabaseFiles

		/// <exception cref="System.Exception"></exception>
		public virtual void TestUpgradeOldDatabaseFiles()
		{
			string directoryName = "test-directory-" + Runtime.CurrentTimeMillis();
			string normalFilesDir = GetRootDirectory().GetAbsolutePath();
			string fakeFilesDir = string.Format("%s/%s", normalFilesDir, directoryName);
			FilePath directory = new FilePath(fakeFilesDir);
			if (!directory.Exists())
			{
				bool result = directory.Mkdir();
				if (!result)
				{
					throw new IOException("Unable to create directory " + directory);
				}
			}
			FilePath oldTouchDbFile = new FilePath(directory, string.Format("old%s", Manager.
				DatabaseSuffixOld));
			oldTouchDbFile.CreateNewFile();
			FilePath newCbLiteFile = new FilePath(directory, string.Format("new%s", Manager.DatabaseSuffix
				));
			newCbLiteFile.CreateNewFile();
			FilePath migratedOldFile = new FilePath(directory, string.Format("old%s", Manager
				.DatabaseSuffix));
			migratedOldFile.CreateNewFile();
			base.StopCBLite();
			manager = new Manager(new FilePath(GetRootDirectory(), directoryName), Manager.DefaultOptions
				);
			NUnit.Framework.Assert.IsTrue(migratedOldFile.Exists());
			//cannot rename old.touchdb in old.cblite, old.cblite already exists
			NUnit.Framework.Assert.IsTrue(oldTouchDbFile.Exists());
			NUnit.Framework.Assert.IsTrue(newCbLiteFile.Exists());
			FilePath dir = new FilePath(GetRootDirectory(), directoryName);
			NUnit.Framework.Assert.AreEqual(3, dir.ListFiles().Length);
			base.StopCBLite();
			migratedOldFile.Delete();
			manager = new Manager(new FilePath(GetRootDirectory(), directoryName), Manager.DefaultOptions
				);
			//rename old.touchdb in old.cblite, previous old.cblite already doesn't exist
			NUnit.Framework.Assert.IsTrue(migratedOldFile.Exists());
			NUnit.Framework.Assert.IsTrue(oldTouchDbFile.Exists() == false);
			NUnit.Framework.Assert.IsTrue(newCbLiteFile.Exists());
			dir = new FilePath(GetRootDirectory(), directoryName);
			NUnit.Framework.Assert.AreEqual(2, dir.ListFiles().Length);
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:44,代码来源:ManagerTest.cs

示例3: DeleteLooseRef

 private void DeleteLooseRef(string name)
 {
     FilePath path = new FilePath(diskRepo.Directory, name);
     NUnit.Framework.Assert.IsTrue(path.Delete(), "deleted " + name);
 }
开发者ID:JamesChan,项目名称:ngit,代码行数:5,代码来源:RefDirectoryTest.cs

示例4: RemoveItemIfExists

		public static bool RemoveItemIfExists(string path)
		{
			FilePath f = new FilePath(path);
			return f.Delete() || !f.Exists();
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:5,代码来源:FileDirUtils.cs

示例5: Checkout

		/// <summary>Execute this checkout</summary>
		/// <returns>
		/// <code>false</code> if this method could not delete all the files
		/// which should be deleted (e.g. because of of the files was
		/// locked). In this case
		/// <see cref="GetToBeDeleted()">GetToBeDeleted()</see>
		/// lists the files
		/// which should be tried to be deleted outside of this method.
		/// Although <code>false</code> is returned the checkout was
		/// successful and the working tree was updated for all other files.
		/// <code>true</code> is returned when no such problem occurred
		/// </returns>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public virtual bool Checkout()
		{
			toBeDeleted.Clear();
			if (headCommitTree != null)
			{
				PreScanTwoTrees();
			}
			else
			{
				PrescanOneTree();
			}
			if (!conflicts.IsEmpty())
			{
				if (failOnConflict)
				{
					dc.Unlock();
					throw new CheckoutConflictException(Sharpen.Collections.ToArray(conflicts, new string
						[conflicts.Count]));
				}
				else
				{
					CleanUpConflicts();
				}
			}
			// update our index
			builder.Finish();
			FilePath file = null;
			string last = string.Empty;
			// when deleting files process them in the opposite order as they have
			// been reported. This ensures the files are deleted before we delete
			// their parent folders
			for (int i = removed.Count - 1; i >= 0; i--)
			{
				string r = removed[i];
				file = new FilePath(repo.WorkTree, r);
				if (!file.Delete() && file.Exists())
				{
					toBeDeleted.AddItem(r);
				}
				else
				{
					if (!IsSamePrefix(r, last))
					{
						RemoveEmptyParents(file);
					}
					last = r;
				}
			}
			if (file != null)
			{
				RemoveEmptyParents(file);
			}
			foreach (string path in updated.Keys)
			{
				// ... create/overwrite this file ...
				file = new FilePath(repo.WorkTree, path);
				file.GetParentFile().Mkdirs();
				file.CreateNewFile();
				DirCacheEntry entry = dc.GetEntry(path);
				CheckoutEntry(repo, file, entry);
			}
			// commit the index builder - a new index is persisted
			if (!builder.Commit())
			{
				dc.Unlock();
				throw new IndexWriteException();
			}
			return toBeDeleted.Count == 0;
		}
开发者ID:nickname100,项目名称:monodevelop,代码行数:82,代码来源:DirCacheCheckout.cs

示例6: CleanUpConflicts

		/// <exception cref="NGit.Errors.CheckoutConflictException"></exception>
		private void CleanUpConflicts()
		{
			foreach (string c in conflicts)
			{
				FilePath conflict = new FilePath(root, c);
				if (!conflict.Delete())
				{
					throw new NGit.Errors.CheckoutConflictException(MessageFormat.Format(JGitText.Get
						().cannotDeleteFile, c));
				}
				RemoveEmptyParents(conflict);
			}
			foreach (string r in removed)
			{
				FilePath file = new FilePath(root, r);
				file.Delete();
				RemoveEmptyParents(file);
			}
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:20,代码来源:WorkDirCheckout.cs

示例7: TestMkdirs

		public virtual void TestMkdirs()
		{
			FilePath root = new FilePath(trash, "test");
			NUnit.Framework.Assert.IsTrue(root.Mkdir());
			FilePath d = new FilePath(root, "test/test");
			FileUtils.Mkdirs(d);
			NUnit.Framework.Assert.IsTrue(d.Exists() && d.IsDirectory());
			try
			{
				FileUtils.Mkdirs(d);
				NUnit.Framework.Assert.Fail("creation of existing directory hierarchy must fail");
			}
			catch (IOException)
			{
			}
			// expected
			FileUtils.Mkdirs(d, true);
			NUnit.Framework.Assert.IsTrue(d.Exists() && d.IsDirectory());
			FileUtils.Delete(root, FileUtils.RECURSIVE);
			FilePath f = new FilePath(trash, "test");
			FileUtils.CreateNewFile(f);
			try
			{
				FileUtils.Mkdirs(d);
				NUnit.Framework.Assert.Fail("creation of directory having path conflicting with existing"
					 + " file must fail");
			}
			catch (IOException)
			{
			}
			// expected
			NUnit.Framework.Assert.IsTrue(f.Delete());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:33,代码来源:FileUtilTest.cs

示例8: Checkout

		/// <exception cref="NGit.Errors.NoWorkTreeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void Checkout()
		{
			foreach (KeyValuePair<string, DirCacheEntry> entry in toBeCheckedOut.EntrySet())
			{
				FilePath f = new FilePath(db.WorkTree, entry.Key);
				if (entry.Value != null)
				{
					CreateDir(f.GetParentFile());
					DirCacheCheckout.CheckoutEntry(db, f, entry.Value);
				}
				else
				{
					if (!f.Delete())
					{
						failingPaths.Put(entry.Key, ResolveMerger.MergeFailureReason.COULD_NOT_DELETE);
					}
				}
				modifiedFiles.AddItem(entry.Key);
			}
		}
开发者ID:stewartwhaley,项目名称:monodevelop,代码行数:22,代码来源:ResolveMerger.cs

示例9: DoCheckout

 /// <exception cref="NGit.Errors.CorruptObjectException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 /// <exception cref="NGit.Errors.MissingObjectException"></exception>
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 /// <exception cref="NGit.Errors.CheckoutConflictException"></exception>
 /// <exception cref="NGit.Errors.IndexWriteException"></exception>
 private bool DoCheckout()
 {
     toBeDeleted.Clear();
     ObjectReader objectReader = repo.ObjectDatabase.NewReader();
     try
     {
         if (headCommitTree != null)
         {
             PreScanTwoTrees();
         }
         else
         {
             PrescanOneTree();
         }
         if (!conflicts.IsEmpty())
         {
             if (failOnConflict)
             {
                 throw new NGit.Errors.CheckoutConflictException(Sharpen.Collections.ToArray(conflicts
                     , new string[conflicts.Count]));
             }
             else
             {
                 CleanUpConflicts();
             }
         }
         // update our index
         builder.Finish();
         FilePath file = null;
         string last = string.Empty;
         // when deleting files process them in the opposite order as they have
         // been reported. This ensures the files are deleted before we delete
         // their parent folders
         for (int i = removed.Count - 1; i >= 0; i--)
         {
             string r = removed[i];
             file = new FilePath(repo.WorkTree, r);
             if (!file.Delete() && file.Exists())
             {
                 // The list of stuff to delete comes from the index
                 // which will only contain a directory if it is
                 // a submodule, in which case we shall not attempt
                 // to delete it. A submodule is not empty, so it
                 // is safe to check this after a failed delete.
                 if (!file.IsDirectory())
                 {
                     toBeDeleted.AddItem(r);
                 }
             }
             else
             {
                 if (!IsSamePrefix(r, last))
                 {
                     RemoveEmptyParents(new FilePath(repo.WorkTree, last));
                 }
                 last = r;
             }
         }
         if (file != null)
         {
             RemoveEmptyParents(file);
         }
         foreach (string path in updated.Keys)
         {
             // ... create/overwrite this file ...
             file = new FilePath(repo.WorkTree, path);
             if (!file.GetParentFile().Mkdirs())
             {
             }
             // ignore
             DirCacheEntry entry = dc.GetEntry(path);
             // submodules are handled with separate operations
             if (FileMode.GITLINK.Equals(entry.RawMode))
             {
                 continue;
             }
             CheckoutEntry(repo, file, entry, objectReader);
         }
         // commit the index builder - a new index is persisted
         if (!builder.Commit())
         {
             throw new IndexWriteException();
         }
     }
     finally
     {
         objectReader.Release();
     }
     return toBeDeleted.Count == 0;
 }
开发者ID:stinos,项目名称:ngit,代码行数:96,代码来源:DirCacheCheckout.cs

示例10: TestMkdir

		public virtual void TestMkdir()
		{
			FilePath d = new FilePath(trash, "test");
			FileUtils.Mkdir(d);
			NUnit.Framework.Assert.IsTrue(d.Exists() && d.IsDirectory());
			try
			{
				FileUtils.Mkdir(d);
				NUnit.Framework.Assert.Fail("creation of existing directory must fail");
			}
			catch (IOException)
			{
			}
			// expected
			FileUtils.Mkdir(d, true);
			NUnit.Framework.Assert.IsTrue(d.Exists() && d.IsDirectory());
			NUnit.Framework.Assert.IsTrue(d.Delete());
			FilePath f = new FilePath(trash, "test");
			FileUtils.CreateNewFile(f);
			try
			{
				FileUtils.Mkdir(d);
				NUnit.Framework.Assert.Fail("creation of directory having same path as existing file must"
					 + " fail");
			}
			catch (IOException)
			{
			}
			// expected
			NUnit.Framework.Assert.IsTrue(f.Delete());
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:31,代码来源:FileUtilTest.cs

示例11: CleanUpConflicts

 /// <summary>
 /// This method implements how to handle conflicts when
 /// <see cref="failOnConflict">failOnConflict</see>
 /// is false
 /// </summary>
 /// <exception cref="NGit.Errors.CheckoutConflictException">NGit.Errors.CheckoutConflictException
 /// 	</exception>
 private void CleanUpConflicts()
 {
     // TODO: couldn't we delete unsaved worktree content here?
     foreach (string c in conflicts)
     {
         FilePath conflict = new FilePath(repo.WorkTree, c);
         if (!conflict.Delete())
         {
             throw new NGit.Errors.CheckoutConflictException(MessageFormat.Format(JGitText.Get
                 ().cannotDeleteFile, c));
         }
         RemoveEmptyParents(conflict);
     }
     foreach (string r in removed)
     {
         FilePath file = new FilePath(repo.WorkTree, r);
         if (!file.Delete())
         {
             throw new NGit.Errors.CheckoutConflictException(MessageFormat.Format(JGitText.Get
                 ().cannotDeleteFile, file.GetAbsolutePath()));
         }
         RemoveEmptyParents(file);
     }
 }
开发者ID:stinos,项目名称:ngit,代码行数:31,代码来源:DirCacheCheckout.cs

示例12: Get

		/// <exception cref="NSch.SftpException"></exception>
		public virtual void Get(string src, string dst, SftpProgressMonitor monitor, int 
			mode)
		{
			// System.out.println("get: "+src+" "+dst);
			bool _dstExist = false;
			string _dst = null;
			try
			{
				((Channel.MyPipedInputStream)io_in).UpdateReadSide();
				src = RemoteAbsolutePath(src);
				dst = LocalAbsolutePath(dst);
				ArrayList v = Glob_remote(src);
				int vsize = v.Count;
				if (vsize == 0)
				{
					throw new SftpException(SSH_FX_NO_SUCH_FILE, "No such file");
				}
				FilePath dstFile = new FilePath(dst);
				bool isDstDir = dstFile.IsDirectory();
				StringBuilder dstsb = null;
				if (isDstDir)
				{
					if (!dst.EndsWith(file_separator))
					{
						dst += file_separator;
					}
					dstsb = new StringBuilder(dst);
				}
				else
				{
					if (vsize > 1)
					{
						throw new SftpException(SSH_FX_FAILURE, "Copying multiple files, but destination is missing or a file."
							);
					}
				}
				for (int j = 0; j < vsize; j++)
				{
					string _src = (string)(v[j]);
					SftpATTRS attr = _stat(_src);
					if (attr.IsDir())
					{
						throw new SftpException(SSH_FX_FAILURE, "not supported to get directory " + _src);
					}
					_dst = null;
					if (isDstDir)
					{
						int i = _src.LastIndexOf('/');
						if (i == -1)
						{
							dstsb.Append(_src);
						}
						else
						{
							dstsb.Append(Sharpen.Runtime.Substring(_src, i + 1));
						}
						_dst = dstsb.ToString();
						dstsb.Delete(dst.Length, _dst.Length);
					}
					else
					{
						_dst = dst;
					}
					FilePath _dstFile = new FilePath(_dst);
					if (mode == RESUME)
					{
						long size_of_src = attr.GetSize();
						long size_of_dst = _dstFile.Length();
						if (size_of_dst > size_of_src)
						{
							throw new SftpException(SSH_FX_FAILURE, "failed to resume for " + _dst);
						}
						if (size_of_dst == size_of_src)
						{
							return;
						}
					}
					if (monitor != null)
					{
						monitor.Init(SftpProgressMonitor.GET, _src, _dst, attr.GetSize());
						if (mode == RESUME)
						{
							monitor.Count(_dstFile.Length());
						}
					}
					FileOutputStream fos = null;
					_dstExist = _dstFile.Exists();
					try
					{
						if (mode == OVERWRITE)
						{
							fos = new FileOutputStream(_dst);
						}
						else
						{
							fos = new FileOutputStream(_dst, true);
						}
						// append
						// System.err.println("_get: "+_src+", "+_dst);
//.........这里部分代码省略.........
开发者ID:LunarLanding,项目名称:ngit,代码行数:101,代码来源:ChannelSftp.cs

示例13: Delete

        /// <summary>
        /// Deletes the %Database%.
        /// </summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"/>
        public void Delete()
        {
            if (open)
            {
                if (!Close())
                {
                    throw new CouchbaseLiteException("The database was open, and could not be closed", 
                        StatusCode.InternalServerError);
                }
            }

            Manager.ForgetDatabase(this);
            if (!Exists())
            {
                return;
            }

            var file = new FilePath(Path);
            var attachmentsFile = new FilePath(AttachmentStorePath);

            var deleteStatus = file.Delete();
            if (!deleteStatus)
            {
                Log.V(Database.Tag, String.Format("Error deleting the SQLite database file at {0}", file.GetAbsolutePath()));
            }

            //recursively delete attachments path
            var deletedAttachmentsPath = true;
            try {
				var dirInfo = new DirectoryInfo(attachmentsFile.GetPath());
				dirInfo.Delete(true);
				//Directory.Delete (attachmentsFile.GetPath (), true);
            } catch (Exception ex) {
                Log.V(Database.Tag, "Error deleting the attachments directory.", ex);
                deletedAttachmentsPath = false;
            }

            if (!deleteStatus)
            {
                throw new CouchbaseLiteException("Was not able to delete the database file", StatusCode.InternalServerError);
            }

            if (!deletedAttachmentsPath)
            {
                throw new CouchbaseLiteException("Was not able to delete the attachments files", StatusCode.InternalServerError);
            }
        }
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:51,代码来源:Database.cs

示例14: Delete

        /// <summary>
        /// Deletes the <see cref="Couchbase.Lite.Database" />.
        /// </summary>
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException">
        /// Thrown if an issue occurs while deleting the <see cref="Couchbase.Lite.Database" /></exception>
        public void Delete()
        {
            if (_isOpen && !Close())
            {
                throw new CouchbaseLiteException("The database was open, and could not be closed", StatusCode.InternalServerError);
            }

            Manager.ForgetDatabase(this);
            if (!Exists())
            {
                return;
            }

            var file = new FilePath(Path);
            var fileJournal = new FilePath(AttachmentStorePath + "-journal");

            var deleteStatus = file.Delete();
            if (fileJournal.Exists())
            {
                deleteStatus &= fileJournal.Delete();
            }

            //recursively delete attachments path
            var attachmentsFile = new FilePath(AttachmentStorePath);
            var deleteAttachmentStatus = FileDirUtils.DeleteRecursive(attachmentsFile);

            //recursively delete path where attachments stored( see getAttachmentStorePath())
            var lastDotPosition = Path.LastIndexOf('.');
            if (lastDotPosition > 0)
            {
                var attachmentsFileUpFolder = new FilePath(Path.Substring(0, lastDotPosition));
                FileDirUtils.DeleteRecursive(attachmentsFileUpFolder);
            }

            if (!deleteStatus)
            {
                Log.V(Tag, String.Format("Error deleting the SQLite database file at {0}", file.GetAbsolutePath()));
            }

            if (!deleteStatus)
            {
                throw new CouchbaseLiteException("Was not able to delete the database file", StatusCode.InternalServerError);
            }

            if (!deleteAttachmentStatus)
            {
                throw new CouchbaseLiteException("Was not able to delete the attachments files", StatusCode.InternalServerError);
            }
        }
开发者ID:FireflyLogic,项目名称:couchbase-lite-net,代码行数:54,代码来源:Database.cs

示例15: Checkout

 /// <exception cref="NGit.Errors.NoWorkTreeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 private void Checkout()
 {
     ObjectReader r = db.ObjectDatabase.NewReader();
     try
     {
         foreach (KeyValuePair<string, DirCacheEntry> entry in toBeCheckedOut.EntrySet())
         {
             FilePath f = new FilePath(db.WorkTree, entry.Key);
             CreateDir(f.GetParentFile());
             DirCacheCheckout.CheckoutEntry(db, f, entry.Value, r);
             modifiedFiles.AddItem(entry.Key);
         }
         // Iterate in reverse so that "folder/file" is deleted before
         // "folder". Otherwise this could result in a failing path because
         // of a non-empty directory, for which delete() would fail.
         for (int i = toBeDeleted.Count - 1; i >= 0; i--)
         {
             string fileName = toBeDeleted[i];
             FilePath f = new FilePath(db.WorkTree, fileName);
             if (!f.Delete())
             {
                 failingPaths.Put(fileName, ResolveMerger.MergeFailureReason.COULD_NOT_DELETE);
             }
             modifiedFiles.AddItem(fileName);
         }
     }
     finally
     {
         r.Release();
     }
 }
开发者ID:stinos,项目名称:ngit,代码行数:33,代码来源:ResolveMerger.cs


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