C#将多个字符串组合成一个路径,可利用System.IO.Path类中的Combine(String,String)方法。
命名空间为:using System.IO;
示例:
string path1 = @"D:temp";string path2 = ";string newPath = Path.Combine(path1, path2); // newPath = "D:";//path.Combine方法拥有多个重载
如果需要返回地址的上一层目录
示例:
string path="c:admindemo";Directory.SetCurrentDirectory(Directory.GetParent(path).FullName);path = Directory.GetCurrentDirectory(); //path="c:admin";//返回几层则可以使用for循环
本文发布于:2024-01-29 16:55:00,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170651850316802.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |