@rem================================================================================== @rem========== Rename File Extensions for Windows =========== @rem========== Copyright (C) 2007 Adarsh Ramamurthy =========== @rem========== www.adarshr.com =========== @rem================================================================================== @rem @rem Usage: @rem renamex [OPTIONS] EXTENSION1 EXTENSION2 @rem @rem Renames a set of files ending with EXTENSION1 to end with EXTENSION2. @rem If none of the following options are provided, renaming is done in the @rem current directory for all files with EXTENSION1. @rem @rem Where [OPTIONS] include: @rem -v --verbose @rem print details of files being renamed @rem -d [directory] --directory [full path] @rem rename files specified in the directory @rem -f [filter] --filter [wildcard] @rem use wildcard characters (* and ?) for renaming files @rem -h --help @rem show this help @rem @rem Examples: @rem renamex htm html @rem (rename all .htm files to .html in the current directory) @rem renamex -v log txt @rem (show verbose output while renaming all .log files to .txt) @rem renamex -v -d "D:\images" JPG jpeg @rem (rename all .JPG files located in D:\images to .jpeg) @rem renamex -v -d "D:\movies" -f *2007* MPG mpeg @rem (rename all .MPG files with 2007 in their names, in D:\movies to .mpeg) @rem @rem @rem================================================================================== @rem================================================================================== @echo off @setlocal set verbose="false" set directory="." set filter="*" :params if /I "%1" == "-v" goto :verbose if /I "%1" == "-d" goto :directory if /I "%1" == "-f" goto :filter if /I "%1" == "-h" goto :help if "%2" == "" goto :help set ext1=%1 set ext2=%2 set count=0 for /R %directory% %%a in (%filter%.%ext1%) do ( ren "%%a" "%%~na.%ext2%" if %verbose% == "true" ( echo Renaming "%%a" to "%%~na.%ext2%" ) set /A count=count+1 ) echo. echo Successfully renamed %count% files goto :eof :verbose set verbose="true" shift goto :params :directory shift set directory="%1" shift goto :params :filter shift set filter="%1" shift goto :params :help echo Usage: echo renamex [OPTIONS] EXTENSION1 EXTENSION2 echo. echo Renames a set of files ending with EXTENSION1 to end with EXTENSION2. echo If none of the following options are provided, renaming is done in the echo current directory for all files with EXTENSION1. echo. echo Where [OPTIONS] include: echo -v --verbose echo print details of files being renamed echo -d [directory] --directory [full path] echo rename files specified in the directory echo -f [filter] --filter [wildcard] echo use wildcard characters (* and ?) for renaming files echo -h --help echo show this help echo. echo Examples: echo renamex htm html echo (rename all .htm files to .html in the current directory) echo renamex -v log txt echo (show verbose output while renaming all .log files to .txt) echo renamex -v -d "D:\images" JPG jpeg echo (rename all .JPG files located in D:\images to .jpeg) echo renamex -v -d "D:\movies" -f *2007* MPG mpeg echo (rename all .MPG files with 2007 in their names, in D:\movies to .mpeg) echo. @endlocal