简体   繁体   English

删除奇怪的文件扩展名

[英]remove strange file extensions

I have a folder which contains some files with names as given below 我有一个文件夹,其中包含一些名称如下的文件

0003.4b3d943b8df71af248d12f8b2e7a224a
0004.1874ab60c71f0b31b580f313a3f6e777
0005.1f42bb885de0ef7fc5cd09d34dc2ba54
0006.7a32642f8c22bbeb85d6c3b5f3890a2c
0007.859c901719011d56f8b652ea071c1f8b
.
.
.

I want to rename these files by removing these extensions and need only file name part ie. 我想通过删除这些扩展名来重命名这些文件,并且只需要file name部分即可。

0003
0004
0005
0006
.
.
.
.

How to achieve this using a script? 如何使用脚本实现这一目标?

If all the files in the folder are to be renamed, then all you need is: 如果要重命名文件夹中的所有文件,那么您需要做的是:

ren * *.

See How does the Windows RENAME command interpret wildcards? 请参阅Windows RENAME命令如何解释通配符? for more info. 有关更多信息。

If there are also files in the folder that should not be renamed (files with "normal" extensions), then the following will work: 如果文件夹中还有不应该重命名的文件(带有“普通”扩展名的文件),那么以下方法将起作用:

for /f "eol=; delims=" %%F in ('dir /b /a-d *^|findstr /r "\.................................$"') do @ren "%%F" *.

The \\. \\. matches the dot, and the 32 . 匹配点和32 . match the 32 characters of the extension. 匹配扩展名的32个字符。 The $ anchors the regex match to the end of the line. $将正则表达式匹配项锚定到该行的末尾。

Change each %%F to %F if you want to run the command directly from the command prompt instead of from within a batch script. 如果要直接从命令提示符而不是批处理脚本中运行命令,请将每个%%F更改为%F

The line you are looking for is 您正在寻找的线是

for %%I in (d:\temp\*) DO ren "%%I" "%%~nI"

Where d:\\temp is the location of the files you want to rename. 其中d:\\temp是要重命名的文件的位置。 Note that your batch file has to be in a different folder, else you will rename it as well. 请注意,批处理文件必须位于其他文件夹中,否则也将对其重命名。 Also note that this will rename all the files in the target folder. 另请注意,这将重命名目标文件夹中的所有文件。

try this: 尝试这个:

for /f "delims=" %%i in ('dir /a-d /b') do echo ren "%%~fi" "%%~ni"

look at the output and remove the echo , if it is OK. 查看输出并删除echo ,如果可以的话。

使用这样的东西

for /f "delims=" %%A in ('dir /a:-d /b /o:n') do echo %%~nA

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM