Changing all files' extensions in a folder with one command on Windows

后端 未结 11 1839
南方客
南方客 2020-12-07 08:00

How can I use the Windows command line to change the extensions of thousands of files to *****.jpg?

11条回答
  •  一向
    一向 (楼主)
    2020-12-07 08:43

    In my case I had a directory with 800+ files ending with .StoredProcedure.sql (they were scripted with SSMS).

    The solutions posted above didn't work. But I came up with this:

    (Based on answers to batch programming - get relative path of file)

    @echo off
    setlocal enabledelayedexpansion
    for %%f in (*) do (
      set B=%%f
      set B=!B:%CD%\=!
      ren "!B!" "!B:.StoredProcedure=!"
    )
    

    The above script removes the substring .StoredProcedure from the filename. I'm sure it can be adapted to cover more cases, ask for input and be overall more generic.

提交回复
热议问题