admin管理员组文章数量:1313733
Assuming a POSIX path to a specific folder in the macOS filesystem:
/root/Owners/J.F. Kennedy
I would like to obtain J.F. Kennedy
.
I used takeFileName
function to solve this problem, but I feel there is a better tool for this job.
Is there any function in System.FilePath
or System.Directory
modules which can accomplish the task at hand ?
Assuming a POSIX path to a specific folder in the macOS filesystem:
/root/Owners/J.F. Kennedy
I would like to obtain J.F. Kennedy
.
I used takeFileName
function to solve this problem, but I feel there is a better tool for this job.
Is there any function in System.FilePath
or System.Directory
modules which can accomplish the task at hand ?
1 Answer
Reset to default 2As per the comments, it's reasonable to consider any path as consisting of a directory part (every component except the last) and a filename part (the last, possibly empty, component) that can be simultaneously retrieved with splitFileName
or individually retrieved with takeDirectory
or takeFileName
, and it doesn't matter if the path refers to a regular file or a directory.
Be warned that if you want to take the last non-empty component of the path, you should consider using:
takeFileName . dropTrailingPathSeparator
instead. This should properly handle all the weird cases of extra path separators:
"/a/b/c" -> "c"
"/a/b/c/" -> "c"
"//a///b//c////" -> "c"
and will only return an empty component if the entire path is empty (or only consists of path separators).
版权声明:本文标题:haskell - How can I extract the base name of a directory with at least one dot in its name? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741959044a2407161.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
takeFileName
, seems to be exactly the functionality you want. – cafce25 Commented Jan 30 at 14:42Get the file name
. I wouldn’t be using it for its intended purpose. – F. Zer Commented Jan 30 at 15:03last . splitPath
, perhaps. – F. Zer Commented Jan 30 at 16:12