Faulty Logic, or folderitem.Exists is Funky?

I’ve been going around with a customer (Pete), having him run some code with debugging statements in it to track program flow, and I ran into this:

DebugLogThis("fi.exists: "+str(fi.Exists)) 'Pete’s run says False
DebugLogThis("fi.IsWriteable: "+str(fi.IsWriteable)) 'Pete’s run says True

If fi.exists and fi.IsWriteable then
DebugLogThis(“Inside Exists/Writeable”) 'Pete’s run falls through to here (based on looking at the log results). How is that possible?!?

Am I forgetting basic logic, or can fi.Exists change during the course of code execution?

Are .Exists and .IsWriteable reliable? I can’t try writing to the file to find out if it exists and is writable because depending on where this logic is used I may not be able to modify existing data.

You said Petes run says fi.exists is false
Is this correct? Any false statement will make the entire if statement false, so you will never get into the “inside writable/exists”

I believe that a FolderItem may NOT exist but the location still be writable. I don’t think they’re mutually exclusive.

I’ve never actually seen IsWriteable used in an app so this is a new one for me.

Usually I see the error reporting at the point where TextOutputStream or BinaryStream actually fails to write a file.

[quote=225362:@Tim Parnell]You said Petes run says fi.exists is false
Is this correct? Any false statement will make the entire if statement false, so you will never get into the “inside writable/exists”[/quote]

That’s what I thought, and yet it fell through. That’s why I was wondering if it’s status could change in the millisecond between the two statements. Bob might be right, in that the two things might not be mutually exclusive.

I have a feeling the best approach might be to just bracket the code inside Try/Catch and attempt to do what I want, then respond if it fails.

It’s not. Something else is going on.

Unless I am missing something… this makes sense to me

Exists = false… the folder/file does not exist
Writeable = true… CAN you write to the location specified?

If you were asking about a nonexistent path on a CD then both would be false, but on a normal disk drive, I can see where Exists=FALSE and Writable=true… This allows you to be able to decide if you should attempt to create the file with any chance of it succeeding

@John - I see what you mean by fell through now.
@Dave - I follow your logic, but the question/issue here is with the AND statement

John’s if fi.Exists AND fi.IsWriteable then is false, but Xojo is behaving as if it’s true and the DebugLog is showing the line it shouldn’t.

Could .iswriteable be making the file exist, even temporarily?

No.

It works as expected:

[code]Dim fi As FolderItem = SpecialFolder.Desktop.Child(“abc.txt”)
// fi.Exists is False
// fi.IsWriteable is True

If fi.Exists And fi.IsWriteable Then
BREAK
Else
BREAK // … so we end here
End[/code]
There must be something else going on.

[quote=225360:@John McKernon]DebugLogThis("fi.exists: "+str(fi.Exists)) 'Pete’s run says False
DebugLogThis("fi.IsWriteable: "+str(fi.IsWriteable)) 'Pete’s run says True[/quote]

Makes sense if fi does not exist that it is writable. Whenever you want to create a file, you do not expect it to exist, but you do expect it to be writable.

I don’t see any issue here.

His question is another one:

If fi.Exists And fi.IsWriteable Then // he gets here but fi.Exists is false End

[quote=225424:@Eli Ott]His question is another one:

If fi.Exists And fi.IsWriteable Then // he gets here but fi.Exists is false End[/quote]

Unless the file is already there, fi will start to actually exist when he actually writes. That is what ‘Pete’ is seaing, if I understand John’s initial post.

This shows exactly that :

dim f as FolderItem = SpecialFolder.desktop.child(str(ticks*rnd)) system.DebugLog "Exists : "+str(f.exists)+" isWritable : "+str(f.IsWriteable) // Result = Exists : False isWritable : True Dim t As TextOutputStream If f <> Nil Then t = TextOutputStream.Create(f) t.Write(" ") system.DebugLog "Exists : "+str(f.exists)+" isWritable : "+str(f.IsWriteable) // Result = Exists : True isWritable : True t.Close End If

I should point out that I initially used GetTemporaryFolderItem, and in that case, Exists was already True. It seems the file is created upon call to the function.