我的计算机上有一个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批量重命名文件。
如果我理解正确,您需要将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