Creates a unique file name based on the specified base name.

    @base_name - The base name to use for the unique file name.
    @extension - The file extension to use for the unique file name.

    Returns a unique file string.
515237
def unique_file_name(base_name, extension=''):
    '''
    
    '''
    idcount = 0

    if extension and not extension.startswith('.'):
        extension = '.%s' % extension

    fname = base_name + extension

    while os.path.exists(fname):
        fname = "%s-%d%s" % (base_name, idcount, extension)
        idcount += 1

    return fname
733465
def file_basename(self, file):
        '''
        
        '''
        valid_extensions = set(".tree",
                               ".tre")
        split_file = os.path.basename(file).split('.')
        base, suffix = '.'.join(split_file[:-1]), split_file[-1]

        if suffix in valid_extensions:
            return base
        else:
            logging.error("Invalid file extension found on file: %s" % file)
            logging.error("For trees, please provide a file with one of the \
following extensions: %s" % ' '.join(valid_extensions.keys()))
            raise InvalidFileExtensionError
1335596
def create_file(self, name: str, generate_unique_name: bool = False):
        '''
        
        '''
        def enumerate_name():
            yield name
            index = 0
            while True:
                index += 1
                yield f'{name} ({index})'
        for n in enumerate_name():
            path = os.path.join(self._path, n)
            if os.path.exists(path):
                if not generate_unique_name:
                    raise FileExistsError
            return FileInfo(path)
339577
def ext_from_filename(filename):
    
    try:
        base, ext = filename.lower().rsplit(".", 1)
    except ValueError:
        return ''
    ext = ".{0}".format(ext)
    all_exts = [x.extension for x in chain(magic_header_array,
                                           magic_footer_array)]

    if base[-4:].startswith("."):
        # For double extensions like like .tar.gz
        long_ext = base[-4:] + ext
        if long_ext in all_exts:
            return long_ext
    return ext
880895
public function getSafeFileName()
    {
        $fileExtension = pathinfo($this->file->getClientOriginalName(), PATHINFO_EXTENSION);
        $mimeTypeExtension = $this->file->guessExtension();
        $newExtension = !empty($mimeTypeExtension) ? $mimeTypeExtension : $fileExtension;

        $baseName = !empty($fileExtension) ? basename($this->file->getClientOriginalName(), $fileExtension) : $this->file->getClientOriginalName();
        $safeBaseName = Transliterator::urlize($baseName);

        return $safeBaseName . (!empty($newExtension) ? '.' . $newExtension : '');
    }
202957
def write filename, options={}
      extension = file_extension(filename)
      send("write_to_#{extension}".to_sym, filename, options)
    end
1373106
def basename(file_path)
      filename = File.basename(file_path)
      return filename.split('.')[0].to_sym if file_path
    end
242833
def filename(self):
        
        if self._filename is None:
            self._filename = storage.get_file(self.basename,
                                              self.ccd,
                                              ext=self.extension,
                                              version=self.type,
                                              prefix=self.prefix)
        return self._filename
82358
public function name()
    {
        if (!$this->info) {
            $this->info();
        }
        if (isset($this->info['extension'])) {
            return basename($this->name, '.' . $this->info['extension']);
        } elseif ($this->name) {
            return $this->name;
        }

        return false;
    }
331321
public static function newName($name)
    {
        if (file_exists($name)) {
            $extension = self::getFileExtension($name);
            $name = substr($name,0,(-strlen($extension)-1)) . '_' . sha1(uniqid(rand(), true)) . ".$extension";
        }
        return $name;
    }
752404
def process(name)
      self.ext = File.extname(name)
      self.basename = name[0..-ext.length - 1].gsub(%r!\.*\z!, "")
    end
349599
def archive_basename(filename):
    ''''''
    for archive in archive_formats:
        if filename.endswith(archive_formats[archive]['suffix']):
            return filename.rstrip('.' + archive_formats[archive]['suffix'])
    return False
194091
protected String createFile() throws IOException {
        generateNewBasename();
        String name = currentBasename + '.' + this.extension  +
            ((settings.getCompress())? DOT_COMPRESSED_FILE_EXTENSION: "") +
            OCCUPIED_SUFFIX;
        File dir = getNextDirectory(settings.calcOutputDirs());
        return createFile(new File(dir, name));
    }
1241274
function createBasenameList(files) {
    const basenames = {};
    files.forEach(function (file) {
        const basename = file.replace(/(-[0-9]+.[0-9]+.[A-Za-z0-9_-]+)?([.-]min)?(.amd|.commonjs|.mustache)?(\.[a-zA-Z]+$)/, '');
        basenames[basename] = true;
    });
    return Object.keys(basenames);
}
510249
function getNewFilename(list, name) {
  if (list.indexOf(name) === -1) {
    return name;
  }
  const parsed = parseFilename(name);
  const base = parsed.base;
  const ext = parsed.ext;
  if (!base) {
    const newName = getNextNumberName(ext);
    return getNewFilename(list, newName);
  } else {
    const basename = getNextNumberName(base);
    return getNewFilename(list, `${basename}${ext}`);
  }
}
930486
def filename(self, prefix='', suffix='', extension='.py'):
        """"""
        return BASE_NAME.format(prefix, self.num, suffix, extension)
840170
def pattern_for(basename)
        extname = File.extname(basename)
        aliases = @reverse_aliases[extname]

        if aliases
          basename = File.basename(basename, extname)
          aliases  = [extname] + aliases
          aliases_pattern = aliases.map { |e| Regexp.escape(e) }.join("|")
          basename_re = Regexp.escape(basename) + "(?:#{aliases_pattern})"
        else
          basename_re = Regexp.escape(basename)
        end

        extension_pattern = extensions.map { |e| Regexp.escape(e) }.join("|")
        /^#{basename_re}(?:#{extension_pattern})*$/
      end