
Console.WriteLine("当前程序目录:"+fileDir)
//一个文件目录
string filePath = "C:\\bin\\files\\test.xml"
Console.WriteLine("该文件的目录:"+filePath) string str = "获取文件的全路径:" + Path.GetFullPath(filePath) //-->C:\bin\files\test.xmlConsole.WriteLine(str)
str = "获取文件所在的目录:" + Path.GetDirectoryName(filePath)//-->C:\碧余bin\filesConsole.WriteLine(str)
str = "获取文件的名称含有后缀:" + Path.GetFileName(filePath) //-->test.xmlConsole.WriteLine(str)
str = "获取文件的顷乱名称没有后缀:" + Path.GetFileNameWithoutExtension(filePath)//-->testConsole.WriteLine(str)
str = "获取路径的后缀扩展雀慧档名称:" + Path.GetExtension(filePath)//-->.xmlConsole.WriteLine(str)
str = "获取路径的根目录:" + Path.GetPathRoot(filePath)//-->C:\Console.WriteLine(str)
Console.ReadKey()
需求不太明确,开发隐皮期间与发布后的目录有可能是不一样的。
如图所示的解决方案,假如folderclass的路径可以用如下代码获取
string debug = System.AppDomain.CurrentDomain.BaseDirectory灶塌差 string proj = System.IO.Path.Combine(debug, @"..\..\")
foreach (string folder in System.IO.Directory.GetDirectories(proj))
MessageBox.Show(folder)//其中就可以遍历到你要的文件夹
如果你想绑定文件夹内的资源,其设置衫逗其属性为资源,并根据如下链接写xaml
http://msdn.microsoft.com/zh-cn/library/aa970069(v=vs.110).aspx
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)