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

后端 未结 11 1744
南方客
南方客 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:24

    Just for people looking to do this in batch files, this code is working:

    FOR /R "C:\Users\jonathan\Desktop\test" %%f IN (*.jpg) DO REN "%%f" *.png
    

    In this example all files with .jpg extensions in the C:\Users\jonathan\Desktop\test directory are changed to *.png.

    0 讨论(0)
  • 2020-12-07 08:25

    Rename behavior is sometimes 'less than intuitive'; for example...

    ren *.THM *.jpg will rename your THM files to have an extension of .jpg. eg: GEDC003.THM will be GEDC003.jpg

    ren *.THM *b.jpg will rename your THM files to *.THMb.jpg. eg: GEDC004.THM will become GEDC004.THMb.jpg

    ren *.THM *.b.jpg will rename your THM files to *.b.jpg eg: GEDC005.THM will become GEDC005.b.jpg

    0 讨论(0)
  • 2020-12-07 08:32

    What worked for me is this one(cd to the folder first):

    Get-ChildItem -Filter *.old | Rename-Item -NewName {[System.IO.Path]::ChangeExtension($_.Name, ".new")}
    
    0 讨论(0)
  • 2020-12-07 08:34

    You can use ren (as in rename):

    ren *.XXX *.YYY
    

    And of course, switch XXX and YYY for the appropriate extensions. It will change from XXX to YYY. If you want to change all extensions, just use the wildcard again:

    ren *.* *.YYY
    

    One way to make this work recursively is with the FOR command. It can be used with the /R option to recursively apply a command to matching files. For example:

    for /R %x in (*.txt) do ren "%x" *.renamed

    will change all .txt extensions to .renamed recursively, starting in the current directory. %x is the variable that holds the matched file names.

    And, since you have thousands of files, make sure to wait until the cursor starts blinking again indicating that it's done working.

    Note: this works only on cmd. Won't work on Powershell or Bash

    0 讨论(0)
  • 2020-12-07 08:38

    NOTE: not for Windows

    Using ren-1.0 the correct form is:

    "ren *.*" "#2.jpg"
    

    From man ren

    The replacement pattern is another filename with embedded wildcard indexes, each of which consists of the character # followed by a digit from 1 to 9. In the new name of a matching file, the wildcard indexes are replaced by the actual characters that matched the referenced wildcards in the original filename.

    and

    Note that the shell normally expands the wildcards * and ?, which in the case of ren is undesirable. Thus, in most cases it is necessary to enclose the search pattern in quotes.

    0 讨论(0)
  • 2020-12-07 08:40

    thats simple

    ren *.* *.jpg
    

    try this in command prompt

    0 讨论(0)
提交回复
热议问题