C# 如何结合两条路径
我有下面的代码,我得到这样的结果C# 如何结合两条路径,c#,.net,C#,.net,我有下面的代码,我得到这样的结果 C:\\Users\\Administrator\\Projects\\CA\\Libraries\\ConvertApi-DotNet\\Example\\word2pdf-console\\bin\\Release\\\\..\\..\\..\\..\\test-files\\test.docx 该文件已找到,但我想向用户显示此路径,并且格式设置对用户不友好。我想去 C:\\Users\\Administrator\\Projects\\CA\\Libra
C:\\Users\\Administrator\\Projects\\CA\\Libraries\\ConvertApi-DotNet\\Example\\word2pdf-console\\bin\\Release\\\\..\\..\\..\\..\\test-files\\test.docx
该文件已找到,但我想向用户显示此路径,并且格式设置对用户不友好。我想去
C:\\Users\\Administrator\\Projects\\CA\\Libraries\\test-files\\test.docx
我已尝试使用Path.Combine,但它不起作用
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string inFile = baseDirectory + @"\..\..\..\..\test-files\test.docx";
描述
你说文件找到了
然后,您可以使用FileInfo namespace System.IO进行此操作
样品
更多信息
描述
你说文件找到了
然后,您可以使用FileInfo namespace System.IO进行此操作
样品
更多信息
您可以使用Path.Combine和:
您可以使用Path.Combine和:
当我使用Path.Combine时,我得到这样的结果C:\\test files\\test.docxUps,对不起,一切正常。我已经从文件路径中删除了\就像在您的演示中一样。当我使用path.Combine时,我得到这样的结果C:\\test files\\test.docxUps,对不起,一切正常。我已从文件路径中删除\就像在您的演示中一样。
FileInfo f = new FileInfo(fileName);
f.Exists // Gets a value indicating whether a file exists.
f.DirectoryName // Gets a string representing the directory's full path.
f.FullName // Gets the full path of the directory or file.
var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
var file = @"..\..\..\..\test-files\test.docx";
string inFile = Path.GetFullPath(Path.Combine(baseDirectory, file));