System.Diagnostics.Process.Start("explorer.exe", path) 不完善之处

本文介绍了一种使用 C# 在 Windows 系统下打开文件夹路径的方法,并针对相对路径进行了改进,确保了路径的正确解析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

string path = @"C:\Program Files\IIS\..\Lenovo"; 
if(Directory.Exists(path))
{
   System.Diagnostics.Process.Start("explorer.exe", path); 
}

这个方法有些不完善,只能打开绝对路径,不能打开的Path中 具有../../../这样的符号这样的相对路径,在Directory.Exists中是可以判断相对路径的,但是在System.Diagnostics.Process.Start("explorer.exe", path); 打开时,却无法识别相对路径,所以需要改成


string path = @"C:\Program Files\IIS\..\Lenovo"; 
path = Path.GetFullPath(path);
if(Directory.Exists(path))
{
   System.Diagnostics.Process.Start("explorer.exe", path); 
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值