C++Language FeatureLearn C++

How To Change A File Extension On Windows Using C+

C++ Builder has specific Path Manipulation Routines that allows user to edit, extract, get and set drive name, directory name, file name, file extensions, .. etc, and these methods are combined in Vcl.FileCtrl, System.IOUtils, System.SysUtils libraries. These path manipulation methods are easy to use and easy to get or set file path strings in that operating system. These can be used with other component properties like FileName property of OpenDialog, SaveDialog components.

By learning how to use ChangeFileExt to change the extension of a file from given a file path String on Windows, and how to compile c++ in windows. It will help you to easily build C++ applications.

Use the ChangeFileExt method

ChangeFileExt (System::SysUtils::ChangeFileExt) is a Path Manipulation Routine that creates a new file name string changes the extension of a file name. ChangeFileExt takes the file name passed in FileName and changes the extension of the file name to the extension passed in Extension. Extension specifies the new extension, including the initial dot character.

ChangeFileExt does not rename the actual file, it just creates a new file name string. Note that this function works with multi-byte character sets (MBCS) that means it uses UnicodeStrings.

Here is the ChangeFileExt method’s syntax

A simple example of how to use the ChangeFileExt method in C++

We should use L”” literal for the UnicodeStrings and we can separate drives and folders in a path string with “\\” to define single \ and we can get new file name with extension change from a given file path string as below,

Note that again this ChangeFileExt method does not rename the actual file.

Here is the simple full C++ Builder VCL example

We can use this method with file name strings of any components. For example we can use this with OpenDialog. We can use bool=RenameFile(old, new) Method to rename the selected file with a new extension as below,

In this example, user selects a file by using OpenDialog file browser and it generates a new file name string with a given extension. Then we change its name to this new name with new extension.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.


Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?