如何更改的很多目录中的文件扩展名? [关闭](How do I change the exten

2019-07-31 03:53发布

假设我有一个目录中的大量文件.txt扩展。

我怎样才能改变所有这些文件的扩展名来.c使用下面的命令行环境:

  • PowerShell的Windows中
  • CMD / DOS在Windows
  • 在bash终端

Answer 1:

在Windows中,转到所需的目录,然后输入:

ren *.txt *.c

在PowerShell中,最好是使用Path.ChangeExtension方法而不是-replace (感谢辖施耐德的说明):

Dir *.txt | rename-item -newname { [io.path]::ChangeExtension($_.name, "c") }

对于Linux(击):

for file in *.txt
do
 mv "$file" "${file%.txt}.c"
done


文章来源: How do I change the extension of many files in a directory? [closed]