dupext.bat: Duplicate file extension association and rename files

@rem *************************************************************
@rem * MS-DOS batch file to create another file name extension   *
@rem * associated with an application, and rename existing files *
@rem *                                                           *
@rem * dupext.bat v2014.06.12                                    *
@rem * https://malwaremusings.com/scripts/dupext.bat              *
@rem *                                                           *
@rem * usage: dupext.bat [-r] <currentextension> <newextension>  *
@rem * where <currentextension> is the extension to duplicate    *
@rem * and <newextension> is the extension that you want to      *
@rem * create.                                                   *
@rem *************************************************************

@echo off

if "%1" == "-r" goto undoassoc
if "%1" == "" goto usage
if "%2" == "" goto usage
for /f "delims== tokens=2 usebackq" %%a in (`assoc %1`) do assoc %2=%%a
goto rename

:undoassoc
shift
if "%1" == "" goto usage
if "%2" == "" goto usage
assoc %1=

:rename
for /f "delims= usebackq" %%f in (`dir c:\*%1 /s/b`) do ren "%%f" "%%~nf%2"
goto end

:usage
echo "usage: dupext.bat [-r] <currentextension> <newextension>"

:end

One comment on “dupext.bat: Duplicate file extension association and rename files

  1. Pingback: A Document in Sheep’s Clothing | Malware Musings

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s