假设我在扩展名为.txt
的目录中有大量文件。
如何使用以下命令行环境将所有这些文件的扩展名更改为.c
:
答案 0 :(得分:82)
在Windows上,转到所需目录,然后键入:
ren *.txt *.c
在PowerShell中,最好使用Path.ChangeExtension
方法而不是-replace
(感谢Ohad Schneider注释):
Dir *.txt | rename-item -newname { [io.path]::ChangeExtension($_.name, "c") }
对于Linux(Bash):
for file in *.txt
do
mv "$file" "${file%.txt}.c"
done