Create a new file but fail if it already exists. The check for
existance of the file and it's creation are an atomic operation with
respect to other filesystem activities.
321011
public void createNewFile() throws SmbException {
        if( getUncPath0().length() == 1 ) {
            throw new SmbException( "Invalid operation for workgroups, servers, or shares" );
        }
        close( open0( O_RDWR | O_CREAT | O_EXCL, 0, ATTR_NORMAL, 0 ), 0L );
    }
688963
function fileExists(fileName) {
  return new BbPromise((resolve) => {
    fs.exists(fileName, (exists) => resolve(exists));
  });
}
794347
def verify_file_exists(file_name, file_location):
    
    return __os.path.isfile(__os.path.join(file_location, file_name))
1062874
boolean add(Path filename) {
    synchronized (pendingReplications) {
      PendingInfo found = pendingReplications.get(filename);
      if (found == null) {
        pendingReplications.put(filename, new PendingInfo(filename));
        return true;
      }
      return false;
    }
  }
387292
def check_exists(filename, oappend=False):
    
    if op.exists(filename):
        if oappend:
            return oappend
        logging.error("`{0}` found, overwrite (Y/N)?".format(filename))
        overwrite = (raw_input() == 'Y')
    else:
        overwrite = True

    return overwrite
522197
function _shouldKeepExisting(file, text)
{
return Promise.coroutine(function *() {
	if (!(yield fs.fileExists(file)))
		return false;

//	var st = yield fs.stat(file);
//	if (st > _ThisBuild)
//		l.logw("File is used multiple times: '" + file)+"'");

	// read the existing file and compare with new contents. ignore if nothing changed
	try
	{
		var existingText = yield fs.readFile(file, "utf8");
		if (existingText == text)
		{
			//l.vlog("Skipping (unchanged): '" + file + "'");
			return true;
		}
	}
	catch (e)
	{
		l.logw("Failed to compare existing file " + path.basename(file) + " (will try and overwrite): " + _.niceStackTrace(e));
		// and continue below...
	}
	return false;
})();
}
3837
function existFile(filePath, mode = fs.constants.W_OK) {
  return new Promise((resolve, reject) => {
    fs.access(filePath, mode, (err) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(filePath);
    });
  });
}
200513
protected void create(File file) throws IOException {
        if(!file.exists()) {
            File dir = file.getParentFile();
            if(dir.exists()) file.createNewFile();
            else if(dir.mkdirs()) file.createNewFile();
            else throw new IOException("Failed to create " + file.getAbsolutePath());
        }
        
        if(file.isDirectory()) {
            throw new IOException("Cannot open directory " + file.getAbsolutePath());
        }
    }
1302788
def create_existing_file(help_string=NO_HELP, default=NO_DEFAULT, suffixes=None):
        # type: (str, Union[str, NO_DEFAULT_TYPE], Union[List[str], None]) -> str
        
        # noinspection PyTypeChecker
        return ParamFilename(
            help_string=help_string,
            default=default,
            type_name="existing_file",
            suffixes=suffixes,
        )
751757
private function checkFile()
    {
        $fileUtils = new FileUtils();
        // check File
        try {
            if (null === $this->file) {
                $this->file = $fileUtils->resolveFile($this->getProject()->getBasedir(), self::DEFAULT_FILENAME);
            }
            if (!$this->file->exists()) {
                $this->file->createNewFile();
                $this->log(
                    'Creating file "' . $this->file->getName() . '" since it was not present',
                    Project::MSG_INFO
                );
            }
        } catch (IOException $ioe) {
            $message = $this->file . " doesn't exist and new file can't be created.";
            throw new BuildException($message, $ioe);
        }

        if (!$this->file->canRead()) {
            $message = "Unable to read from " . $this->file . ".";
            throw new BuildException($message);
        }
        if (!$this->file->canWrite()) {
            $message = "Unable to write to " . $this->file . ".";
            throw new BuildException($message);
        }
    }
1218080
def create(
    name,

    create_file,
    open_file,
    remove_file,

    create_directory,
    list_directory,
    remove_empty_directory,
    temporary_directory,

    stat,

    lstat,
    link,
    readlink,

    realpath=_realpath,
    remove=_recursive_remove,
):
    

    methods = dict(
        create=create_file,
        open=lambda fs, path, mode="r": open_file(
            fs=fs, path=path, mode=mode,
        ),
        remove_file=remove_file,

        create_directory=create_directory,
        list_directory=list_directory,
        remove_empty_directory=remove_empty_directory,
        temporary_directory=temporary_directory,

        get_contents=_get_contents,
        set_contents=_set_contents,
        create_with_contents=_create_with_contents,

        remove=remove,
        removing=_removing,

        stat=stat,

        lstat=lstat,
        link=link,
        readlink=readlink,
        realpath=realpath,

        exists=_exists,
        is_dir=_is_dir,
        is_file=_is_file,
        is_link=_is_link,

        touch=_touch,

        children=_children,
        glob_children=_glob_children,
    )
    return attr.s(hash=True)(type(name, (object,), methods))
440337
function existsFile(file, permission) {
    return Promise.resolve(fsPromise.accessAsync(file, permission))
      .then(() => true)
      .catch(() => false);
}
999542
public static FSDataOutputStream tryCreateFile(FileSystem fs, Path file) throws IOException {
    try {
      FSDataOutputStream os = fs.create(file, false);
      return os;
    } catch (FileAlreadyExistsException e) {
      return null;
    } catch (RemoteException e) {
      if( e.unwrapRemoteException() instanceof AlreadyBeingCreatedException ) {
        return null;
      } else { // unexpected error
        throw e;
      }
    }
  }
689025
def create(self):
        
        if not os.path.exists(self.path):
            with open(self.path, 'w') as fileobj:
                fileobj.write('')
1000390
def _ensure_module_folder_exists():
  
  if not os.path.isdir(MODULES_FOLDER_PATH):
    try:
      os.mkdir(MODULES_FOLDER_PATH)
    except OSError, e:
      if "file already exists" in str(e):
        raise RuntimeError("Could not create modules folder: file exists with the same name")
479712
public static boolean createFile(String filePath) {
        if (!StringUtils.isEmpty(filePath)) {
            File file = new File(filePath);
            return createFile(file);
        }
        return false;
    }
147331
def file_exists(original_file):
    
    if original_file.startswith("s3://"):
        from filesystem import s3
        return s3.file_exists(original_file)
    else:
        if not os.path.exists(original_file):
            return False
        if not os.path.isfile(original_file):
            return False
    return True