简体   繁体   English

脚本或Java程序来重命名目录中的多个文件

[英]script or a java program to rename multiple files in a directory

I have a Directory with many sub folders. 我有一个包含许多子文件夹的目录。 There are many files in it and I need to rename the files like file_pl.properties to file_en.properties. 其中有许多文件,我需要将file_pl.properties之类的文件重命名为file_en.properties。 Can you suggest a script that iterates through the folders and matches the pattern of _pl for a file and renames the file to _en 您能否建议一个脚本来遍历文件夹并匹配文件的_pl模式并将文件重命名为_en

Use this little gem from the console, it is written using Bash. 从控制台使用这个小宝石,它是使用Bash编写的。

for FILE in `find . -name *_pl.properties`;do mv "${FILE}" "${FILE%_pl.properties}_en.properties";done

This code will iterate over every file in a directory and its child directories. 此代码将遍历目录及其子目录中的每个文件。 Every time it finds a file that ends with '_pl.properties', it will then move (renames) the postfix to _en.properties. 每次找到以“ _pl.properties”结尾的文件时,它都会将后缀移动(重命名)为_en.properties。

This bash script was tested under Ubuntu and Mac OSX. 此bash脚本已在Ubuntu和Mac OSX下进行了测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM