Safely wipe and re-create the destination directory.
@return {Promise}
767961
function refresh (env) {
    return safeWipe(env.dest, {
      force: true,
      parent: is.string(env.src) || is.array(env.src) ? g2b(env.src) : null,
      silent: true,
    })
      .then(() => mkdir(env.dest))
      .then(() => {
        env.logger.log(`Folder \`${env.displayDest}\` successfully refreshed.`)
      })
      .catch(err => {
        // Friendly error for already existing directory.
        throw new errors.SassDocError(err.message)
      })
  }
902621
def cd(new_directory, clean_up=lambda: True):  # pylint: disable=invalid-name
    
    previous_directory = os.getcwd()
    os.chdir(os.path.expanduser(new_directory))
    try:
        yield
    finally:
        os.chdir(previous_directory)
        clean_up()
677164
def clean_destination(dest)
      cached = @git.ls_files(dest)

      if @handler
        cached.select! do |file|
          results = @handler.on_precheck_delete?(file)
          # a file gets removed if there are no results or any result is false
          results.empty? || results.inject(&:&)
        end
      end

      @git.remove(*cached)
    end
570360
function create(options, cb) {

	options.force = (options.force) ? options.force : false;
	options.preserve = (options.preserve) ? options.preserve : true;
	options.password = getPwHash(options.password);  
	console.log('Gernerating directories with folling options:\n', options, '\n');
	if(options.test) {return;}
	//create directory
	if(options.force || !fs.existsSync(options.dest)) {
		wrench.mkdirSyncRecursive(options.dest);
		wrench.copyDirSyncRecursive(options.src, options.dest, { preserve: options.preserve }); 
	}
	if(options.files.length) {
		_.each(options.files, function(file) {
			fs.exists(path.join(options.dest,options.pwfile), function(exists) {
				if(!exists || options.force || file.force) {
					fs.writeFile(path.join(options.dest,strReplace(file.name, options)),  strReplace(file.data, options), function(err){
						if(err) {throw err;}
					});
				}
			});
		});
	}
	//Search and replace 
	replace(options.dest, {
		filters: ['index\.php$', '\.htaccess']
		, type: 'replace' 
		, values: [{
			user: options.user
			, root: options.root
			, project: options.project
			, title: options.title
			, userDir: options.userDir
			, pwfile: options.pwfile
		}]
	}, function(err, data) {
		if(cb) {
			cb(err, data);
			}
	});
}
1278323
function cleanup_directory(directory_path, callback) {
  // only remove the folder at directory_path if it exists
  fs.exists(directory_path, function (exists) {
    if (!exists) {
      return callback();
    }
    rimraf(directory_path, callback);
  });
}
645391
function makeDir(file) {
  return new Promise((resolve, reject) => {
    mkdirp(path.extname(file) ? path.dirname(file) : file, (err) => {
      if (err) reject(err);
      resolve();
    });
  });
}
860637
function clean(fld, leaveRoot = false) {
    return __awaiter(this, void 0, void 0, function* () {
        if (!leaveRoot) {
            yield del([fld]);
        }
        else {
            const promises = [];
            fs.readdirSync(fld).forEach(child => {
                promises.push(del(fld + '/' + child));
            });
            return Promise.all(promises);
        }
    });
}
843286
function mkdirRecursive(dirpath, mode, cb)
{
	if( arguments.length<3 ){
		cb= mode;
		mode= null;
	}
	
	fs.stat(dirpath, function(err, stats){
		if( err ){
			mkdirRecursive(path.dirname(dirpath), mode, function(err){
				if(err) cb(err);
				else{ fs.mkdir( dirpath, mode, cb ); }
			});
		}
		else if( stats.isDirectory() ){ cb( null ); }
		else{ cb( "create directory fail, not a directory, " + dirpath ); }
	});
}
774050
function() {
    // Cleans all cache files
    if (fs.existsSync(this.dir)) {
      var files = fs.readdirSync(this.dir);

      files.forEach(function(file) {
        fs.unlinkSync(path.join(this.dir, file));
      }.bind(this));
    }
  }
708972
function() {
    var wipe_opts = [
      '-token', opts.token,
      exports.cloud.toString(),
      exports.directories.toString()
    ];

    var args = [join(__dirname, 'runner.js')].concat(items).concat(wipe_opts);
    system.spawn_as_admin_user(node_bin, args, function(err, child) {
      if (err) {
        if (err.toString().includes('No logged user') && os_name == 'windows') {
          logger.warn('Not logged user found, proceding without impersonation')
          return queue(err, items);
        }
        else return finished(err);
      }

      if (typeof child == 'function') {  // only for windows
        os_wipe.paths.directories = exports.directories;

        wipe.fetch_dirs(items, exports.directories, exports.cloud, ['-token', token], (err, dirs_to_wipe) => {
          var opts = {
            dirs:  dirs_to_wipe,
            token: token,
            key:   keys.get().device.toString()
          };

          child('wipe', opts, function(err) {
            if (err) last_err = new Error('Wipe command failed through service');
            finished(last_err, true);
          });
        });

      } else {
        child.stdout.on('data', function(str) {
          var lines = str.toString().split(/\n/);
          lines.forEach(function(line) {
            if (line.toString().match('Removing directory')) {
              logger.warn(line.trim());
              removed++;
            } else if (line.toString().match('Error while removing dir')) {
              logger.warn(line.trim());
            } else if (line.trim() != '') {
              logger.debug(line.trim());
            }
          });
        })

        child.on('exit', function(code) {
          if (code !== 0)
            last_err = new Error('Wipe command failed.');

          finished(last_err);
        });

        wipe_process = child;
      }
    });
  }
428048
function() {
        var items = _utils.getArgArray(arguments);
        if (items.length === 0) {
            throw new Error('no folders specified to create');
        }
        items.forEach(function(item) {
            try {
                _fs.mkdirSync(item);
            } catch (e) {
                // Eat the exception.
            }
        });
    }
218683
function() {
                var def = _promise.deferred();

                _fs.exists(_folderPath, function(exists) {
                    if (exists) {
                        def.resolve();
                    } else {
                        _fs.mkdir(_folderPath, function(err) {
                            if (!err) {
                                def.resolve();
                            } else {
                                def.reject();
                            }
                        });
                    }
                });

                return def.promise();
            }
806146
function(sourceDir, newDirLocation, opts) {

        if (!opts || !opts.preserve) {
            try {
                if(fs.statSync(newDirLocation).isDirectory()) {
                    exports.rmdirSyncRecursive(newDirLocation);
                }
            }
            catch(e) { }
        }

        /*  Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */
        var checkDir = fs.statSync(sourceDir);
        try {
            fs.mkdirSync(newDirLocation, checkDir.mode);
        }
        catch (e) {
            //if the directory already exists, that's okay
            if (e.code !== 'EEXIST') {
                throw e;
            }
        }

        var files = fs.readdirSync(sourceDir);

        for(var i = 0; i < files.length; i++) {
            var currFile = fs.lstatSync(sourceDir + "/" + files[i]);

            if(currFile.isDirectory()) {
                /*  recursion this thing right on back. */
                copyDirectoryRecursiveSync(sourceDir + "/" + files[i], newDirLocation + "/" + files[i], opts);
            }
            else if(currFile.isSymbolicLink()) {
                var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]);
                fs.symlinkSync(symlinkFull, newDirLocation + "/" + files[i]);
            }
            else {
                /*  At this point, we've hit a file actually worth copying... so copy it on over. */
                var contents = fs.readFileSync(sourceDir + "/" + files[i]);
                fs.writeFileSync(newDirLocation + "/" + files[i], contents);
            }
        }
    }
651202
function ensureFolder(rootFolder) {
    return rmDir(rootFolder)
    .fail(function() {
        return Promise();
    })
    .then(function() {
        return Promise.nfcall(mkdirp, rootFolder);
    });
}
446803
function (callback) {
        // Name the destination folder
        context.tempName = generateId();
        // Create destination folder
        if (imageSizes.length) {
          context.tempFolder = tempPath + '/' + context.tempName;
          return fs.mkdir(context.tempFolder, callback);
        } else {
          return callback(null);
        }
      }
610380
function cleanUp (directoryToClean) {
  return new Promise((resolve, reject) => {
    rimraf(directoryToClean, (err) => {
      if (err) {
        return reject(new Error(err));
      }
      return resolve();
    });
  });
}
235345
function prepareRepo(remoteUrl, origin, dir) {
  let promise

  if (remoteUrl) {
    // if a remoteUrl was provided, use it
    promise = wrapPromise.Promise.resolve(remoteUrl)
  } else {
    // else try to extract it from the .git folder of
    // the current directory.
    promise = getRemoteUrl(git(process.cwd()), origin)
  }

  return promise.catch(function (e) { console.error(e) }).then(function (rUrl) {
    remoteUrl = rUrl

    return wrapPromise(function (resolve, reject) {
      function initRepo(repo) {
        repo.branch(function (err, head) {
          if (err) {
            reject(err)
            return
          }

          resolve(new Git(repo, head.name).status())
        })
      }

      function clearAndInitRepo() {
        rimraf(dir, function (rmErr) {
          if (rmErr) {
            reject(rmErr)
            return
          }

          git.clone(rUrl, dir, function (cloneErr, repo) {
            if (cloneErr) {
              reject(cloneErr)
              return
            }

            initRepo(repo)
          })
        })
      }

      // assume that if there is a .git folder get its remoteUrl
      // and check if it mathces the one we want to use.
      getRemoteUrl(git(dir), origin).then(function (cwdRemoteUrl) {
        if (remoteUrl === cwdRemoteUrl) {
          initRepo(git(dir))
          return
        }

        clearAndInitRepo()
      }, function () {

        clearAndInitRepo()
      })
    })
  }).catch(function (err) {
    console.error(err)
  })
}