Find and rename files with no extension?

后端 未结 3 863
感动是毒
感动是毒 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:24

    For windows batch files, this will rename only files with no extension to the .bla extension:

    rename *. *.bla
    

    Notice the first argument is a star and a dot: *.

    The second argument is: *.bla

    The start dot (*.) combination represents files with no extensions in this context.

    Before:

    06/21/2009  11:57 PM                 6 test
    06/21/2009  11:57 PM                 7 test.exe
    06/21/2009  11:57 PM                 7 test2
    

    After:

    06/21/2009  11:57 PM                 6 test.bla
    06/21/2009  11:57 PM                 7 test.exe
    06/21/2009  11:57 PM                 7 test2.bla
    

    Additional note: The opposite commandline would rename all .bla files into no extension files.

    EDIT:

    For recursively renaming files with no extension across subdirectories (doesn't support spaces in paths):

    @echo off
    FOR /F %%i in ('dir /b/s/A-d') DO (
      if "%%~xi" == "" rename "%%~fi" "%%~ni.bla"
    )
    

    EDIT2:

    For recursively renaming files with no extension across subdirectories (supports spaces in path):

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

提交回复
热议问题