当前位置: 首页>>代码示例>>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;未经允许,请勿转载。