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

How to Use GetHomePath Method in C++ Builder

How to Use GetHomePath Method in C++ Builder

How can 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? Let’s answer these questions.

C++ Builder has a lot of specific methods in its SysUtils library which is 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.IOUtilsSystem.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 drive, files or directories if they are exist or not in that given path. And we can get home directory path of the operating system.

Let’s see how we can use GetHomePath Method in C++ Builder.

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
Linux/home/<username>

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.

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++ComponentsLanguage FeatureLearn C++

How To Add Shadow Effects To Your C++ Apps

C++ComponentsLanguage FeatureLearn C++

How To Make Controls Have A Glow Effect In C++?

C++Learn C++

What Is The sscanf Function In C++ And How Can I Use It?

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

This Is How To Use Parallel Programming in C++ Builder

jaJapanese