我的计算机上有一个php文件的存档文件,我想对它们进行大规模重命名。问题出在这里。下面是这些文件的示例(我有大约42万个这样的文件)。
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批量重命名文件。
发布于 2016-04-19 16:57:04
如果我正确理解,您希望将viewtopic.php_id=x
重命名为viewtopicx
.php。
:: 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
https://stackoverflow.com/questions/36710168
复制相似问题