Is that correct? On a file 'a/b/c/f.txt' wont this path.split..[0] construct return only 'a' (instead of 'a/b/c' what I expect is what you want). Maybe its better to work with lastIndexOf('/') and substring().
lastSlash = path.lastIndexOf('/');
if (lastSlash>-1) pathKey = path.substring(0, lastSlash);