Sign in Join

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

Mailing lists / fpc-pascal / 2005-07

Re: Paths on different OS's

9 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

Michael Van Canneyt
to L505: Could someone tell me the way forward and backward slashes are handled easily? For…
L505 wrote 7 lines
Could someone tell me the way forward and backward slashes are handled easily? For example this is sort of code bloat below Is there some way around this: {$ifdef unix} path:= ExtractFileDir(paramstr(0)+'/somepath/directory/etc/';
Path:=ExtractFileDir(ParamStr(0)+PathDelim+'SomePath'+PatHDelim+'Directory'+PatHDelim+'etc'+PathDelim;

Is cross platform, or

Path:=ExtractFileDir(SetDirSeparators(paramstr(0)+'\somepath\directory\etc\'));

DoDirSeparators is the same as SetDirSeparators, but operates on a var param.

All these functions are in sysutils, and are documented.

Michael.

Michael Van Canneyt
to L505: | I always do something like this: | | {$ifdef UNIX} | const dirsep = '/'; | {$else} |…
L505 wrote 19 lines
| I always do something like this: | | {$ifdef UNIX} | const dirsep = '/'; | {$else} | const dirsep = '\'; | {$endif} | | path := ExtractFileDir(paramstr(0) + dirsep + 'somepath' + dirsep + | 'directory' + 'etc' + dirsep); | | Id imagine that one of fpc's units already has something very similar to | this. That's a good tip.. Yeah, so if anyone knows.. is there something like this already in a unit somewhere that should be used as a standard directory separator variable?

PathDelim (in sysutils, delphi compatible)
or
DirectorySeparator (FPC native, defined in system)

Michael.

Show quoted text 8 lines
_______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Michael Preslar
to L505: Could someone tell me the way forward and backward slashes are handled easily? For…

I always do something like this:

{$ifdef UNIX}
const dirsep = '/';
{$else}
const dirsep = '\';
{$endif}
path := ExtractFileDir(paramstr(0) + dirsep + 'somepath' + dirsep +
'directory' + 'etc' + dirsep);

Id imagine that one of fpc's units already has something very similar to this.

Earlier message 25 lines
-----Original Message----- From: On Behalf Of L505 Sent: Thursday, July 14, 2005 1:33 PM To: FPC-Pascal users discussions Subject: [fpc-pascal] Paths on different OS's Could someone tell me the way forward and backward slashes are handled easily? For example this is sort of code bloat below Is there some way around this: {$ifdef unix} path:= ExtractFileDir(paramstr(0)+'/somepath/directory/etc/'; {$ifdef win32} path:= ExtractFileDir(paramstr(0)+'\somepath\directory\etc\'; Thank you.
A.J. Venter
to L505: | I always do something like this: | | {$ifdef UNIX} | const dirsep = '/'; | {$else} |…
Show quoted text 5 lines
That's a good tip.. Yeah, so if anyone knows.. is there something like this already in a unit somewhere that should be used as a standard directory separator variable?

Not sure which unit it's from, sysutils I think, but there is a predeclared constant PATHDELIM which auto-adjusts for the OS you're compiling to.

A.J.

A.J. Venter Lead Developer - Direq International +27 82 726 5103 Fax: 0866542898 http://direq.org http://silentcoder.co.za
L505

Could someone tell me the way forward and backward slashes are handled easily?

For example this is sort of code bloat below
Is there some way around this:

{$ifdef unix}
path:= ExtractFileDir(paramstr(0)+'/somepath/directory/etc/';
{$ifdef win32}
path:= ExtractFileDir(paramstr(0)+'\somepath\directory\etc\';

Thank you.

L505
to Michael Preslar: I always do something like this: {$ifdef UNIX} const dirsep = '/'; {$else} const dirsep =…

| I always do something like this:
|
| {$ifdef UNIX}
| const dirsep = '/';
| {$else}
| const dirsep = '\';
| {$endif}
|
| path := ExtractFileDir(paramstr(0) + dirsep + 'somepath' + dirsep + | 'directory' + 'etc' + dirsep);
|
| Id imagine that one of fpc's units already has something very similar to | this.

That's a good tip.. Yeah, so if anyone knows.. is there something like this already in a unit somewhere that should be used as a standard directory separator variable?

L505
to Michael Van Canneyt: Path:=ExtractFileDir(ParamStr(0)+PathDelim+'SomePath'+PatHDelim+'Directory'+PatHDelim+'etc…

|
Path:=ExtractFileDir(ParamStr(0)+PathDelim+'SomePath'+PatHDelim+'Directory'+PatH Delim+'etc'+PathDelim;
|
| Is cross platform, or
|
|
Path:=ExtractFileDir(SetDirSeparators(paramstr(0)+'\somepath\directory\etc\')); |
| DoDirSeparators is the same as SetDirSeparators, but operates on a var param. |
| All these functions are in sysutils, and are documented. |

Thanks, I remember coming across them in the docs somewhere before! The second example you mentioned might be easier on the eyes in the source code. A little extra CPU, but oh well.