

If "!NewExtension:~0,1" = "." set "NewExtension=!NewExtension:~1!" Rem If the new file extension starts with a point, remove the point. If "!TargetFolder:~-1!" = "\" set "TargetFolder=!TargetFolder:~0,-1!"Įcho Please specify the new file extension.Įcho Default file extension is: %NewExtension% Rem If the target folder path ends with a backslash, remove the backslash. Rem Replace all / by \ in target folder path. Set "TargetFolder=%USERPROFILE%\Documents" Rem Is the batch file called without an argument/parameter?Įcho Call %~nx0 always with name of a file with full path.Įcho %~nx0 "C:\Path to folder\with file to\move with new extension.txt"Įcho specifies a directory and not a file.

It can be still enhanced with more error checks. However, here is a batch script which you might use and contains already some extensions to detect some possible mistakes which can always occur when a user has to enter a path and a file extension manually.
