Kevin A. Foss wrote:
Well... but I think in most cases it would be more appropriate to return false for directories (I hadn't thought about this problem at all) because I'd usually call this functions before trying to open the file for reading or updating.
Yeah, that's true -- I was thinking of using a check for file existance to check and see if the filename was available for creating a file with a unique filename. But your use is more common and good code would check to see if the bind fails anyway.
True, this seems like another use for the functions (and I just saw that I was using it in this way sometimes... ;-). OTOH, there can be other obstacles to creating a file, such as write-protected directories / file systems / volumes, so one would have to check the Bind, and perhaps the Rewrite as well.
So, I think it would be better to return false if the binding fails.
Yes I do too, now that I considered the actual usage of the function. :)
Just for the record, with the built-in Assign function, Exists could be shortened a little:
function Exists(FileName:String):Boolean; var b:BindingType; f:Text; begin Assign(f,FileName); b:=Binding(f); Exists:=b.Bound and b.Existing; Unbind(f) end;
Chief, perhaps it would be worth putting such a function into one of the BP compatibility units. Though BP does not have a built-in Exists, it could be hard for many ex-BP users (like me ;-) to figure out the bindings...