windows 重命名不带括号的多个文件/删除括号窗口

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13933944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:08:47  来源:igfitidea点击:

Rename multiple files without parentheses/remove parentheses windows

windowscmdrename

提问by neeraj

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 files to abc_.jpeg it results in abc_(1).jpeg, abc_(2).jpeg and so on.

我想从任何地方开始按数字递增的顺序重命名大量文件。但是当我重命名多个文件时,它给我留下了括号。例如,我将文件重命名为 abc_.jpeg,结果是 abc_(1).jpeg、abc_(2).jpeg 等等。

I tried using command prompt to rename

我尝试使用命令提示符重命名

ren abc_(*).jpeg abc_*.jpeg
doesn't work. probably because of brackets

ren abc_(*).jpeg abc_*.jpeg
不起作用。可能是因为括号

ren abc_"("*")".jpeg abc_*.jpeg
renames the files, but results in the same file name as before. I just want to remove the parentheses somehow.

ren abc_"("*")".jpeg abc_*.jpeg
重命名文件,但产生与以前相同的文件名。我只是想以某种方式删除括号。

回答by Bali C

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

要删除括号,您必须进行一些字符串操作。我已经编写了一个批处理文件来执行此操作(另存为.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.

我认为您无法从命令行轻松地在一行中完成此操作,这可能是可能的,但不会很漂亮。如果您可以帮助它使用此批处理文件删除括号。

回答by Subskybox

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.

在文件资源管理器窗口中,选择所有文件,右键单击并选择重命名。Windows 将选择起始编号作为圆括号之间提供的编号,因此使用比所需位数多 1 位的编号命名文件。

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:

示例:我们想要模式“test_xxx”。使用文件资源管理器,将文件重命名为“tes(1000)”。您的文件现在将被命名为 [“tes(1000)”、“tes(1001)”、“tes(1002)”等。]。按住 SHIFT 并右键单击文件资源管理器的打开区域,然后选择“在此处打开命令窗口”。发出以下命令:

ren *.* test_???.*

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

这会将所有文件重命名为正确的格式 ["test_000"、"test_001"、"test_002" 等..]。

回答by SlayerCat

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

聚会有点晚了,但这是删除括号和自动创建的空白空间的组合。此代码的工作原理是将 .bat 文件放在一个包含您要修改的所有文件的文件夹中。

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

将代码复制并粘贴到记事本中并将其另存为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.bat上所写的相同。话虽如此,如果您想更改文件名,您可以手动更新第一行。

: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.

默认情况下,此代码将仅定位 .jpg 文件。在第三行,更改(*.jpg)to(*.png)或 to(*.mp4)或您想要的任何扩展名将使代码兼容。

回答by Michael Weiner

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"
)