create unique name for saved file (same pattern as BB10 camera app)
778112
function imgName() {
    var date = new Date(),
        pad = function (n) { return n < 10 ? '0' + n : n; };
    return 'IMG_' + date.getFullYear() + pad(date.getMonth() + 1) + pad(date.getDate()) + '_' +
            pad(date.getHours()) + pad(date.getMinutes()) + pad(date.getSeconds()) + '.png';
}
1279415
def file_save(self, name, filename=None, folder="", keep_ext=True) -> bool:
        
        if name in self.files:
            file_object = self.files[name]
            clean_filename = secure_filename(file_object.filename)
            if filename is not None and keep_ext:
                clean_filename = filename + ".%s" % \
                    (clean_filename.rsplit('.', 1)[1].lower())
            elif filename is not None and not keep_ext:
                clean_filename = filename
            file_object.save(os.path.join(
                current_app.config['UPLOADS']['FOLDER'],
                folder, clean_filename))
        return None
1224574
def generate_unique_name(self, basename):
        """"""
        counts = self.__counts
        try:
            count = counts[basename]
            counts[basename] += 1
        except KeyError:
            count = 0
            counts[basename] = 1
            
        prefix = self.Naming_prefix

        if count == 0:
            name = prefix + basename
        else:
            name = prefix + basename + "_" + str(count)
            
        if prefix != "" or count != 0:
            try:
                count = counts[name]
                return self.generate_unique_name(name)
            except KeyError:
                # wasn't already used so return it
                counts[name] = 1
        return name
770794
def generate_filename(self, directory=os.getcwd(), prefix='tile',
                          format='png', path=True):
        """"""
        filename = prefix + '_{col:02d}_{row:02d}.{ext}'.format(
                      col=self.column, row=self.row, ext=format.lower().replace('jpeg', 'jpg'))
        if not path:
            return filename
        return os.path.join(directory, filename)
653714
def save(self, filename):
        
        with open(filename, 'wb') as fp:
            writer = BlockWriter()
            factory = BlockFactory()

            preamble_dummy_bytes = bytearray([0] * 9)
            preamble = bread.parse(
                preamble_dummy_bytes, spec.lsdsng_preamble)
            preamble.name = self.name
            preamble.version = self.version

            preamble_data = bread.write(preamble)
            raw_data = self.get_raw_data()
            compressed_data = filepack.compress(raw_data)

            writer.write(compressed_data, factory)

            fp.write(preamble_data)

            for key in sorted(factory.blocks.keys()):
                fp.write(bytearray(factory.blocks[key].data))
323282
def __filename(self, id):
        """"""
        suffix = self.fnsuffix()
        filename = "%s-%s.%s" % (self.fnprefix, id, suffix)
        return os.path.join(self.location, filename)
890381
def store(self, transient_file, persistent_file):
        ''''''
        #for i in range(5):
        #    persistent_file = PersistentFile(self.persistent_root,
        #                                     persistent_name, self)
        #    if not os.path.exists(persistent_file.path):
        #        break
        #else:
        #    raise Exception('Unable to find free file name')
        dirname = os.path.dirname(persistent_file.path)
        if not os.path.isdir(dirname):
            os.makedirs(dirname)
        os.rename(transient_file.path, persistent_file.path)
        return persistent_file
402505
def save(self, filename):
        

        if filename is None:
            filename = self.filename('.b26s')
        # if len(filename.split('\\\\?\\')) == 1:
        #     filename = '\\\\?\\' + filename
        with open(filename, 'w') as outfile:
            outfile.write(pickle.dumps(self.__dict__))
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)
438047
def _create_cache_filename(self, cache_dir=None, **kwargs):
        """"""
        cache_dir = cache_dir or '.'
        hash_str = self.get_hash(**kwargs)

        return os.path.join(cache_dir, 'resample_lut-' + hash_str + '.npz')
228375
def backup_name(self, timestamp=None):
        
        suffix = datetime2string(coalesce(timestamp, datetime.now()), "%Y%m%d_%H%M%S")
        return File.add_suffix(self._filename, suffix)
832770
def save(cls,instance,filename):
        """"""
        filename = cls.correct_file_extension(filename)
        try:
            with open(filename,'wb') as f:
                pickle.dump(instance,f,protocol=pickle.HIGHEST_PROTOCOL)
        except MemoryError as e:
            print ('{} occurred, will downsampled the saved file by 20.'
                   .format(type(e).__name__))
            copy_instance = instance.copy()
            copy_instance.H = copy_instance.H[::20,:,:]
            copy_instance.Y = copy_instance.Y[::20,:]
            with open(filename,'wb') as f:
                pickle.dump(copy_instance,f,protocol=pickle.HIGHEST_PROTOCOL)
822605
def random_filename(path=None):
    """"""
    filename = uuid4().hex
    if path is not None:
        filename = os.path.join(path, filename)
    return filename
381116
function saveFileChanges(themeId, folderName, fileName, text) {
        io({
            url:getURL("save") + "/" + themeId + "/" + folderName + "/" + fileName,
            data:{
                content:encodeURI(text)
            },
            callback:function (isSuccess, message, response) {
                if (!isSuccess) {
                    showErrorMsg(message);
                }
            }
        });
    }
754719
private function setSeveName()
    {
        $this->saveName = $this->randomFileName();

        if ($this->saveName == '')
        {
            $this->saveName = $this->files['name'];
        }
    }
1343956
def file_id_to_name(self, file_id):
        """"""
        sql = 'select name from files where id = ?'
        logging.debug('%s %s', sql, (file_id,))
        self.cursor.execute(sql, (file_id,))
        name = self.cursor.fetchone()
        if name:
            return name[0]
        return ''
530477
def get_new_filename(self, name: str) -> str:
        
        nonce = get_random_string(length=8)
        return '%s-%s/%s/%s.%s.%s' % (
            self.obj._meta.model_name, self.attribute_name,
            self.obj.pk, name, nonce, name.split('.')[-1]
        )