file-rename

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

落爺英雄遲暮 提交于 2019-11-28 17:46:23
I know how I can rename files and such, but I'm having trouble with this. I only need to rename test-this in a for loop. test-this.ext test-this.volume001+02.ext test-this.volume002+04.ext test-this.volume003+08.ext test-this.volume004+16.ext test-this.volume005+32.ext test-this.volume006+64.ext test-this.volume007+78.ext 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

How can I batch rename files using the Terminal?

我们两清 提交于 2019-11-28 15:55:16
问题 I have a set of files, all of them nnn.MP4.mov . How could I rename them so that it is just nnn.mov ? 回答1: First, do a dry run (will not actually rename any files) with the following: for file in *.mov do echo mv "$file" "${file/MP4./}" done If it all looks fine, remove the echo from the third line to actually rename the files. 回答2: I just successfully used Automator (first time I've bothered), and it works really well. I saved the automation as a Service. It took about 10 seconds to make

Rename uploaded file (php)

安稳与你 提交于 2019-11-28 14:06:00
问题 I'm trying to rename a file I'm uploading. I will be uploading a xml or pdf file, and I want it to be in a folder called "files/ orderid /" and the filename should also be orderid .extension The file uploads fine, and the folder id created with the correct name, but all the ways I have tried to rename it fails. Below is my code. // include database connection include 'config/database.php'; // get passed parameter value, in this case, the record ID $id=isset($_GET['orderid']) ? $_GET['orderid'

How to change file extension at runtime in Java

余生长醉 提交于 2019-11-28 11:20:47
I am trying to implement program to zip and unzip a file. All I want to do is to zip a file (fileName.fileExtension) with name as fileName.zip and on unzipping change it again to fileName.fileExtension . Try with: File file = new File("fileName.zip"); // handler to your ZIP file File file2 = new File("fileName.fileExtension"); // destination dir of your file boolean success = file.renameTo(file2); if (success) { // File has been renamed } John This is how I used to rename files or change its extension. public static void modify(File file) { int index = file.getName().lastIndexOf("."); //print

Batch file script to remove special characters from filenames (Windows)

我与影子孤独终老i 提交于 2019-11-28 09:17:02
I have a large set of files, some of which contain special characters in the filename (e.g. ä,ö,%, and others). I'd like a script file to iterate over these files and rename them removing the special characters. I don't really mind what it does, but it could replace them with underscores for example e.g. Störung%20.doc would be renamed to St_rung_20.doc In order of preference: A Windiws batch file A Windows script file to run with cscript (vbs) A third party piece of software that can be run from the command-line (i.e. no user interaction required) Another language script file, for which I'd

How to find out why renameTo() failed?

纵饮孤独 提交于 2019-11-28 08:05:01
I am using WinXP. I use java to generate a list of files. The file will be created as abc.txt.temp at first, and after completing the generation, it will be renamed to abc.txt. However, when i generating the files, some of the files failed to be renamed. It happen randomly. Is there anyway to find out the reason why it failed? int maxRetries = 60; logger.debug("retry"); while (maxRetries-- > 0) { if (isSuccess = file.renameTo(file2)) { break; } try { logger.debug("retry " + maxRetries); Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(

php - Differences between copy, rename and move_uploaded_file

£可爱£侵袭症+ 提交于 2019-11-28 07:05:09
问题 Are there differences when I use that functions? Why should I use one instead of the other one... 回答1: copy() copies the file - you now have 2 files, and for large files, this can take very long rename() changes the file's name, which can mean moving it between directories. move_uploaded_file() is basically the same as rename() , but it will only work on files that have been uploaded via PHP's upload mechanism. This is a security feature that prevents users from tricking your script into

Rename files during upload within Wordpress backend

不想你离开。 提交于 2019-11-28 06:33:56
is there a way to rename files during the upload progress within the Wordpress 3.0 backend? I would like to have a consistent naming of files, especially for images. I think an 12 (+-) digit hash value of the original filename or something similar would be awesome. Any suggestions? Regards But it would really be easier to do that before uploading files. Not quite sure about that - this seems fairly easy; /** * @link http://stackoverflow.com/a/3261107/247223 */ function so_3261107_hash_filename( $filename ) { $info = pathinfo( $filename ); $ext = empty( $info['extension'] ) ? '' : '.' . $info[

How to do a git diff on moved/renamed file?

岁酱吖の 提交于 2019-11-28 03:37:26
I moved a file using git mv . Now I would like to do a diff on the new file to compare it with the old file (with the old, now non-existent name). How do I do this? You need to use -M to let git autodetect the moved file when diffing. Using just git diff as knittl mentioned does not work for me. So simply: git diff -M should do it. The documentation for this switch is: -M[<n>], --find-renames[=<n>] Detect renames. If n is specified, it is a threshold on the similarity index (i.e. amount of addition/deletions compared to the file’s size). For example, -M90% means git should consider a delete

When renaming a file with PowerShell, how do I handle filenames with “[”?

南笙酒味 提交于 2019-11-28 02:06:04
I'm running this PowerShell command: Get-ChildItem .\tx\*.htm | Rename-Item -NewName {$_.Name -replace '\.htm','.tmp'} and receive the following error when a filename contains square brackets -- [ and/or ] --, understandable since those have a meaning within the PowerShell syntax. Rename-Item : Cannot rename because item at 'Microsoft.PowerShell.Core\FileSystem::C:\users\xxxxx\desktop\tx\ Foofoofoofoo_foo_foo_[BAR]_Foofoofoofoo_foofoofoo.htm' does not exist. At C:\users\xxxxx\desktop\foo002.ps1:59 char:39 + Get-ChildItem .\tx\*.htm | Rename-Item <<<< -NewName { $_.Name -replace '\.htm','.tmp'