Cryso Agori
V.I.P. Member
I heard ChatGPT could write code so I made it create a script that can find any png and gif files in a folder and convert those into jpg files while ignoring any jpg files already in the folder on Windows Powershell, question is though would it actually work?
Here's the code:
@Ral
Here's the code:
Code:
@echo off
rem Set the folder where the images are stored
set "E:\Images\NEneNe"
rem Loop through all files in the folder
for /f "delims=" %%i in ('dir /b "%folder%\*.gif" "%folder%\*.png"') do (
rem Generate the .jpg file name
set "jpg_file_name=%%~ni.jpg"
rem Check if a .jpg file with the same name already exists in the folder
if not exist "%folder%\%jpg_file_name%" (
rem Convert the image to .jpg and save it in the folder
magick convert "%%i" -colorspace RGB "%folder%\%jpg_file_name%"
rem Check if there are duplicate files
if exist "%folder%\%jpg_file_name%" (
rem Add a -1 to the file name
set /a cnt=1
set "jpg_file_name=%%~ni-%cnt%.jpg"
rem Check if there are still duplicate files
if exist "%folder%\%jpg_file_name%" (
rem Add 1 to the -1 in the file name
set /a cnt=cnt+1
set "jpg_file_name=%%~ni-%cnt%.jpg"
)
rem Convert the image to .jpg and save it in the folder
magick convert "%%i" -colorspace RGB "%folder%\%jpg_file_name%"
)
)
)
@Ral
Last edited: