How to rename files in folders to foldername using batch file

后端 未结 4 1361
别跟我提以往
别跟我提以往 2020-12-15 01:55


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

4条回答
  •  星月不相逢
    2020-12-15 02:32

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

    Tested folder structure:

    C:\Users\Administrador\Desktop\Nueva carpeta (3)\123321
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\123321\Index.txt
    
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\123456
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\123456\Index.php
    
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\123456\000000
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\123456\000000\Index.css
    
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\654321
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\654321\Index.html
    
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\654321\666999
    C:\Users\Administrador\Desktop\Nueva carpeta (3)\654321\666999\Index.jpg
    

    Output:

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

提交回复
热议问题