Find and rename files with no extension?

后端 未结 3 858
感动是毒
感动是毒 2020-12-14 02:45

So, I\'ve got a bunch of files with no extension. I want to write a windows batch script that will:

  1. Find files with no extension (in a specified folder)
3条回答
  •  伪装坚强ぢ
    2020-12-14 03:41

    Here's another possible command for renaming files with no extensions recursively (assuming that file paths don't contain spaces):

    for /f %i in ('dir *. /b /s /a-d') do rename "%~fi" "%~ni.bla"
    

    Batch version (with doubled %):

    @echo off
    for /f %%i in ('dir *. /b /s /a-d') do (
       rename "%%~fi" "%%~ni.bla"
    )
    


    If file or folder names contain spaces, use this command instead:

    for /f "tokens=* delims= " %i in ('dir *. /b /s /a-d') do rename "%~fi" "%~ni.bla"
    

    Batch version:

    @echo off
    for /f "tokens=* delims= " %%i in ('dir *. /b /s /a-d') do (
       rename "%%~fi" "%%~ni.bla"
    )
    

    Edit: here's even shorter one-liner that supports spaces in paths:

    for /r %i in (*.) do ren "%~fi" "%~ni.bla"
    

    Batch version:

    @for /r %%i in (*.) do ren "%%~fi" "%%~ni.bla"
    

提交回复
热议问题