Checking whether a file exists

Ben Abbott bpabbott at mac.com
Sat Mar 8 12:45:46 CST 2008


On Mar 7, 2008, at 10:00 AM, Primoz PETERLIN wrote:

>> 2008/3/7, Ben Abbott <bpabbott at mac.com>:
>> On Mar 7, 2008, at 5:24 AM, Primoz PETERLIN wrote:
>>
>> > Hello everyone,
>> >
>> > Time for another novice question...
>> >
>> > What is the best way to check whether a data file exists (in order
>> > to avoid its accidental overwriting)?
>> >
>> > 1) The function exist() is supposed to return 2 "if the name (after
>> > appending `.m') is a function file in Octave's `path'", but it also
>> > returns 2 if a file is a data file in my search path, e.g., my
>> > current working directory. Is this the intended behaviour and
>> > something I should rely on, or is it just some side effect which  
>> can
>> > vanish in the next release of Octave. In the former case, the
>> > documentation should probably explicitely say so (Matlab
>> > documentation claims that exist(name) returns 2 "If name is an M-
>> > file on your MATLAB® search path. It also returns 2 when name is  
>> the
>> > full pathname to a file or the name of an ordinary file on your
>> > MATLAB search path. ").
>> >
>> > 2) stat() also does the job, but I believe it is not available in
>> > Matlab?
>> >
>> > TIA, Primoz
>>
>>
>> Regarding how exist() functions in Octave, it is intended to be
>> consistent with Matlab. If is it not, or if you'd like to see the
>> documentation changed we're all volunteers, and would like to see  
>> more!
>>
>> You can find the sources here: http://www.gnu.org/software/octave/download.html
>>
>> Instructions for bug reports are here: http://www.gnu.org/software/octave/bugs.html
>>
>> In any event, with regards to your present question; take a look at
>> "dir" and "what"
>>
>> Ben
>>
>>
> Please find attached a patch for octave-3.0.0/src/variables.cc which  
> updates the "help" text.
>
> All the best,
> Primož
>
> <variables.diff>


Thanks Primož.

Note, we've switched mail-list, and I've included a complete changeset.

Ben

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: changeset-variables-exist.txt
Url: https://www.cae.wisc.edu/pipermail/octave-maintainers/attachments/20080308/bad3d0a8/attachment.txt 
-------------- next part --------------







More information about the Octave-maintainers mailing list