Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get the parent of a directory? #8

Open
glacjay opened this issue Aug 19, 2015 · 2 comments
Open

How can I get the parent of a directory? #8

glacjay opened this issue Aug 19, 2015 · 2 comments

Comments

@glacjay
Copy link
Contributor

glacjay commented Aug 19, 2015

I've not found the API.

@fgenesis
Copy link
Owner

You can't. This is by design -- since you can mount subtrees whereever you want, there would also be multiple parents to choose from in such cases. To avoid the complication and confusion, directory traversal only works forward, not backwards.
For the same reason, ".." in a path name will usually not do what you want. ".." works only if you specify a raw directory on disk, e.g. when mounting "../../" to something else.

Note: PhysicsFS does also not support ".." by design.

@fgenesis
Copy link
Owner

Consider something like this instead:

#include "VFSUtil.h"

ttvfs::Root root;
// ...
ttvfs::VFSDir *d = root.GetDir("path/to/thing");
std::string s= d->name();
ttvfs::StripLastPath(s);
ttvfs::VFSDir *parent = root.GetDir(s);

While you can't go backwards, you can always get the internal (or complete, which would be fullname()) path name in the tree, chop off the last part, and retrieve that directory (which is effectively the parent).
Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants