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

How To Use GetTempPath Method In C++ Builder?

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 Path Manipulation Routines which allow the user to edit, extract, get and set drive name, directory name, file name, file extensions among other things. These methods are combined in Vcl.FileCtrl, System.IOUtilsSystem.SysUtils libraries. These methods are easy to use and make it simple to get or set file path strings in the 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 to see if they exist or not in that given path. We can also get a temp directory path from the operating system to use in our programs as a safe place to store transient or volatile working information which we want to remove when we are finished with it.

In this post, you’ll learn how to obtain a GetTempPath from the operating system, how to use the GetTempPath Method in C++, and how to easily find the location of the Temp Directory. By learning how to use GetTempPath Method in C++ Software. It will help you to easily build C++ applications.

What is the GetTempPath method?

The GetTempPath method (System:IOUtils:TPath:GetTempPath) is a Path Manipulation Routine that returns the path to a directory to store temporary files. This directory is a system-managed location; files saved here may be deleted between application sessions or system restarts. You cannot – and should not – count on it being safe to store anything between launches of your program.

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. GetTempPath points to the following locations on the various platforms:

  • On WindowsOS X, and Linux it points to a system-wide directory.
  • On iOS and Android, it points to a user-specific, application-specific directory.
PlatformSample path
Windows XPC:\Documents and Settings\<User name>\Local Settings\Temp
Windows Vista or laterC:\Users\<User name>\AppData\Local\Temp
OS X/var/folders/<random folder name>
iOS Device/private/var/mobile/Applications/<application ID>/tmp
iOS Simulator/Users/<username>/Library/Application Support/iPhone Simulator/<SDK version>/Applications/<application ID>/tmp
Android/storage/emulated/0/Android/data/<application ID>/files/tmp
Linux/tmp

What is the Syntax of the GetTempPath method in Modern C++?

Here is the Syntax of GetTempPath() Method,

Is there a simple example of using the GetTempPath Method in Modern C++?

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

What about a full Example of how to use the GetTempPath Method in Modern C++?

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

In addition, we can get Home Folder Path by using GetHomePath Method. We can also get all Environment Variables by using the GetEnvironmentVariable Method. These methods will be explained in another posts.

Where can I learn more about path manipulation routines in C and C++?

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.

Click the following dynamic search link to see other examples of path manipulation routines on this blog: https://learncplusplus.org/?s=path

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.


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

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 graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

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

What Is The Queue (std::queue) In Modern C++?

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

What Are The Logical Operation Metafunctions In Modern C++?

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

What Are The Deprecated C++14 Features In C++17?