本文整理汇总了C#中System.IO.Path.GetFullPath方法的典型用法代码示例。如果您正苦于以下问题:C# Path.GetFullPath方法的具体用法?C# Path.GetFullPath怎么用?C# Path.GetFullPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Path
的用法示例。
在下文中一共展示了Path.GetFullPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1:
string fileName = "myfile.ext";
string path1 = @"mydir";
string path2 = @"\mydir";
string fullPath;
fullPath = Path.GetFullPath(path1);
Console.WriteLine("GetFullPath('{0}') returns '{1}'",
path1, fullPath);
fullPath = Path.GetFullPath(fileName);
Console.WriteLine("GetFullPath('{0}') returns '{1}'",
fileName, fullPath);
fullPath = Path.GetFullPath(path2);
Console.WriteLine("GetFullPath('{0}') returns '{1}'",
path2, fullPath);
// Output is based on your current directory, except
// in the last case, where it is based on the root drive
// GetFullPath('mydir') returns 'C:\temp\Demo\mydir'
// GetFullPath('myfile.ext') returns 'C:\temp\Demo\myfile.ext'
// GetFullPath('\mydir') returns 'C:\mydir'
示例2: Main
//引入命名空间
using System;
using System.IO;
class Program
{
static void Main()
{
string basePath = Environment.CurrentDirectory;
string relativePath = "./data/output.xml";
// Unexpectedly change the current directory.
Environment.CurrentDirectory = "C:/Users/Public/Documents/";
string fullPath = Path.GetFullPath(relativePath, basePath);
Console.WriteLine($"Current directory:\n {Environment.CurrentDirectory}");
Console.WriteLine($"Fully qualified path:\n {fullPath}");
}
}
输出:
Current directory: C:\Users\Public\Documents Fully qualified path: C:\Utilities\data\output.xml
示例3: Path.GetFullPath(String fileName)
//引入命名空间
using System;
using System.IO;
class MainClass {
static void Main() {
Console.WriteLine("Using: " + Directory.GetCurrentDirectory());
Console.WriteLine("The relative path 'file.txt' " + "will automatically become: '" + Path.GetFullPath("file.txt") + "'");
}
}