file - About resolve method of the java.nio.Path -
i thoroughly understand use of resolve(path) , relativize(path). in following snippet though there not clear me:
public filevisitresult previsitdirectory(path dir, basicfileattributes attr) throws ioexception { destinationfolder = destinationfolder.resolve(source.relativize(dir)); files.copy(dir, destinationfolder,standardcopyoption.replace_existing); return filevisitresult.continue; }
this snippet has been taken here (previsitdirectory method). have modified changing name of target
destinationfolder
.
if destinationfolder /home/user/desktop/destination
, source , dir (at least first recursive call) /home/user/desktop/tobecopied
.
the result of destinationfolder /home/user/desktop/destination
. works fine , supercool cannot see why gives outcome since source.relativize(dir)
; returns ../tobecopied
, destinationfolder.resolve(../tobecopied)
should return (without normalizing it) /home/user/desktop/destination/../tobecopied
hence /home/user/desktop/tobecopied
. if case program not work, /tobecopied
self copy (if makes sense). happens in somehow system takes relative pattern used in source.relativize(dir)
../tobecopied
, read "go 1 step , comeback" not "go 1 step , /tobecopied
". why happen though? logically should give /home/user/desktop/destination/../tobecopied
instead returns /home/user/desktop/destination
. missing? lot in advance!
ps: dir
current directory of recursive method previsitdirectory
, first call same source itself.
Comments
Post a Comment