XPages create a new Folder on button click

I have a file upload control that saves a file directly to the server instead of a Notes Document, However, the folder that the file saves in has to be created beforehand. Is there a way to create a new folder and save the file to that folder instead of a folder that already exists.

See Code below:


<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">

        <xp:script src="/scriptsTest.jss" clientSide="false"></xp:script>
    <xp:fileUpload id="fileUpload1"></xp:fileUpload>
    <xp:button value="Label" id="button1">
        <xp:eventHandler event="onclick" submit="true"
    <xp:text escape="true" id="message"></xp:text></xp:view>


function saveTest()
    var con = facesContext.getExternalContext(); 
    var request:com.sun.faces.context.MyHttpServletRequestWrapper = con.getRequest(); 
    var map:java.util.Map = request.getParameterMap(); 
    var fileDataName = getClientId("fileUpload1");
    var fileData:com.ibm.xsp.http.UploadedFile = map.get( fileDataName ); 
    if (fileData == null) {
        getComponent("message").value = "File could not be found on " + fileDataName;

    var fileName = fileData.getServerFileName();
    var serverFile:java.io.File = fileData.getServerFile();
    if (serverFile != null && serverFile.exists()) {
         var dir = "/home/notesdata/Shared/XBRL"; //Want to create a folder programmatically called Test in XBRL folder so path should be /home/notesdata/Shared?XBRL/Test

        var tempFile:java.io.File = new java.io.File(fileName);
        var correctedFileName = dir + java.io.File.separator + fileData.getClientFileName();
         var correctedFile:java.io.File = new java.io.File( correctedFileName ); 
        var success = tempFile.renameTo(correctedFile);
        getComponent("message").value = "Yay!" + correctedFileName;
    else {
        getComponent("message").value = "There's a problem to find the temporal file.";


Use mkdir() to create a new folder in a path that already exist. So the following will create a new folder called Test in /home/notesdata/Shared/XBRL if that path already exists:

var newPath = "/home/notesdata/Shared/XBRL/Test";
var newFolder:java.io.File = new java.io.File(newPath);

Notice: use mkdirs() to create a new folder hierarchy that doesn’t already exist.