我有一个方法正在执行文件复制。 “root”由用户在命令行中指定,我使用 Path.GetFullPath(input)
对其进行了清理。
我需要获取文件相对于该根目录的路径,因此将返回以下情况:
Root FilePath Return
y:\ y:\temp\filename1.txt temp\filename1.txt
y:\dir1 y:\dir1\dir2\filename2.txt dir2\filename2.txt
最佳答案
你可以写
var relative = new Uri(rootPath).MakeRelativeUri(new Uri(filePath));
http://msdn.microsoft.com/en-us/library/system.uri.makerelativeuri.aspx
关于c# - 如何获取特定目录的相对文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5656210/