BeeOnRope BeeOnRope - 1 year ago 82
Java Question

Resolve a path name with .. parent directory specifiers ("dot dot") without resolving symlinks

Given a path like

, I would like to remove all the "current directory" indicators (i.e., period) and "parent directory" indicators (i.e., ..), giving

I could use
, but that also resolves symlinks, which I don't want.

Any simple way? That is, simpler than writing a tokenizer and handling it all myself.

Bonus points if you can tell me what the right name for '.' and '..' are in this context.

Answer Source

You can use FilenameUtils.normalize() in the Apache Commons IO library - see javadoc here.

"Dot" (.) is the current directory and "dot dot" (..) is the parent directory - read up on unix directories.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download