Skip to content

Instantly share code, notes, and snippets.

@Infinitusvoid
Created April 9, 2024 17:35
Show Gist options
  • Select an option

  • Save Infinitusvoid/f2ed3da8c7d664a5f6eed30bb46564df to your computer and use it in GitHub Desktop.

Select an option

Save Infinitusvoid/f2ed3da8c7d664a5f6eed30bb46564df to your computer and use it in GitHub Desktop.
Bat : bash script that changes the files extension for all files in a folder to specefied one
@echo off
setlocal enabledelayedexpansion
rem Check if user provided the old extension and new extension
if "%~2"=="" (
echo Usage: %~nx0 old_extension new_extension
exit /b 1
)
set "old_extension=%~1"
set "new_extension=%~2"
rem Change extension for each file in the directory
for %%F in (*.%old_extension%) do (
rem Get the filename without extension
set "filename=%%~nF"
rem Rename the file with the new extension
ren "%%F" "!filename!.%new_extension%"
echo Changed %%F to !filename!.%new_extension%
)
echo All files with extension .%old_extension% are changed to .%new_extension%
change_extension.bat txt csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment