如何重命名的扩展名的批处理文件? [英] How do I rename the extension for a batch of files?

查看:135
本文介绍了如何重命名的扩展名的批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个目录,我有一大堆的 *。HTML 文件。

In a directory, I have a bunch of *.html files.

我想他们都重命名为 *。txt的

我用的是bash shell的。

I use the bash shell.

推荐答案

有关一个更好的解决办法(只有bash的功能,而不是外部调用),看的其他答案之一。

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

编辑:的正如评论指出,这不适合带空格的文件名没有适当的引用(现在上面添加)工作。当你知道没有在文件名中的空间,这将工作,但只要你写的东西,可能会在以后的时间被重用,不要跳过适当引用自己的文件纯属工作。

As pointed out in the comments, this does not work for filenames with spaces in them without proper quoting (now added above). When working purely on your own files that you know do not have spaces in the filenames this will work but whenever you write something that may be reused at a later time, do not skip proper quoting.

这篇关于如何重命名的扩展名的批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆