如何批量更改子文件夹中的文件扩展名 [英] How to Batch change file extensions within subfolders

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

问题描述

我对Command Prompt还是很陌生,直到1天才开始使用它.

I am very new to Command Prompt, and only started using it as of 1 day ago.

我在某个位置有一个文件夹,例如C:\Users\Administrator\Desktop\Images,在该文件夹中大约有650个子文件夹,每个子文件夹包含约20张图像,是JPG和PNG的混合.我正在寻找CMD的命令行,该命令行将遍历所有子文件夹并将每个.png文件更改为.jpg文件.

I have a folder in a location, for example C:\Users\Administrator\Desktop\Images, and inside that folder there is roughly 650 sub-folders, each containing around 20 images, a mix of JPG's and PNG's. I am looking for a command line for CMD which will go through all sub folders and change each .png file into a .jpg file.

我做了一些研究,发现了一些信息,但是很难遵循和理解,但我仍然无法做到.我想保留文件名,但是将每个文件扩展名从.png更改为.jpg.

I have done a little research and found some information, however it is very hard to follow and understand, and I am still unable to do it. I am wanting to keep the file names, however change each file extension from a .png to a .jpg.

我知道对于1个文件夹,该行类似于ren *.png *.jpg.但是,这不适用于子文件夹.

I understand that for 1 folder, the line is something like ren *.png *.jpg. However, this does not apply changes to subfolders.

推荐答案

如果我正确理解您只想将文件从.png重命名为.jpg,而不转换它们,则可以使用以下批处理代码:

If I understand correctly that you only want to rename the files from .png to .jpg, and not convert them, you could use the following batch code:

@ECHO OFF
PUSHD .
FOR /R %%d IN (.) DO (
    cd "%%d"
    IF EXIST *.png (
       REN *.png *.jpg
    )
)
POPD


更新:我在此处找到了一个更好的解决方案,您可以从命令行直接运行它(在代替%f(如果在批处理文件中使用此代码):


Update: I found a better solution here that you can run right from the command line (use %%f in stead of %f if using this inside a batch file):

FOR /R %f IN (*.png) DO REN "%f" *.jpg

请注意,以上内容将处理当前目录及其子目录.如有必要,可以将任意目录指定为根目录,如下所示:

Note that the above will process the current directory and its subdirectories. If necessary, you can specify an arbitrary directory as the root, like this:

FOR /R "D:\path\to\PNGs" %f IN (*.png) DO REN "%f" *.jpg

这篇关于如何批量更改子文件夹中的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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