Site icon Learn C++

How To Understand File And Folder Paths In Programming

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

By learning how to understand file and folder paths in programming, it will help you to easily build C++ applications with the use of a C++ IDE.

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:

[crayon-673fc0f2d74e5240282506/]

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;

[crayon-673fc0f2d74ed503717572/]

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,

[crayon-673fc0f2d74ee230441148/]
[crayon-673fc0f2d74ef693680720/]
[crayon-673fc0f2d74f0339293412/]
[crayon-673fc0f2d74f1747322720/]
[crayon-673fc0f2d74f2304916272/]
[crayon-673fc0f2d74f3968594455/]
[crayon-673fc0f2d74f4260111296/]
[crayon-673fc0f2d74f5254112511/]

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.

[crayon-673fc0f2d74f7842608198/]

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.

[crayon-673fc0f2d74f8019600913/]

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:

[crayon-673fc0f2d74f9578123415/]

is equal to:

[crayon-673fc0f2d74fa066281196/]

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

[crayon-673fc0f2d74fb170020527/]

To this Short Path string,

[crayon-673fc0f2d74fc641197261/]

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,

[crayon-673fc0f2d74fd439732291/]

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,

[crayon-673fc0f2d74fe390375299/]

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,

[crayon-673fc0f2d74ff614454680/]

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.

Exit mobile version