Re: If and openwrite and openappend
- To: mathgroup at smc.vnet.net
- Subject: [mg49193] Re: If and openwrite and openappend
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 7 Jul 2004 01:42:26 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <ccdm2a$sf6$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
nix[x_String, y_String] := Module[{t},
t = {x, y};
If[FileType["dBaspap"] === None,
stmp = OpenWrite["dBaspap"],
stmp = OpenAppend["dBaspap"]];
Write[stmp, t];
Close[stmp]
]
For two symbols without a value
a==b is left unevaluated and gives not True or False,
you need SameQ[]
Regards
Jens
"camartin at snet.net" 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