file-rename

Batch rename files

一世执手 提交于 2019-11-27 20:23:57
问题 I want to batch re-name a number of files in a directory so that the preceding number and hypen are stripped from the file name. Old file name: 2904495-XXX_01_xxxx_20130730235001_00000000.NEW New file name: XXX_01_xxxx_20130730235001_00000000.NEW How can I do this with a linux command? 回答1: This should make it: rename 's/^[0-9]*-//;' * It gets from the beginning the block [0-9] (that is, numbers) many times, then the hyphen - and deletes it from the file name. If rename is not in your machine

Getting Git to follow renamed and edited files

百般思念 提交于 2019-11-27 16:01:28
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 files. Is Git clever enough to work this out on its own? It seems hard to believe. And if so, how can I

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

十年热恋 提交于 2019-11-27 10:27:14
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year . 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

Rename multiple files in Python

蓝咒 提交于 2019-11-27 08:06:46
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(???)) 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.split('_') #[abc, 2000.jpg] new_name = 'year_{}'.format(parts[1]) #year_2000.jpg os.rename(file, new_name)

Rename a running executable (exe) file [duplicate]

陌路散爱 提交于 2019-11-27 06:03:37
问题 This question already has answers here : Why does rename a loaded .net assembly work? (3 answers) Closed last year . We are trying to push updates to multiple servers at once and my manager has found that it is possible to rename running .exe file. Using that knowledge he wants to rename a running exe and copy over a new version of said exe such that anyone running their in memory copy of foo.exe are fine and anybody who opens a shortcut pointing to foo.exe will get a new copy with updates

mac os x terminal batch rename

萝らか妹 提交于 2019-11-27 05:52:59
i have a folder with a series of files named: prefix_1234_567.png prefix_abcd_efg.png i'd like to batch remove one underscore and the middle content so the output would be prefix_567.png prefix_efg.png thanks relevant but not completely explanatory: how can I batch rename files using the Terminal? Regex to batch rename files in OS X Terminal In your specific case you can use the following bash command ( bash is the default shell on macOS): for f in *.png; do echo mv "$f" "${f/_*_/_}"; done Note: If there's a chance that your filenames start with - , place -- before them[1]: mv -- "$f" "${f/_*_

Is rename() atomic?

与世无争的帅哥 提交于 2019-11-27 04:28:10
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. Basically is rename() is an atomic system call? Thanks Yes and no. rename() is atomic assuming the OS

Enforce unique upload file names using django?

孤者浪人 提交于 2019-11-27 03:23:13
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? Nathan 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

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

你离开我真会死。 提交于 2019-11-27 02:53:19
问题 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

How to stage a rename without subsequent edits in git?

一个人想着一个人 提交于 2019-11-27 02:14:49
问题 I have a file that I've renamed and then edited. I would like to tell Git to stage the rename, but not the content modifications. That is, I wish to stage the deletion of the old file name, and the addition of the old file contents with the new file name. So I have this: Changes not staged for commit: deleted: old-name.txt Untracked files: new-name.txt but want either this: Changes to be committed: new file: new-name.txt deleted: old-name.txt Changes not staged for commit: modified: new-name