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
C:StuffJunk
I would like to get
C:Stuff
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().
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
C:StuffJunk..
?
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
if(prev_folder.charAt(prev_folder.length-2)!=":")
{
last_sep = prev_folder.lastIndexOf("/", prev_folder.length-2);
var jump_to = prev_folder.slice(0, last_sep) + "/";
jump_folder(jump_to);
}
}
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!