首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在windows 7中批处理重命名文件名,以便它们在其末尾有数字顺序?

如何在windows 7中批处理重命名文件名,以便它们在其末尾有数字顺序?
EN

Stack Overflow用户
提问于 2016-04-19 06:25:27
回答 1查看 60关注 0票数 0

我的计算机上有一个php文件的存档文件,我想对它们进行大规模重命名。问题出在这里。下面是这些文件的示例(我有大约42万个这样的文件)。

代码语言:javascript
运行
复制
viewtopic.php_id=4
viewtopic.php_id=5
viewtopic.php_id=6

我希望所有这些文件都在.php中。现在,我知道如何将您转到cmd和cd的文件扩展名重命名为文件,然后重命名为"ren *.* *.php"

但是,我不能这样做,因为所有文件都被命名为VIEWTOPIC。我很想要它,所以它将所有文件重命名为viewtopic1, viewtopic2, viewtopic3,甚至1,2,3,4,5,6,7, etc,.php。然后,我可以通过cmd批量重命名文件。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-19 16:57:04

如果我正确理解,您希望将viewtopic.php_id=x重命名为viewtopicx.php。

代码语言:javascript
运行
复制
:: Simple Batch Script

@echo off
setlocal enabledelayedexpansion

:: Assuming all files exist in same directory tree.  
:: Note - this will take a while.  Probably 30 minutes or more ( just a guess )

:: Also - I am not going to add a check to see if they are php_id files.
:: If you have other file types in this subdirectory,
:: it  will effect them too, and the results will be unpredictable. 
:: Could add a check for it, but easier move *.php_id* into their own subdirectory

for /r %%i in ( * ) do (
    :: set extension to everything after the period
    set "extension=%%~nxi"

    :: remove everything that is not the number
    set "num=!extension:php_id^==!"

    :: rename the original file the file name (%%~ni) + the number + ".php"
    rename %%i %%~ni!num!.php
 )

endlocal
@echo on
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36710168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档