从路径获取文件夹名称(S) [英] Getting Folder Name(s) from Path

查看:128
本文介绍了从路径获取文件夹名称(S)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个文件路径,如C:\我的文档\图片\ Image1.png,我怎么能得到Image1.png文件的父文件夹的名字吗?在这种情况下,图像,但是这只是一个样本。我已经通过 System.IO.Path 望去,似乎没有被任何东西在那里。也许我俯瞰它,但我不知道哪里会。

If I have a file path like "C:\My Documents\Images\Image1.png", how can I get the parent folder name of the "Image1.png" file? In this case, "Images", but that's just a sample. I've looked through System.IO.Path and there doesn't seem to be anything there. Maybe I'm overlooking it, but I have no idea where it would be.

推荐答案

这样的:

Path.GetFileName(Path.GetDirectoryName(something))

这篇关于从路径获取文件夹名称(S)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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