Navigating Folders… going "up"

May 27, 2008 at 2:47am

Navigating Folders… going "up"

I am making a file browser, and jsfolderiter.js has shown me everything I need except the ability to go “up” a folder. Is there a simple property such as foldername.backpath to do this?

For example, if I am in

I would like to get

I looked into string manipulation as a workaround, but this brings in problems with being cross-platform because of the differences between Windows and OSX paths.

I hope this is not a silly question, I could not find a reference with the properties of Folder().

May 30, 2008 at 10:38am

Looking at the code for jsfolderiter.js, it looks as though it always uses’/’ as its own path separator. Do you really need to worry about cross-platform path handling? Unless Im missing something, shouldnt the following suffice??

var folderString = new String(fodlerName);
lastSep = folderString.lastIndexOf(‘/’,folderString.length-2);
folderString = folderString.slice(0,lastSep);

Alternately, would your application suffice with just



May 30, 2008 at 4:22pm

I was doing something similar to your code, but less efficient. The .lastIndexOf really speeds things up. My final code (for Windows) is:

function back_folder()
//protect from going “up” at a drive
last_sep = prev_folder.lastIndexOf(“/”, prev_folder.length-2);
var jump_to = prev_folder.slice(0, last_sep) + “/”;

Where jump_folder is my folder loading function, and prev_folder is the last folder that’s been loaded.
It’s working fine on Windows and is faster than what I had before. Thank you!


You must be logged in to reply to this topic.