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”
[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.
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
[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.
[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.