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

How To Get A Full Path From A String On Windows?

How can I get a full path from a path string in C++ Builder? What is the GetFullPath Method is? What is the Syntax of the GetFullPath Method? Is there an example of how to use the GetFullPath Method?

How to understand paths on Windows?

The full path is also known as the absolute path. It begins with a drive letter followed by a colon, such as D: For example this is a full path file name.

The current path is the path that is normally file path of your application that you are running. We can change the current path on runtime, so every new folder or file operation may occur in that path.

The relative path is the path that is ‘relative’ to a current directory – by that we mean at the same level or a deeper level, but without having the full path expressed. We can use a dot (.) and a double-dot (..) to translate it as the current directory and the parent directory. Here single dot represents the current directory itself and double dots are used for parent directory.

Let’s assume our app is stored as “D:\Projects\MyProject\Win32\Debug\MyApp.exe“. The relative path of the folder:

is equal to:

Are there any other C++ Builder path methods?

C++ Builder has a lot of specific methods in its SysUtils and IOUtils library that are included in VCL and FMX libraries. Some of these are grouped as a Path Manipulation Routines that allow the user 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 are all methods which 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.

We can also check drives, files, or directories if they exist or not in that given path. And we can get file name from a given path string.

Let’s see how we can use GetFullPath Method to get full path from a a path string file name on Windows.

What is the GetFullPath method?

GetFullPath (System::IOUtils::TPath:: GetFullPath) is a Path Manipulation Routine that returns the absolute path for a given path. The full path, also known as the absolute path, begins with a drive letter followed by a colon, such as D: For example this is a full path file name: D:\myfolder\anotherfolder\myapp.exe

GetFullPath returns the full, absolute path for a given relative path. If the given path is absolute, GetFullPath simply returns it; otherwise, GetFullPath uses the current working directory as a root for the given path. The following table lists the parameters expected by this method:

NameMeaning
PathThe relative path

Note: GetFullPath raises an exception if the given path contains invalid characters.

What is the Syntax of the GetFullPath Method ?

Here is the Syntax of GetFullPath() method,

Here the FileName is the file name from which the name and extension parts should be extracted.

Note: GetFileNameWithoutExtension raises an exception if the given file name contains invalid characters.

Here is a simple example of how to use the GetFullPath Method

GetFileNameWithoutExtension Method returns a UnicodeString. With it we can get the file name without an extension from a path string as in example below,

Example:

Assume that you have an application in this path;

If we run this MyApp.exe and if we use GetFullPath Method as in example below,

the output of ShowMessage() will display this result path string as below,

Is there a full example of using the GetFullPath method?

Here is the full example to GetFullPath Method,

If we run this example in this Debug folder;

The output will be as follows:

as you see if we ask for L”.” it returns same full path of current directory that we run the application. You can copy in other folders and run your executable to see changes.

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
C++ComponentsDatabaseIntroduction to C++Language FeatureLearn C++

Get To Know The Powerful C++ Data Bindings In Windows Apps

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

How to Create a New Windows FMX Static Library In C++

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

How To Use C++ front() And back() Methods Of Vectors

C++Generic ProgrammingIntroduction to C++Language FeatureLearn C++

5 Things You Need To Know About Optimization In C++ Builder

jaJapanese