file-rename

How to find out why renameTo() failed?

橙三吉。 提交于 2019-11-27 02:08:57
问题 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);

android, How to rename a file?

半城伤御伤魂 提交于 2019-11-27 01:32:33
In my application, I need to record video. Before start of recording in I'm assigning a name and directory to it. After recording is finished user has ability to rename his file. I wrote following code but seem it doesn't work. When user enters name of file and click on button I'll do this: private void setFileName(String text) { String currentFileName = videoURI.substring(videoURI.lastIndexOf("/"), videoURI.length()); currentFileName = currentFileName.substring(1); Log.i("Current file name", currentFileName); File directory = new File(Environment.getExternalStoragePublicDirectory(Environment

Rename files during upload within Wordpress backend

好久不见. 提交于 2019-11-27 01:22:52
问题 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 回答1: 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

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

醉酒当歌 提交于 2019-11-27 00:04:49
问题 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? 回答1: 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

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

匆匆过客 提交于 2019-11-26 23:38: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

How do I rename files using R?

China☆狼群 提交于 2019-11-26 17:35:50
I have over 700 files in one folder named as: files from number 1 to number9 are named for the first month: water_200101_01.img water_200101_09.img files from number 10 to number30 are named: water_200101_10.img water_200101_30.img And so on for the second month: files from number 1 to number9 are named: water_200102_01.img water_200102_09.img files from number 10 to number30 are named: water_200102_10.img water_200102_30.img How can I rename them without making any changes to the files. just change the nams, for example water_1 water_2 ...till... water_700 file.rename will rename files, and

Enforce unique upload file names using django?

こ雲淡風輕ζ 提交于 2019-11-26 17:30:39
问题 What's the best way to rename photos with a unique filename on the server as they are uploaded, using django? I want to make sure each name is used only once. Are there any pinax apps that can do this, perhaps with GUID? 回答1: 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

Getting Git to follow renamed and edited files

白昼怎懂夜的黑 提交于 2019-11-26 17:11:50
问题 Questions about renaming files in Git have been asked before, but I can't work out a solution to my specific problem. I have moved and edited multiple files (I didn't use git mv - unfortunately it's now too late for that). Now I want it so when my colleague pulls from my repository, having made his own edits to those same files (without moving them), it successfully merges my changes with his in the file's new location. To successfully merge, Git clearly needs to know that these are the same

Rename multiple files in Python

折月煮酒 提交于 2019-11-26 13:46:43
问题 How can I rename the following files: abc_2000.jpg abc_2001.jpg abc_2004.jpg abc_2007.jpg into the following ones: year_2000.jpg year_2001.jpg year_2004.jpg year_2007.jpg The related code is: import os import glob files = glob.glob('abc*.jpg') for file in files: os.rename(file, '{}.txt'.format(???)) 回答1: import os import glob files = glob.glob('year*.jpg') for file in files: os.rename(file, 'year_{}'.format(file.split('_')[1])) The one line can be broken to: for file in files: parts = file

Batch renaming files with Bash

孤者浪人 提交于 2019-11-26 12:03:19
How can Bash rename a series of packages to remove their version numbers? I've been toying around with both expr and %% , to no avail. Examples: Xft2-2.1.13.pkg becomes Xft2.pkg jasper-1.900.1.pkg becomes jasper.pkg xorg-libXrandr-1.2.3.pkg becomes xorg-libXrandr.pkg richq You could use bash's parameter expansion feature for i in ./*.pkg ; do mv "$i" "${i/-[0-9.]*.pkg/.pkg}" ; done Quotes are needed for filenames with spaces. If all files are in the same directory the sequence ls | sed -n 's/\(.*\)\(-[0-9.]*\.pkg\)/mv "\1\2" "\1.pkg"/p' | sh will do your job. The sed command will create a