checking, if a file exists
- To: mathgroup at smc.vnet.net
- Subject: [mg84383] checking, if a file exists
- From: vejrazka at icpf.cas.cz
- Date: Thu, 20 Dec 2007 16:50:02 -0500 (EST)
Hello, 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], calculate[0]] 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. Jiri