找出文件所在的目录名称 [英] Finding out Directory name in which a file lies

查看:184
本文介绍了找出文件所在的目录名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我对正则表达式来说很陌生,并且正在和他们一起玩耍。


所以在我的例子中我想弄清楚文件所在目录的名称请参阅以下示例路径:



C:\ MyContent\business\SomeStuff\test.doc



使用以下正则表达式I在这个例子中,成功可以提取当前目录的名称,SomeStuff。



\w +(?= \\ [\ w] + \。[az] {2,3})



我一见到为行结束设置一个锚点,就像那样



\w +(?= \\ [\ w] + \。[az] {2,3})$



不再匹配了。我对此感到疑惑,因为我认为行以文件扩展名结尾.doc


是否有人对该问题有解释?



亲切的问候



解决方案

使用Path.GetDirectoryName()


Hello there,

 

I am quite new to regex and am freaking a litte arround with them.

So in my example I would like to figure out the name of directory in which the file lies in.

Given the following example path:

 

C:\MyContent\business\SomeStuff\test.doc 

 

Using the following regex I successfully can extract the name of the current directory, SomeStuff in this example.

 

\w+(?=\\[\w]+\.[a-z]{2,3})

 

As soon as I set an anchor for line ending, like that

 

\w+(?=\\[\w]+\.[a-z]{2,3})$

 

there is no match any more. I wonder about that because I think line ends with the file extention .doc

Does anybody has an explanation for that issue?

 

Kind Regards

 

 

解决方案

Use Path.GetDirectoryName()

 


这篇关于找出文件所在的目录名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆