Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PathDelim VS DirectorySeparatorChar

One can use either

  • System.IOUtils.TPath.DirectorySeparatorChar

http://docwiki.embarcadero.com/Libraries/Seattle/en/System.IOUtils.TPath.DirectorySeparatorChar

OR

  • System.SysUtils.PathDelim

Are there any particular differences, benefits using one over another part from System.IOUtils.TPath is more object oriented interface?

http://docwiki.embarcadero.com/Libraries/Seattle/en/System.SysUtils

like image 276
Gad D Lord Avatar asked Nov 21 '16 08:11

Gad D Lord


People also ask

What is path Directoryseparatorchar?

PathSeparator Field (System.IO) A platform-specific separator character used to separate path strings in environment variables.

How do I use a directory separator in both Linux and Windows in Python?

How do I use "/" (directory separator) in both Linux and Windows? You can define it in the beginning depending on Win/*nix and then work with the variable. In Windows you can use either \ or / as a directory separator.


2 Answers

System.SysUtils.PathDelim was introduced in Delphi 6 / Kylix 1, as a means to enable the writing of platform independent code. The introduction of Kylix, the original Delphi Linux compiler, meant that for the first time Delphi code executed on a *nix platform, as well as its original target of Windows.

System.IOUtils.TPath.DirectorySeparatorChar is part of the IOUtils unit that was introduced more recently to support the current wave of cross-platform tooling, which supports MacOS, iOS, Android and will soon encompass Linux once more.

Where you have a choice between System.SysUtils and System.IOUtils, you are generally expected to use the latter. The System.IOUtils is the cross-platform unit for file system support. That said, you commonly would not use DirectorySeparatorChar directly, but instead would use methods like System.IOUtils.TPath.Combine.

like image 64
David Heffernan Avatar answered Oct 06 '22 00:10

David Heffernan


TPath.DirectorySeparatorChar is defined in System.IOUtils as

{$IFDEF MSWINDOWS}
  FDirectorySeparatorChar := '\';    // DO NOT LOCALIZE;
  // ...
{$ENDIF}
{$IFDEF POSIX}
  FDirectorySeparatorChar := '/';    // DO NOT LOCALIZE;
  // ...
{$ENDIF}

while PathDelim is defined in System.SysUtils as

PathDelim  = {$IFDEF MSWINDOWS} '\'; {$ELSE} '/'; {$ENDIF}

While the conditionals are slightly different, they would only differ if neither or both of MSWINDOWS and POSIX were defined, which is not the case for any platform. And if there would be such a platform in the future, the declarations would surely be fixed accordingly.

TL;DR: There is no difference, you can use either based on your preference.

like image 28
DNR Avatar answered Oct 06 '22 00:10

DNR