One can use either
http://docwiki.embarcadero.com/Libraries/Seattle/en/System.IOUtils.TPath.DirectorySeparatorChar
OR
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
PathSeparator Field (System.IO) A platform-specific separator character used to separate path strings in environment variables.
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.
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With