Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2010-12

Directory separator character / or \ for file path differences between Linux, Mac and Windows, etc

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Peter E Williams

Hi

This is really 4 questions:

One: Since Windows users the '\' (backslash) character and Linux uses the '/' (foreslash) character in file paths, have I got those the right way around?

Two: What do Macs use for directory path separator character?

Three: Is the a cross-platform function (or procedure) for correcting the file path separator character? I believe that there is one.

e.g. c:\Program Files\Fred's software\data (folder) >>> c:/Program Files/Fred's software/data (folder)

Yes, I am well aware the c:\Program Files\ does usually exist on Linux systems. Actually, if it does exist it will be:

~/Home/.wine/drive_c/ (folder) with Wine installed.

So, it would become ~/Home/.wine/drive_c/Program Files/Fred's software/data/ (folder)

Four: Is the a compiler directive (cross-platform) or other way of detecting the OS of the user's system?

pew

Fond Regards, Peter Eric WILLIAMS
--- Hobart, Tasmania, Australia
--- Phone: +61 (03) 6236-9675
My free websites are: http://pewink.info (&)
http://pewslinuxvault.googlepages.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101229/1bbc9db6/attachment.html>

Reply by email

Žilvinas Ledas
to Peter E Williams

Hi,

Peter E Williams wrote
Three: Is the a cross-platform function (or procedure) for correcting the file path separator character? I believe that there is one.

From
http://www.freepascal.org/docs-html/rtl/system/directoryseparator.html :

const DirectorySeparator = '/';
    Description

DirectorySeparator is the character used by the current operating system to separate directory parts in a pathname. This constant is system dependent, and should not be set.

This constant is part of a set of constants that describe the OS characteristics. These constants should be used instead of hardcoding OS characteristics.

Regards
?ilvinas Ledas

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20101228/65c3deae/attachment.html>

Reply by email

Michael Van Canneyt
to Peter E Williams: Hi This is really 4 questions: One: Since Windows users the '\' (backslash) character and…
Peter E Williams wrote 6 lines
Hi This is really 4 questions: One: Since Windows users the '\' (backslash) character and Linux uses the '/' (foreslash) character in file paths, have I got those the right way around?

You have.

Two: What do Macs use for directory path separator character?

Never hardcode the path separator.

The PathDelim constant in the system unit always contains the correct character.

Always use the IncludeTrailingPathDelimiter or ExcludeTrailingPathDelimiter functions to correct paths. in the best case, you can do something like

Apath := IncludeTrailingPathDelimiter(Apath)+'asubdir'+PathDelim;

I suggest you check out the documentation of the system unit.

Three: Is the a cross-platform function (or procedure) for correcting the file path separator character? I believe that there is one.

There is. SetDirSeparators, in sysutils:

http://www.freepascal.org/docs-html/rtl/sysutils/setdirseparators.html

Show quoted text 8 lines
e.g. c:\Program Files\Fred's software\data (folder) >>> c:/Program Files/Fred's software/data (folder) Yes, I am well aware the c:\Program Files\ does usually exist on Linux systems. Actually, if it does exist it will be: ~/Home/.wine/drive_c/ (folder) with Wine installed. So, it would become ~/Home/.wine/drive_c/Program Files/Fred's software/data/? (folder)

No, it will not become that. It will become c:/program files/.

We do not support a wine emulation under linux.

Never, ever, hardcode paths like C:\program files in your programs. It is not cross-platform.

(and furthermore, it may not always exist on windows, either)

Four: Is the a compiler directive (cross-platform) or other way of detecting the OS of the user's system?

Yes. See:

http://www.freepascal.org/docs-html/prog/progsu38.html#x44-430001.1.38

Basically,

Const
   CurrentOS = {$I %FPCTARGETOS };

Will create a string constant that contains the name of the target you compiled for. (which under normal circumstances equals the system the binary can run on)

Michael.

Reply by email