Is there any way to get valid/existing parent from provided path without looping.
My requirement is to create folder at provided path and i want to add validation that that folder have write permission.
So I added below code. but issue is some time path of getParent is not exists
Files.isWritable(Paths.get(path).getParent())
Example
"C:\MyFolder\Test" is existing folder.
Case1:
path=C:\MyFolder\Test\a
Paths.get(path).getParent() will be C:\MyFolder\Test
Files.isWritable will be true/false based on permission of "C:\MyFolder\Test".
Case2:
path=C:\MyFolder\Test\a\b\c
Paths.get(path).getParent() will be C:\MyFolder\Test\a\b
Files.isWritable will be always false.
I can add loop like getParent() till exists and then verify Files.isWritable(). Is there any better solution to get valid/existing path.