Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试获取路径中的所有目录。例如,从a/b/c/d.e我想得到a、a/b和a/b/c。我可以通过dirname多次调用posix之类的函数来实现这一点。问题在于像a/b/c/. 我想得到a,a/b和a/b/c. 既然有/以下c,c应该是我想列出的目录。但是函数像dirnamereturna/b而不是a/b/c当a/b/c/作为输入给出时。
a/b/c/d.e
a
a/b
a/b/c
dirname
a/b/c/
/
c
我可以直接拆分/以获取目录列表,还是存在无法正常工作的边缘情况?
我知道的唯一特殊情况是
a.e
\
/tmp//something
如果您的功能支持上述所有情况,我认为没问题。