如何使用批处理文件将文件夹中的文件重命名为文件夹名 [英] How to rename files in folders to foldername using batch file

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

问题描述


你们中的任何人都可以帮助我解决很多同名文件的问题,这些文件放在单独的文件夹中.
文件夹以数字命名,但其中的文件名为 index.XXXX - 其中 XXXX 可以是 .jpg 或 .html 或 .pdf.
我想制作一个程序",可以将所有索引"文件重命名为与其所在文件夹相同的名称.
文件夹以 6 位数字命名 - 各不相同.
希望完成此操作后,我想将所有重命名的文件移动到一个新的单个文件夹中,这样我就可以更轻松地查看整个内容.
期待阅读您的答案.


Could any of you help me with a problem I have with a lot of files with the same name, placed in sperate folders.
The folders are named with numbers, but the files inside are named index.XXXX - where XXXX could be .jpg or .html or .pdf.
I would like to make a 'program' that can rename all the 'index' files to the same name as the folder they are placed in.
The folders are named with 6 digit numbers - all different.
After this hopefully has been done, then I would like to move all the renamed files to a new single folder, so it will be easier for me to see the whole content.
Looking forward to reading your answers.

推荐答案

@Echo OFF

FOR /D /R %%# in (*) DO (
    PUSHD "%%#"
    FOR %%@ in ("index*") DO (
        Echo Ren: ".\%%~n#\%%@" "%%~n#%%~x@"
        Ren "%%@" "%%~n#%%~x@"
    )
    POPD
)

Pause&Exit

经过测试的文件夹结构:

C:UsersAdministradorDesktopNueva carpeta (3)123321
C:UsersAdministradorDesktopNueva carpeta (3)123321Index.txt

C:UsersAdministradorDesktopNueva carpeta (3)123456
C:UsersAdministradorDesktopNueva carpeta (3)123456Index.php

C:UsersAdministradorDesktopNueva carpeta (3)12345600000
C:UsersAdministradorDesktopNueva carpeta (3)12345600000Index.css

C:UsersAdministradorDesktopNueva carpeta (3)654321
C:UsersAdministradorDesktopNueva carpeta (3)654321Index.html

C:UsersAdministradorDesktopNueva carpeta (3)654321666999
C:UsersAdministradorDesktopNueva carpeta (3)654321666999Index.jpg

输出:

Ren: ".123321Index.txt"      "123321.txt"
Ren: ".123456Index.php"      "123456.php"
Ren: ".654321Index.html"     "654321.html"
Ren: ".00000Index.css"      "000000.css"
Ren: ".666999Index.jpg"      "666999.jpg"

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

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