www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Windows to Linux Porting

reply Vino <vino.bheeman hotmail.com> writes:
Hi All,

   Request you help on the below code, the below code always state 
the file does not exist even if the file do exist.

Code:

import core.stdc.stdlib: exit;
import std.stdio;
import std.file;
import std.path;

auto osSwitch () {
string ConfigFile;
version (Windows) { ConfigFile = absolutePath(`.\nasconfig.txt`); 
} else version (Linux) { ConfigFile = 
absolutePath(`nasconfig.txt`); }
return ConfigFile;
}
void main () {
auto ConfigFile = osSwitch;
if (!ConfigFile.exists) { writeln("The Configuration File ", 
buildNormalizedPath(ConfigFile), " do to exist, Terminating the 
execution.."); exit(-1);}
else { writeln(ConfigFile); }
}

From,
Vino.B
May 03 2018
parent reply Russel Winder <russel winder.org.uk> writes:
On Fri, 2018-05-04 at 03:30 +0000, Vino via Digitalmars-d-learn wrote:
 Hi All,
=20
    Request you help on the below code, the below code always state=20
 the file does not exist even if the file do exist.
=20
 Code:
=20
 import core.stdc.stdlib: exit;
 import std.stdio;
 import std.file;
 import std.path;
=20
 auto osSwitch () {
 string ConfigFile;
 version (Windows) { ConfigFile =3D absolutePath(`.\nasconfig.txt`);=20
`./nasconfig.txt` perhaps: Linux uses / (as does Windows in fact) for directory separator.= =20
 } else version (Linux) { ConfigFile =3D=20
 absolutePath(`nasconfig.txt`); }
 return ConfigFile;
 }
 void main () {
 auto ConfigFile =3D osSwitch;
 if (!ConfigFile.exists) { writeln("The Configuration File ",=20
 buildNormalizedPath(ConfigFile), " do to exist, Terminating the=20
 execution.."); exit(-1);}
 else { writeln(ConfigFile); }
 }
=20
 From,
 Vino.B
=20
--=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 04 2018
parent reply Vino <vino.bheeman hotmail.com> writes:
On Friday, 4 May 2018 at 07:43:39 UTC, Russel Winder wrote:
 On Fri, 2018-05-04 at 03:30 +0000, Vino via Digitalmars-d-learn 
 wrote:
 [...]
`./nasconfig.txt` perhaps: Linux uses / (as does Windows in fact) for directory separator.
 [...]
Hi Russel, Was able to resolve the issue, the issue was the letter "L" in version (Linux) where is should be version (linux). From, Vino.B
May 04 2018
next sibling parent reply Russel Winder <russel winder.org.uk> writes:
On Fri, 2018-05-04 at 08:47 +0000, Vino via Digitalmars-d-learn wrote:
=20
[=E2=80=A6]
   Was able to resolve the issue, the issue was the letter "L" in=20
 version (Linux) where is should be version (linux).
It would have helped if I had read the code first rather than jumped to a conclusion. :-) --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 04 2018
parent Vino <vino.bheeman hotmail.com> writes:
On Friday, 4 May 2018 at 09:25:28 UTC, Russel Winder wrote:
 On Fri, 2018-05-04 at 08:47 +0000, Vino via Digitalmars-d-learn 
 wrote:
 
[…]
   Was able to resolve the issue, the issue was the letter "L" 
 in
 version (Linux) where is should be version (linux).
It would have helped if I had read the code first rather than jumped to a conclusion. :-)
Hi Russel, No issue, and thank you for your help. From, Vino.B
May 04 2018
prev sibling parent Jonathan M Davis <newsgroup.d jmdavisprog.com> writes:
On Friday, May 04, 2018 10:25:28 Russel Winder via Digitalmars-d-learn 
wrote:
 On Fri, 2018-05-04 at 08:47 +0000, Vino via Digitalmars-d-learn wrote:

 […]

   Was able to resolve the issue, the issue was the letter "L" in

 version (Linux) where is should be version (linux).
It would have helped if I had read the code first rather than jumped to a conclusion. :-)
It happens to us all from time to time, and the casing of the version identifiers can be easy to screw up and easy to miss the mistakes - especially since many of them are based on the names that get used with #ifdef in C/C++ rather than having consistent casing across the various version identifiers. - Jonathan M Davis
May 04 2018