title: How to create nested directories in Phonegap
body: <p>I have tried <a href="https://stackoverflow.com/questions/10961000/nested-directory-creator-phonegap">this</a>, but it didn't satisfy my request at all. I write a new one:</p>
  
  <pre><code>var file_system;
  var fs_root;
  window.requestFileSystem(LocalFileSystem.PERSISTENT, 1024*1024, onInitFs, request_FS_fail);
  
  function onInitFs(fs) {
    file_system= fs;
    fs_root= file_system.root;
    alert("ini fs");
    create_Directory();
    alert("ini fs done.");
  }
  var string_array;
  var main_dir= "story_repository/"+ User_Editime;
  string_array= new Array("story_repository/",main_dir, main_dir+"/rec", main_dir+"/img","story_repository/"+ User_Name );
  
  function create_Directory(){
    var start= 0;
    var path="";
    while(start &lt; string_array.length) {
      path = string_array[start];
      alert(start+" th created directory " +" is "+ path);
      fs_root.getDirectory(
        path,
        {create: true, exclusive: false},
        function(entry) {
          alert(path +"is created.");
        },
        create_dir_err()
      );
      start++;
    }//while loop
  }//create_Directory
  
  function create_dir_err() {
    alert("Recursively create directories error.");
  }
  
  function request_FS_fail() {
    alert("Failed to request File System ");
  }
  </code></pre>
  
  <p>Although the directories are created, the it sends me</p>
  
  <blockquote>
    <p>ErrorCallback:"alert("Recursively create directories error.");"</p>
  </blockquote>
  
  <p>First, I don't think this code will work since I have tried this, which failed:</p>
  
  <pre><code>window.requestFileSystem(
    LocalFileSystem.PERSISTENT,
    0,
    //request file system success callback.
    function(fileSys) {
      fileSys.root.getDirectory(
        "story_repository/"+ dir_name,
        {create: true, exclusive: false},
        //Create directory story_repository/Stallman_time.
        function(directory) {
          alert("Create directory: "+ "story_repository/"+ dir_name);
          //create dir_name/img/
          fileSys.root.getDirectory {
            "story_repository/"+ dir_name + "/img/",
            {create: true, exclusive: false},
            function(directory) {
              alert("Create a directory: "+ "story_repository/"+ dir_name + "/img/");
              //check.
              //create dir_name/rec/
              fileSys.root.getDirectory {
                "story_repository/"+ dir_name + "/rec/",
                {create: true, exclusive: false},
                function(directory) {
                  alert("Create a directory: "+ "story_repository/"+ dir_name + "/rec/");
                  //check.
                  //Go ahead.
                },
                createError
              }
              //create dir_name/rec/
            },
            createError
          }
          //create dir_name/img
        },
        createError
      );
    },
    //Create directory story_repository/Stallman_time.
    createError());
  }
  </code></pre>
  
  <p>I just repeatedly call <code>fs.root.getDirectory</code> only but it failed. But the first one is almost the same...</p>
  
  <ol>
  <li>What is the problem at all? Why does the first one always gives me the ErrorCallback?</li>
  <li>Why can't the second one work?</li>
  <li>Does anyone has a better solution? (no ErrorcallBack msg)</li>
  </ol>
  
  <p>ps: I work on Android and PhoneGap 1.7.0.</p>