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

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

Changing capitalization of filenames in Git

Starting Git 2.0.1 (June 25th, 2014), a git mv will just work on a case-insensitive OS. See commit baa37bf by David Turner (dturner-tw). mv: allow renaming to fix case on case-insensitive filesystems “git mv hello.txt Hello.txt” on a case-insensitive filesystem always triggers “destination already exists” error, because these two names refer to the same path … Read more

Rename a file using Java

Copied from http://exampledepot.8waytrips.com/egs/java.io/RenameFile.html // File (or directory) with old name File file = new File(“oldname”); // File (or directory) with new name File file2 = new File(“newname”); if (file2.exists()) throw new java.io.IOException(“file exists”); // Rename file (or directory) boolean success = file.renameTo(file2); if (!success) { // File was not successfully renamed } To append to … 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