2016-04-19 6 views
0

私は自分のコンピュータ上にphpファイルのアーカイブを持っています。それらを一括して名前を変更したいと思います。ここに問題がある。ここにファイルのサンプルがあります(私は約42万種類あります)。Windows 7のファイル名を一括して名前を変更すると、ファイル名の末尾に数字の順序が付けられます。

viewtopic.php_id=4 
viewtopic.php_id=5 
viewtopic.php_id=6 

これらのファイルはすべて.phpにします。さて、私はあなたがcmdに行くファイル拡張子をファイル名に変更して、"ren *.* *.php"に行くことを知っています。

ただし、すべてのファイルの名前がVIEWTOPICであるため、これを行うことはできません。私はそれを持っているので、すべてのファイルの名前を viewtopic1, viewtopic2, viewtopic3、または地獄1,2,3,4,5,6,7, etc、.phpに変更します。その後、cmdを使ってファイルの名前を一括して変更することができます。

+0

SOのトピックではありませんが、Windowsでは、過去にacdseeを使用してイメージ名を変更しました。しかし、情報のソースに応じて、それらをもう一度読んで、情報を解析し、データベースに格納する方が良い選択かもしれません... – jeroen

+0

別の '.php'を追加すると、' viewtopic.php_id = 4.php'? 'ren * * .php *" "* .php * .php" ' – Stephan

+0

@Stephan、それは私が必要としていたものです。私はそれを考えていないので、とても愚かではないと感じます。どうもありがとうございます。 –

答えて

0

私が正しく理解している場合、viewtopic.php_id = xの名前をviewtopic x .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 
+0

ファイルタイプをチェックしたり、予期しない結果になるリスクを避けるため、ファイルマスクを正しく選択する必要はありません: 'for/r %% i in( * .php_id * .php)do( '.. – Stephan

関連する問題