参考了:[新手入门] shell脚本批量修改文件名 4楼回复 我刚好是在vagrant+ubuntu中进行开发,windows手动修改太麻烦. #!/bin/ksh ls *.htm | while read NAME do echo $NAME page_article${NAME%\.htm}.php done 我是将所有的.htm修改了page_article{}.php文件 运行之后是对的,看到输出的结果是自己想要的,就将echo 替换为 mv即可.
[root@localhost file1]# ls a.htm b.htm c.htm d.htm pl.sh [root@localhost file1]# vi pl.sh #!/bin/bash for f in `ls *.htm` do mv $f `echo ${f/htm/html}` done [root@localhost file1]# sh pl.sh [root@localhost file1]# ls a.html b.html c.html d.html pl.sh
修改文件名,替换中间字符: 例如:ABC_define_EFG.jpg,要把中间的define替换成argument: 用如下脚本即可: for var in *; do mv "$var" `echo "$var" | sed 's/define/argument/g'` ;done 参考材料: https://blog.csdn.net/isuker/article/details/51226179 https://www.jb51.net/article/33
代码这种经常完善的东西,其实是不太适合使用博客来发布的. 以下是一个批量修改照片名称的shell脚本: 事情是这样的,虽然手机拍的照片文件名是按照日期来确定的,但是是这种形式的 IMG_mmddYY_HHiiss.jpg.(字母的含义借助了php的表示法) 脚本的目的是将其修改成这种形式: IMG_YYmmdd_HHiiss.jpg #!/system/bin/sh # #This shell to rename a or some jpg files #some jpg file name a
引言: 有时因为文件版本的更新,后缀名会发生变化,例如Word13的docx到Word16的doc,又例如我们想修改音频文件的后缀.一个一个修改后缀名往往很麻烦,于是我们便可以写一个Python的脚本来批量处理. 代码: import os files = os.listdir(".")#获取当前目录下的文件 for filename in files: portion = os.path.splitext(filename)#将文件名拆成名字和后缀 if portion[1] ==
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication2 { class Program { static void Main(string[] args) { DirectoryInfo theFolder = new Direc