MathGroup Archive 2007

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

Search the Archive

checking, if a file exists

  • To: mathgroup at
  • Subject: [mg84383] checking, if a file exists
  • From: vejrazka at
  • Date: Thu, 20 Dec 2007 16:50:02 -0500 (EST)


I am new to Mathematica & I have the following problem: I need to
1. check, if a file ("data.dat") with some computationally intensive
results exists
2. if yes, read the file
3. if no, do the calculation

I have written (in Mathematica 6) the following:

  fileName = "...some path ... \\data.dat";
  data = If[FileType[fileName] == File, Import[fileName],

It reads correctly the data if the file exists. But if the file does
not exists, it returns

  If[None == File, Import[fileName], calculate[0]]

Evidently, the problem is, that

  FileType[fileName] == File

returns correctly True if the file exists, but it does not return
False when the file is missing -- it returns only None == File.

How to do that?

Thank you.


  • Prev by Date: Re: Re: LinearSolve[m, b] is not equivalent to LinearSolve
  • Next by Date: using Dsolve for equation: y'' + |y|^2y=ay
  • Previous by thread: Re: ClearAll[f]; f[x_] := x^2; f[y_] :=y^4; (*What is:*) f[2]
  • Next by thread: Re: checking, if a file exists