src/project/ProjectModel.js
function doCreate(path, isFolder) {
        var d = new $.Deferred();
        var filename = FileUtils.getBaseName(path);

        // Check if filename
        if (!isValidFilename(filename)){
            return d.reject(ERROR_INVALID_FILENAME).promise();
        }

        // Check if fullpath with filename is valid
        // This check is used to circumvent directory jumps (Like ../..)
        if (!isValidPath(path)) {
            return d.reject(ERROR_INVALID_FILENAME).promise();
        }

        FileSystem.resolve(path, function (err) {
            if (!err) {
                // Item already exists, fail with error
                d.reject(FileSystemError.ALREADY_EXISTS);
            } else {
                if (isFolder) {
                    var directory = FileSystem.getDirectoryForPath(path);

                    directory.create(function (err) {
                        if (err) {
                            d.reject(err);
                        } else {
                            d.resolve(directory);
                        }
                    });
                } else {
                    // Create an empty file
                    var file = FileSystem.getFileForPath(path);

                    FileUtils.writeText(file, "").then(function () {
                        d.resolve(file);
                    }, d.reject);
                }
            }
        });

        return d.promise();
    }
function doCreate(path, isFolder) {
        var d = new $.Deferred();
        var filename = FileUtils.getBaseName(path);

        // Check if filename
        if (!isValidFilename(filename)){
            return d.reject(ERROR_INVALID_FILENAME).promise();
        }

        // Check if fullpath with filename is valid
        // This check is used to circumvent directory jumps (Like ../..)
        if (!isValidPath(path)) {
            return d.reject(ERROR_INVALID_FILENAME).promise();
        }

        FileSystem.resolve(path, function (err) {
            if (!err) {
                // Item already exists, fail with error
                d.reject(FileSystemError.ALREADY_EXISTS);
            } else {
                if (isFolder) {
                    var directory = FileSystem.getDirectoryForPath(path);

                    directory.create(function (err) {
                        if (err) {
                            d.reject(err);
                        } else {
                            d.resolve(directory);
                        }
                    });
                } else {
                    // Create an empty file
                    var file = FileSystem.getFileForPath(path);

                    FileUtils.writeText(file, "").then(function () {
                        d.resolve(file);
                    }, d.reject);
                }
            }
        });

        return d.promise();
    }
function doCreate ( path , isFolder ) { var d = new $ . Deferred ( ) ; var filename = FileUtils . getBaseName ( path ) ; // Check if filename if ( ! isValidFilename ( filename ) ) { return d . reject ( ERROR_INVALID_FILENAME ) . promise ( ) ; } // Check if fullpath with filename is valid // This check is used to circumvent directory jumps (Like ../..) if ( ! isValidPath ( path ) ) { return d . reject ( ERROR_INVALID_FILENAME ) . promise ( ) ; } FileSystem . resolve ( path , function ( err ) { if ( ! err ) { // Item already exists, fail with error d . reject ( FileSystemError . ALREADY_EXISTS ) ; } else { if ( isFolder ) { var directory = FileSystem . getDirectoryForPath ( path ) ; directory . create ( function ( err ) { if ( err ) { d . reject ( err ) ; } else { d . resolve ( directory ) ; } } ) ; } else { // Create an empty file var file = FileSystem . getFileForPath ( path ) ; FileUtils . writeText ( file , "" ) . then ( function ( ) { d . resolve ( file ) ; } , d . reject ) ; } } } ) ; return d . promise ( ) ; }
Creates a new file or folder at the given path. The returned promise is rejected if the filename
is invalid, the new path already exists or some other filesystem error comes up.

@param {string} path path to create
@param {boolean} isFolder true if the new entry is a folder
@return {$.Promise} resolved when the file or directory has been created.
Creates a new file or folder at the given path . The returned promise is rejected if the filename is invalid the new path already exists or some other filesystem error comes up .