MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: If and openwrite and openappend

  • To: mathgroup at
  • Subject: [mg49193] Re: If and openwrite and openappend
  • From: Jens-Peer Kuska <kuska at>
  • Date: Wed, 7 Jul 2004 01:42:26 -0400 (EDT)
  • Organization: Universitaet Leipzig
  • References: <ccdm2a$sf6$>
  • Reply-to: kuska at
  • Sender: owner-wri-mathgroup at


nix[x_String, y_String] := Module[{t},
    t = {x, y};
If[FileType["dBaspap"] === None, 
   stmp = OpenWrite["dBaspap"], 
   stmp = OpenAppend["dBaspap"]];
   Write[stmp, t];

For two symbols without a value
a==b is left unevaluated and gives not True or False,
you need SameQ[]


"camartin at" wrote:
> MathGroup,
> Obviously I don't understand something about using If, etc.
> I'm trying to write a piece of code to store strings in a file.  A very
> simplified example follows:
> Clear[t]
> Clear[nix]
> nix[x_String, y_String] :=
>   t = {x, y}
> If[FileType["c:\\Mathematica\\dBaspap"] == None,
>     stmp = OpenWrite["c:\\Mathematica\\dBaspap"],
>   stmp = OpenAppend["c:\\Mathematica\\dBaspap"]]
> Write[stmp, t]
> Close[stmp]
> The function seems to work as I want if the file doesn't exist.  If it
> exists the code doesn't work.
> If I  the OpenAppend from the If statement things work fine.  But a
> subsequent use of nix fails because it refuses to open a stream.
> I've read Wolfram fairly carefully I thought but I'm missing something
> obvious.
> Thanks for any help.
> Cliff Martin

  • Prev by Date: Re: If and openwrite and openappend
  • Next by Date: Re: Appending 2D arrays to files?
  • Previous by thread: Re: If and openwrite and openappend
  • Next by thread: RE: If and openwrite and openappend