title: Grunt - Can you call grunt-contrib-copy from within a custom registered task and customize the copy on the fly?
body: <p>I know I can setup a task in grunt.config that will grunt-contrib-copy files from src to dest, and looking through Grunt docs I know I can copy single files using grunt.file.copy.</p>
  
  <p>But, is it possible to create grunt-contrib-copy tasks on the fly in a custom registered task to accommodate arguments being sent from the bash?  I want to create a new directory grunt.file.mkdir("some/path/appfoldername") and then copy files to that folder from another destination, but I won't know the folder name until after the custom task is run.  So something like:</p>
  
  <pre><code>grunt create_app:appfoldername
  </code></pre>
  
  <p>So I could copy single files over one at a time, but the files will change so want the power of grunt-contrib-copy, but with the flexibility of a custom registered task.</p>
  
  <p>I imagine something like this if my explanation isn't clear enough:</p>
  
  <pre><code>grunt.registerTask('createCopy', 'Create a copy', function(folderName) {
  
      var cwd = grunt.template.process("some/path/to/app");
      var src = grunt.template.process("some/path/to/src");
      var dest = grunt.template.process("some/path/to/dest") + folderName;
  
      grunt.task.run('copy: {  
         files: { 
            cwd: cwd,
            src: src,
            dest: dest
         }           
      }');
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>grunt.registerTask('mkapp', 'Create Application', function(appName) {
  
      // Check appName is not empty or undefined
      if(appName !== "" &amp;&amp; appName !== undefined) { 
  
          // Require node path module, since not a global
          var path = require("path");
  
          // Resolve directory path using templates
          var relPath = grunt.template.process("&lt;%= root %&gt;/&lt;%= dirs.src %&gt;/application/");
          var srcPath = relPath + "default_install";
          var destPath = relPath + appName;
  
          // Create new application folder
          grunt.file.mkdir(destPath, 0444);
  
          // Return unique array of all file paths which match globbing pattern
          var options = { cwd: srcPath, filter: 'isFile' };
          var globPattern = "**/*"
  
          grunt.file.expand(options, globPattern).forEach(function(srcPathRelCwd) {
  
              // Copy a source file to a destination path, creating directories if necessary
              grunt.file.copy(
                  path.join(srcPath, srcPathRelCwd), 
                  path.join(destPath, srcPathRelCwd)
              );
          });
      }
  });
  </code></pre>