Given a folder with files using a design name as part of the file, I want to run svn rename
on matches to the design name. The directory listing showing the files (more than shown here) has this format:
reg_ptst_lib_ptst_rtl_12.ngc
reg_ptst_lib_ptst_rtl_13.ngc
reg_ptst_lib_ptst_rtl_14.ngc
reg_ptst_lib_ptst_rtl_15.ngc
The design name string is ptst. I want to have the script iterate over each file, executing something like this command:
$svn rename reg_ptst_lib_ptst_rtl_12.ngc reg_scst3_lib_scst3_rtl_12.ngc
to change the design name from ptst
to scst3
in subversion.
No need to use ruby or perl, here's an example with find
, awk
and bash
. In the directory containing your files:
find *.ngc | awk '{ str=$0; gsub(/ptst/,"scst3",str); print "svn rename " $0 " " str }' | bash
You can test this first by removing the final | bash
| bash
, which prints out the svn rename command to the terminal.
与 Jon 相同的方法,只是在文件名周围添加引号,以防其他人(如我)想要在文件名包含空格时执行类似的操作。
find *.ngc | awk '{ str=$0; gsub(/ptst/,"scst3",str); print "svn rename \"" $0 "\" \"" str "\""}' | bash
I've put to work the total commander + windows batch files for this task (called tacklebar
project). You can adopt to use any other commander like Far or Double Commander as long as it can calls scripts with arguments for selected files by keyboard shortcut or by toolbar button (currently the installer supports only the Total Commander).
The idea is to select the files/directories you want for rename (does not matter here are they under version control or not) in a commander application and put them into the temporary created text file (Total Commander does it automatically through the %L
variable) and then call the script to rename the paths selected by that list file.
The script just copy the list file into 2 temporary list files and opens, for example, Notepad++ to edit the second list file. After you done renaming the files in the Notepad++ you close the editor and saves changes, after that the script compares the 2 lists and does the renaming.
You can install the script and all other scripts into the Total Commander buttons bar by run _install.bat
from:
https://sf.net/p/tacklebar/tacklebar/HEAD/tree/trunk/
To install 3d party dependencies run _install.bat
from:
https://sf.net/p/tacklebar/external_tools/HEAD/tree/trunk/
Project on github:
https://github.com/andry81/tacklebar https://github.com/andry81/tacklebar/blob/trunk/README.md
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.