Drag and drop files onto batch script to add file extension #
Appends ".jpg" to files dragged and dropped onto the saved script's icon:
@echo on
for %%I in (%*) do ren %%I "%%~nI.jpg"
pause
From Microsoft's 'for' documentation:
- Use a single percent sign (%) to carry out the for command at the command prompt. Use double percent signs (%%) to carry out the for command within a batch file.
- You can use wildcard characters (* and ?) to specify a file set.
- %~nI Expands %I to a file name only.
Simple, but perhaps a trifle cavalier, without any sanity checks or filetype awareness. By leveraging exiftool, we can improve on things a bit:
@echo on
for %%I in (%*) do exiftool.exe "-filename<$filename.$filetypeextension" -r -ext . %%I
pause
- only processes files missing an extension
- appends correct file extension to supported file types
- handles files, directories, and subdirectories properly
H/T:
/windows | Nov 20, 2021
Subscribe or visit the archives.