Odd GetFileFolderInfo behavior
I frequently use GetFileFolderInfo to make sure a path is both valid and points to a file rather than a folder. Originally the function simply checked whether V_IsFile is equal to 1. However, if I run GetFileFolderInfo twice, the first time with a valid file path and the second time with an invalid path, V_IsFile does not update and retains the value of 1 from the first time. The fix on my end is relatively simple: In addition to making sure V_IsFIle is 1, I also make sure V_Flag is 0. However, this behavior seems rather undesirable, since the results of the operation will not be the same every time and instead depend on whether or not GetFileFolderInfo was called previously in the function. Setting V_IsFile and V_IsFolder to 0 if V_Flag is non-0 seems like the preferred behavior.
Is there a reason why V_IsFile and V_IsFolder only update when the path is valid, and if this behavior can't be changed, can it at least be documented in the help?
GetFileFolderInfo/Q/Z "Path to invalid file/folder"
Print V_Flag //Will be nonzero
Print V_IsFolder //Will be 0
GetFileFolderInfo/Q/Z "Path to valid file/folder"
Print V_Flag //Will be 0
Print V_IsFolder //Will be 1
END
FUNCTION Valid_Folder_First()
GetFileFolderInfo/Q/Z "Path to valid file/folder"
Print V_Flag //Will be 0
Print V_IsFolder //Will be 1
GetFileFolderInfo/Q/Z "Path to invalid file/folder"
Print V_Flag //Will be nonzero
Print V_IsFolder //Will be 1!! Not expected!
END
I suspect that GetFileFolderInfo does not update V_IsFolder in this case. This sounds like a bug to me and should be reported to WM support.
I would create wrapper functions a la https://github.com/AllenInstitute/MIES/blob/7696a3a52de3e7cc7f509df3479… to ease the use of `GetFileFolderInfo` in any case though.
February 9, 2020 at 04:45 pm - Permalink
Hm. A name that is non-existent isn't a file and isn't a folder.
February 11, 2020 at 01:07 pm - Permalink
Igor 8.05 and later will properly reset all the output variables and strings even if the file or folder is not found.
February 11, 2020 at 05:08 pm - Permalink
Great, thanks!
February 12, 2020 at 08:02 am - Permalink