file-rename

Is rename() atomic?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-26 11:10:51
问题 I am not being able to check this via experiments and could not gather it from the man pages as well. Say I have two processes, one moving(rename) file1 from directory1 to directory2. Say the other process running concurrently copies the contents of directory1 and directory2 to another location. Is it possible that the copy happens in such a way that both directory1 and directory2 will show file1 - i.e directory1 is copied before the move and directory2 after the move by the first process.

android, How to rename a file?

拥有回忆 提交于 2019-11-26 09:40:53
问题 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

Using sed to mass rename files

和自甴很熟 提交于 2019-11-26 07:17:40
问题 Objective Change these filenames: F00001-0708-RG-biasliuyda F00001-0708-CS-akgdlaul F00001-0708-VF-hioulgigl to these filenames: F0001-0708-RG-biasliuyda F0001-0708-CS-akgdlaul F0001-0708-VF-hioulgigl Shell Code To test: ls F00001-0708-*|sed \'s/\\(.\\).\\(.*\\)/mv & \\1\\2/\' To perform: ls F00001-0708-*|sed \'s/\\(.\\).\\(.*\\)/mv & \\1\\2/\' | sh My Question I don\'t understand the sed code. I understand what the substitution command $ sed \'s/something/mv\' means. And I understand regular

How do I rename the extension for a bunch of files?

我与影子孤独终老i 提交于 2019-11-26 05:56:59
问题 In a directory, I have a bunch of *.html files. I\'d like to rename them all to *.txt How can I do that? I use the bash shell. 回答1: For an better solution (with only bash functionality, as opposed to external calls), see one of the other answers. The following would do and does not require the system to have the rename program (although you would most often have this on a system): for file in *.html; do mv "$file" "$(basename "$file" .html).txt" done EDIT: As pointed out in the comments, this

How do I rename files using R?

微笑、不失礼 提交于 2019-11-26 05:29:08
问题 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

Rename a file using Java

六眼飞鱼酱① 提交于 2019-11-26 01:23:39
问题 Can we rename a file say test.txt to test1.txt ? If test1.txt exists will it rename ? How do I rename it to the already existing test1.txt file so the new contents of test.txt are added to it for later use? 回答1: 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 multiple files in a directory in Python [duplicate]

情到浓时终转凉″ 提交于 2019-11-26 00:35:10
问题 This question already has an answer here: How to rename a file using Python 10 answers Rename multiple files in Python 5 answers I\'m trying to rename some files in a directory using Python. Say I have a file called CHEESE_CHEESE_TYPE.*** and want to remove CHEESE_ so my resulting filename would be CHEESE_TYPE I\'m trying to use the os.path.split but it\'s not working properly. I have also considered using string manipulations, but have not been successful with that either. 回答1: Use os.rename

How to rename a file using Python

一笑奈何 提交于 2019-11-26 00:27:57
问题 I want to change a.txt to b.kml . 回答1: Use os.rename: import os os.rename('a.txt', 'b.kml') 回答2: File may be inside a directory, in that case specify the path: import os old_file = os.path.join("directory", "a.txt") new_file = os.path.join("directory", "b.kml") os.rename(old_file, new_file) 回答3: import shutil shutil.move('a.txt', 'b.kml') This will work to rename or move a file. 回答4: As of Python 3.4 one can use the pathlib module to solve this. If you happen to be on an older version, you

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

两盒软妹~` 提交于 2019-11-26 00:06:18
问题 Below is the code I used in order to upload files into a directory. It works fine. My main question is: move_uploaded_file() is the one that saves the uploaded file into the directory, and it is also my guess that move_uploaded_file() is the one that sets the name for it. How could I change the name of my file to a random number? I have tried to do so below: $allowedExts = array(\"gif\", \"jpeg\", \"jpg\", \"png\"); $temp = explode(\".\", $_FILES[\"file\"][\"name\"]); $extension = end($temp);

Changing capitalization of filenames in Git

百般思念 提交于 2019-11-25 23:48:02
问题 I am trying to rename a file to have different capitalization from what it had before: git mv src/collision/b2AABB.js src/collision/B2AABB.js fatal: destination exists, source=src/collision/b2AABB.js, destination=src/collision/B2AABB.js As you can see, git throws a fit over this. I tried renaming using just the plain old mv command as well but git doesn\'t pick up the rename (as a rename or as a new untracked file). How can I change a file to have a different capitalization of the same name?