當前位置: 首頁>>代碼示例>>C#>>正文


C# FilePath.RenameTo方法代碼示例

本文整理匯總了C#中Sharpen.FilePath.RenameTo方法的典型用法代碼示例。如果您正苦於以下問題:C# FilePath.RenameTo方法的具體用法?C# FilePath.RenameTo怎麽用?C# FilePath.RenameTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Sharpen.FilePath的用法示例。


在下文中一共展示了FilePath.RenameTo方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: FileFor

		/// <exception cref="System.IO.IOException"></exception>
		internal override FileObjectDatabase.InsertLooseObjectResult InsertUnpackedObject
			(FilePath tmp, ObjectId id, bool createDuplicate)
		{
			// If the object is already in the repository, remove temporary file.
			//
			if (unpackedObjectCache.IsUnpacked(id))
			{
				FileUtils.Delete(tmp);
				return FileObjectDatabase.InsertLooseObjectResult.EXISTS_LOOSE;
			}
			if (!createDuplicate && Has(id))
			{
				FileUtils.Delete(tmp);
				return FileObjectDatabase.InsertLooseObjectResult.EXISTS_PACKED;
			}
			FilePath dst = FileFor(id);
			if (dst.Exists())
			{
				// We want to be extra careful and avoid replacing an object
				// that already exists. We can't be sure renameTo() would
				// fail on all platforms if dst exists, so we check first.
				//
				FileUtils.Delete(tmp);
				return FileObjectDatabase.InsertLooseObjectResult.EXISTS_LOOSE;
			}
			if (tmp.RenameTo(dst))
			{
				dst.SetReadOnly();
				unpackedObjectCache.Add(id);
				return FileObjectDatabase.InsertLooseObjectResult.INSERTED;
			}
			// Maybe the directory doesn't exist yet as the object
			// directories are always lazily created. Note that we
			// try the rename first as the directory likely does exist.
			//
			FileUtils.Mkdir(dst.GetParentFile());
			if (tmp.RenameTo(dst))
			{
				dst.SetReadOnly();
				unpackedObjectCache.Add(id);
				return FileObjectDatabase.InsertLooseObjectResult.INSERTED;
			}
			if (!createDuplicate && Has(id))
			{
				FileUtils.Delete(tmp);
				return FileObjectDatabase.InsertLooseObjectResult.EXISTS_PACKED;
			}
			// The object failed to be renamed into its proper
			// location and it doesn't exist in the repository
			// either. We really don't know what went wrong, so
			// fail.
			//
			FileUtils.Delete(tmp);
			return FileObjectDatabase.InsertLooseObjectResult.FAILURE;
		}
開發者ID:yayanyang,項目名稱:monodevelop,代碼行數:56,代碼來源:ObjectDirectory.cs

示例2: Rename

 private static bool Rename(FilePath src, FilePath dst)
 {
     if (src.RenameTo(dst))
     {
         return true;
     }
     FilePath dir = dst.GetParentFile();
     if ((dir.Exists() || !dir.Mkdirs()) && !dir.IsDirectory())
     {
         return false;
     }
     return src.RenameTo(dst);
 }
開發者ID:sharwell,項目名稱:ngit,代碼行數:13,代碼來源:RefDirectoryRename.cs


注:本文中的Sharpen.FilePath.RenameTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。