consider 2 given file paths strings:
/path/to/dir
, /path/to/dir/file
in java, how can 1 test, if later file path represent real file on disk, below or equal directory represented first string. here more examples clarify point, including sample return values of checking function questioned here:
/path/to/dir /path/to/dir (true) /path/to/dir /path/to/dir/file (true) /path/to/dir /path (false) /path/to/dir /path/to/dir/../../file (false) /path/to/dir file (false) /path/to/dir /path/to/dir/dir2/../ (true)
would 1 rid of dots file
method .getcanonicalpath
, check on string level? maybe there better way. not find out, file
's .compareto
exactly.
please use native path operations. string operations may introduce errors due incorrect handling of path separators, etc.
path path1 = paths.get("/home").normalize(); path path2 = paths.get("/home/user/filename").normalize(); path2.startswith(path1);
Comments
Post a Comment