Enforce unique upload file names using django?

Use uuid. To tie that into your model see Django documentation for FileField upload_to. For example in your models.py define the following function: import uuid import os def get_file_path(instance, filename): ext = filename.split(‘.’)[-1] filename = “%s.%s” % (uuid.uuid4(), ext) return os.path.join(‘uploads/logos’, filename) Then, when defining your FileField/ImageField, specify get_file_path as the upload_to value. file = … Read more

How do I rename files using R?

file.rename will rename files, and it can take a vector of both from and to names. So something like: file.rename(list.files(pattern=”water_*.img”), paste0(“water_”, 1:700)) might work. If care about the order specifically, you could either sort the list of files that currently exist, or if they follow a particular pattern, just create the vector of filenames directly … Read more

How to rename uploaded file before saving it into a directory?

You can simply change the name of the file by changing the name of the file in the second parameter of move_uploaded_file. Instead of move_uploaded_file($_FILES[“file”][“tmp_name”], “../img/imageDirectory/” . $_FILES[“file”][“name”]); Use $temp = explode(“.”, $_FILES[“file”][“name”]); $newfilename = round(microtime(true)) . ‘.’ . end($temp); move_uploaded_file($_FILES[“file”][“tmp_name”], “../img/imageDirectory/” . $newfilename); Changed to reflect your question, will product a random number based … Read more

Rename multiple files, but only rename part of the filename in Bash

If you have all of these files in one folder and you’re on Linux you can use: rename ‘s/test-this/REPLACESTRING/g’ * The result will be: REPLACESTRING.ext REPLACESTRING.volume001+02.ext REPLACESTRING.volume002+04.ext … rename can take a command as the first argument. The command here consists of four parts: s: flag to substitute a string with another string, test-this: the … Read more

How to rename the downloaded file with wget?

A redirect of standard output into arbitrary file name always works. You are doing it correctly as man wget says, using -O wget http://www.kernel.org/pub/linux/kernel/README -O foo –2013-01-13 18:59:44– http://www.kernel.org/pub/linux/kernel/README Resolving www.kernel.org… 149.20.4.69, 149.20.20.133 Connecting to www.kernel.org|149.20.4.69|:80… connected. HTTP request sent, awaiting response… 200 OK Length: 12056 (12K) [text/plain] Saving to: `foo’ 100%[======================================================================================================================================>] 12,056 –.-K/s in … Read more

Using sed to mass rename files

First, I should say that the easiest way to do this is to use the prename or rename commands. On Ubuntu, OSX (Homebrew package rename, MacPorts package p5-file-rename), or other systems with perl rename (prename): rename s/0000/000/ F0000* or on systems with rename from util-linux-ng, such as RHEL: rename 0000 000 F0000* That’s a lot … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)