Rename multiple files without parentheses/remove parentheses windows

后端 未结 4 1948
情深已故
情深已故 2021-02-06 03:03

I want to rename a large number of files in increasing order of numbers, starting from anywhere. But when I rename multiple files, it leaves me with parentheses. eg i rename f

相关标签:
4条回答
  • 2021-02-06 03:46

    The problem comes when we need to pass a list of specific parenthesis-containing file names to the script. The following does work for this. In this example, we are changing parentheses to underscores.

    SET fileList=%*
    SET delim1=aaaaaaaaaaaaa
    SET delim2=zzzzzzzzzzzzz
    setlocal enabledelayedexpansion
    SET fileList=!fileList:^(=%delim1%!
    SET fileList=!fileList:^)=%delim2%!
    FOR %%f in (%fileList%) DO (
     SET f1=%%~f
     SET f1=!f1:%delim1%=^(!
     SET f1=!f1:%delim2%=^)!
     SET f2=%%f
     SET f2=!f2:%delim1%=_!
     SET f2=!f2:%delim2%=_!
     FOR %%i IN (!f2!) DO RENAME "!f1!" "%%~nxi"
    )
    
    0 讨论(0)
  • 2021-02-06 03:48

    To remove the brackets you will have to do some string manipulation. I have written a batch file to do this (save as .bat)

    cd C:\folder
    setlocal enabledelayedexpansion
    for %%a in (abc_*.jpeg) do (
    set f=%%a
    set f=!f:^(=!
    set f=!f:^)=!
    ren "%%a" "!f!"
    )
    

    I don't think you can easily do this in one line from the command line though, it may be possible but it won't be pretty. If you can help it use this batch file to remove the brackets.

    0 讨论(0)
  • 2021-02-06 03:48

    In the File Explorer window, select all files, right-click and select rename. Windows will select the starting number as the number supplied between the round brackets so name the file using a number that is 1 digit more than the number of digits required.

    Example: We want the pattern "test_xxx". Using the File Explorer, rename the files to "tes(1000)". Your files will now be named ["tes(1000)", "tes(1001)", "tes(1002)", etc..]. Hold SHIFT and right click in the open area of the File Explorer, then choose "Open command window here". Issue the following command:

    ren *.* test_???.*
    

    This will rename all the files to the proper format ["test_000", "test_001", "test_002", etc..].

    0 讨论(0)
  • 2021-02-06 03:49

    A bit late to the party, but here's a combination of removing parentheses and the empty space automatically created. This code works by having the .bat file inside a folder containing all the files you'd like to modify.

    Copy and paste the code in notepad and save it as sequentialFileNameCleaner.bat

    Your file name must be the same as what is written on the first line sequentialFileNameCleaner.bat. That being said, you can manually update the first line if you want to change the file name.

    :sequentialFileNameCleaner  [/R]  [FolderPath]
    setlocal enabledelayedexpansion
    for %%a in (*.jpg) do (
    set f=%%a
    set f=!f:^(=!
    set f=!f:^)=!
    ren "%%a" "!f!"
    )
    @echo off
    setlocal disableDelayedExpansion
    if /i "%~1"=="/R" (
      set "forOption=%~1 %2"
      set "inPath="
    ) else (
      set "forOption="
      if "%~1" neq "" (set "inPath=%~1\") else set "inPath="
    )
    for %forOption% %%F in ("%inPath%* *") do (
      if /i "%~f0" neq "%%~fF" (
        set "folder=%%~dpF"
        set "file=%%~nxF"
        setlocal enableDelayedExpansion
        echo ren "!folder!!file!" "!file: =!"
        ren "!folder!!file!" "!file: =!"
        endlocal
      )
    
    )
    

    By default, this code will only locate .jpg files. On the 3rd line, changing the (*.jpg) to (*.png) or to (*.mp4) or any extension you'd like will make the code compatible.

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