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

How to Use GetHomePath Method in C++ Builder

How to Use GetHomePath Method in C++ Builder

C++ Builder has a lot of specific methods in its SysUtils library which are included in the vcl and fmx libraries. Some of these are grouped in Path Manipulation Routines that allows user to edit, extract, get and set drive name, directory name, file name, and file extensions. These methods are combined in Vcl.FileCtrl, System.IOUtils,  System.SysUtils libraries. These all 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. We can also check drives, files, or directories if they exist or not in that given path. And we can get the home directory path of the operating system.

In this post, you’ll get answers to these questions:

  • How do I get Home Path of the System?
  • How we can use GetHomePath Method in C++?
  • How can I easily find the location of Roaming Directory?

By learning how to use GetHomePath method in C++Builder, it will help you to easily build C++ applications with the use of C++ Software.

What is the GetHomePath Method?

GetHomePath Method (System:IOUtils:TPath:GetHomePath) is a Path Manipulation Routine that returns either the home path of the user or the application’s writable scratch directory or storage.

We can call GetHomePath() Method to obtain the user’s home path on the supported target platforms. If the system running your application does not support the requested folder, or if the requested folder does not exist in the system, this function returns an empty string instead.

We should use GetHomePath to store settings per user. For example:

GetHomePath Method points to the following locations on the various platforms:

  • On Windows, it points to the user’s application data folder.
  • On Linux and OS X, it points to the user’s home folder, as defined by the $(HOME) environment variable.
  • On iOS and Android, it points to the device-specific location of the sandbox for the application; the iOS home location is individually defined for each application instance and for each iOS device.
PlatformSample pathPath ID
Windows XPC:\Documents and Settings\<username>\Application DataCSIDL_APPDATA
Windows Vista or laterC:\Users\<username>\AppData\RoamingFOLDERID_RoamingAppData
OS X/Users/<username>NSUserDirectory
iOS Device/private/var/mobile/Containers/Data/Application/<application ID>
iOS Simulator/Users/<username>/Library/Developer/CoreSimulator/Devices/<Device ID>/data/Containers/Data/Application/<application ID>
Android/data/data/<application ID>/filesContext.getFilesDir

What is the Syntax of the GetHomePath method in modern C++?

Here is the Syntax of GetHomePath() Method,

Is there a simple example of using the GetHomePath method in modern C++ ?

GetHomePath() Method returns a UnicodeString, We can get Home Path of the system from a given path string as below,

Is there a full example of how to use the GetHomePath method in modern C++ ?

Here is the full C++ Builder VCL example with the Memo (TMemo) component below,

Note In addition, we can get Temporary Folder Path by using GetTempPath Method. We can also get all Environment Variables by using the GetEnvironmentVariable Method. These methods will be explained in other posts.

If you are looking to Paths and Directories of C++ Builder IDE Options, they are listed here. C++ Builder Compiler Directories and Conditionals are listed here Environment variables are listed here

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.

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++C++17Code SnippetComponentsIteratorsLearn C++

What Are The Boost C++ Libraries?

C++C++17Introduction to C++Learn C++Syntax

Learn Bits and How To Use std::bitset In C++

C++C++17IteratorsLearn C++

How To Use Insert In std::map In Modern C++

C++C++17Introduction to C++IteratorsLearn C++Syntax

What Are The Differences Between Vector And Array In C++?