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

How to use SameFileName method on Windows

How can I check if two files are actually the same file? What is SameFileName method in C++? How can I compare file names based on the current Windows locale? Let’s answer these questions.

C++ Builder has a lot of specific methods in its SysUtils library that are included in VCL and FMX libraries. Some of these are grouped as a Path Manipulation Routines that allow a user to edit, extract, get and set drive name, directory name, file name, and file extensions. These methods are combined in the Vcl.FileCtrl, System.IOUtils, System.SysUtils libraries. These methods are easy to use and easy to get or set file path strings in that operating system. The functions can be used with other component properties like FileName property of OpenDialog, SaveDialog components. We can also check drives, files, or directories to see if they exist or not on a given path.

We can also check two file name strings if they are the same on the current locale. Let’s see how we do this.

What is the C++ SameFileName method?

The SameFileName Method (System::SysUtils::SameFileName) is a SysUtils Method that compares file names based on the current locale. SameFileName compares two file names in the same way as AnsiCompareFileName. SameFileName returns True if the file names match, False otherwise. Like AnsiCompareFileName, SameFileName supports locales and MBCS strings; see the AnsiCompareFileName topic for more details.

The following table lists the parameters expected by this method:

NameMeaning
PathThe verified file or directory name

Note: that SameFileName method raises an exception if the given path contains invalid characters.

What is the syntax of the SameFileName method ?

Here is the syntax for the SameFileName Method,

Here is a simple example of using SameFileName Method

Is there a more complete example of how to use the C++ SameFileName method?

Here is the full C++ Builder VCL example,

Note that can use this method with the OpenDialog (TOpenDialog) or SaveDialog (TSaveDialog) components. For example you can check if OpenDialog1->FileName is exactly same as the file name that you want.

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.

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.


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

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
Artificial Intelligence TechC++C++11C++14C++17Learn C++

Why You Should Know ELU Artificial Neural Net Functions

Artificial Intelligence TechC++C++11C++14C++17Learn C++

What You Need To Know About C++ Gaussian Error Linear Units

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

What Is The SoftPlus Activation Function in C++ Neural Nets?

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Make AI Binary/Heaviside Step Functions In C++

en_USEnglish