Create Subdirectory

From PlainOldWebserver

Jump to: navigation, search

To create a subdirectory (/pow/htdocs/dr/application/) create an array represents the entire path and all its subdirectories and then iterate on this array:


<?sjs
    var myPath= new Array('pow', 'htdocs', 'dr', 'application');
    var file = Components.classes["@mozilla.org/file/directory_service;1"]
                    .getService(Components.interfaces.nsIProperties)
                    .get("ProfD", Components.interfaces.nsIFile);

    for (var i=0; i<myPath.length; i++) {
        file.append(myPath[i]);
        if( !file.exists() || !file.isDirectory() )
            file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE , 0664);
    }
?>

Any sub directory from the array that doesn't exist will be created with this code.

Personal tools
Navigation