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

How To Understand File And Folder Paths In Programming

What is difference between the Dir, Directory and the Folder terms? What is a Drive? What is a Directory? What is a Path? What does Full Path mean? What does Absolute Path mean? What is the Current Path? What is a Short Path? What does Relative Path mean?

What do we mean by “Drive” in programming?

The Drive is the partition of a Disc that is format in the appropriate file format of an operating system . Generally it is shown by a drive letter with columns or a drive name with columns , (i.e.” C:” or “MyDrive:”) For example:

What does Dir, Directory or Folder mean?

The Directory term is the same as the Folder term that defines name of file container group in a file system hierarchy. Dir is the shorten of Directory term generally used in commands and in some path methods. For example;

What do programmers mean when they say “Path”?

Path is a list of directory names with slash-separated and followed by either a directory name or a file name. All these examples below are Path,

In these examples, the last Path example points a file while the others point a folder location.

How do I return the full path of a file?

Full Path is also known as Absolute Path, begins with a drive letter followed by a colon, such as D: For example this is a full path file name.

So full path should start with a drive letter or name.

What do programmers mean by “Current Path” or “Current Directory”?

Current Path is the path that is normally 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.

Current Directory is the Directory where we are in, in this example it is “Debug”. In some cases Current Directory is shown in Full Path as same in Current Path.

What is a “Relative Path”?

Relative Path is the path that is relative to a current directory. 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 at the “D:\Projects\MyProject\Win32\Debug\MyApp.exe” application, Thus Relative Path of this folder:

is equal to:

In C++ Builder, we can use RelativePath Method to get Relative Path of a Path String.

What do programmers mean by “Short Path”?

Short Path term is used to define old short 8.3 form of windows operating system.
ExtractShortPathName method to convert a path file name to the short 8.3 form. In other terms this method converts the file name, FileName, to the short 8.3 form. For example;
It return this Full Path

To this Short Path string,

ExtractShortPathName returns an empty string if the file or directory does not exist and ExtractShortPathName  is only available on Windows. The first parameter, FileName, can be a full path name.

What is a UNC Path?

UNC Path (Uniform (Universal or Unified) Naming Convention Path) is a syntax for accessing folders and files on a network of computers. For example,

C++ Builder has some UNC specific Path Manipulation Routines that allows to use UNC formats like isUNCPath, IsUNCRooted, ExpandUNCFileName Methods.

What is a URL Path?

URL Path (Uniform Resource Locator Path) is used to locate the address of any document or folder on the Internet. For example,

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 Path Manipulation Routines which allow a user to edit, extract, get and set drive name, directory name, file name, file extensions. These methods are combined in Vcl.FileCtrlSystem.IOUtilsSystem.SysUtils libraries. These 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 file name from a given path string.

Is there a C++ Builder Example of using the Path methods?

Here is the full C++ example about the some of the Path Methods that we used in programming,

These above and all other Path Methods are listed in Path Manipulation Routines. You can use them in your applications.

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.

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

de_DE_formalGerman