I'm trying to figure out a way to compare two absolute(ish!) file locations and return the relative path from one to another in the shortest way possible.
/*
Example 1:
..\root\folder\subFolder\myCurrent.file
..\root\folder\subFolder\img\myTarget.image
Expected result:
.\img\myTarget.image
Example 2:
..\root\folder\subFolder\myCurrent.file
..\root\folder\otherSubFolder\img\myTarget.image
Expected result:
..\otherSubFolder\img\myTarget.image
Example 3:
..\root\folder\subFolder\myCurrent.file
..\root\folder\subFolder\myTarget.image
Expected result:
myTarget.image
*/
I tried to split the paths to arrays and compare length and values, but it turned out to be a complete mess and I didn't even manage to do it yet...
const currentFilePath = activepath.split('\\')
const currentDir = currentFilePath[currentFilePath.indexOf(currentFilePath[currentFilePath.length - 2])];
const targetFilePath = file.path.split('\\');
const targetDir = targetFilePath[targetFilePath.indexOf(targetFilePath[targetFilePath.length - 2])];
const currentFileDepth = currentFilePath.length;
// and so on...
I would like a decent, clean way to figure this out...