C++Introduction to C++Language FeatureLearn C++

This Is How To Extract A File Extension in A Windows C++ App

C++ Builder has specific Path Manipulation Routines that allows your C++ app to edit, extract, get and set drive name, directory name, file name, file extensions and so on. These methods are combined in Vcl.FileCtrlSystem.IOUtilsSystem.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.

Let’s see how we can use ExtractFileExt Method to extract a File Extension from the File Path String on Windows.

What does the ExtractFileExt method do?

The ExtractFileExt method (System::SysUtils::ExtractFileName) is a Path Manipulation Routine that returns the extension portions of a file name. We can use ExtractFileExt to obtain the extension of a file name.

The resulting string includes the period character that separates the name and extension parts. This string is empty if the given file name has no extension. Note that this function works for multi-byte character systems (MBCS) ) that means it uses and returns UnicodeString.

Syntax:

Here is a simple example of how to use ExtractFileExt

We can separate drives and folders in a path string with “\\” to define single \ and we can extract file extension as below.

the output file name string will be “.jpg ” including dot character.

Here is the simple full C++ Builder VCL Example,

Here ShowMessage() command will extract and display file name from this string as “.jpg” below,

We can easily use this method with the FileName property of OpenDialog, SaveDialog components or with the string properties of other components. Here is the C++ Builder VCL Example,

This will show the extension of a file that you select by the OpenDialog component.

RAD Studio C++ Builder is a great environment for learning to use C++ and is also powerful enough for all your professional and beginner development needs.
You can download and use the latest C++ Builder Community Edition free.
You can download and try the C++ Builder trial version 30 days.

close

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.

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 was born in 1974, Eskisehir-Turkey, started coding in college and graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. He worked as a research assistant at the same university for more than 10 years. He received his MSc and PhD degrees from the same department at the same university. Since 2012, he is the founder and CEO of Esenja LLC Company. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Learn C++Syntax

What Is A Forced (Default) Copy Assignment Operator In Modern C++

C++C++11C++14C++17C++20Learn C++Syntax

What is Implicitly-declared Copy Assignment Operator In C++?

C++C++11C++14C++17C++20Learn C++Syntax

What is Avoiding Implicit Copy Assignment In C++?

C++C++11C++14C++17C++20Learn C++

Typical Declaration Of A Copy Assignment Operator Without std::swap