file - Java - shorten the path of a directory -
i shorten path of directory.
i know directory path must start, example (the path starts 1):
instead of c:\temp\top\1\file.txt, want 1\file.txt.
note: careful \ , /....
you can traverse path file root, check if dir dir want:
file basedir = new file(basepath); file candidate = new file(fullpath); string subpath = candidate.getname(); candidate = candidate.getparent(); while (candidate != null && !candidate.equals(basedir)) { candidate = candidate.getparent(); subpath = candidate.getname() + file.separatorchar + subpath; } // if candidate == null file on directory, have use path // if candidate != null, subpath has want
Comments
Post a Comment