Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Sun Nov 19, 2017 1:46 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Jun 16, 2009 9:33 pm 
Offline

Joined: Sun Nov 09, 2008 7:01 pm
Posts: 21
Hi,

I would like to know how to properly check to see if a file exists on the G58's flash drive.

I am using /drv1 for the path. However, no matter what I try I cannot execute the GetFileInfo API without throwing an exception (when the file doesn't exist). I have tried using the "flags" parameter to see if it is zero. I also tried checking the FILEINFO_ISNOT flag but no matter what I do an exception is always thrown unless the file actually exists.

I thought the point of checking these flags was so that you could safely verify if a file exists without actually causing an exception. Anyway, I could always read the directory entries into an array to see if I can find what I'm looking for but this isn't very efficient when I just want to verify the existence of one file and the functionality to do this is supposedly provided in this API. I haven't had problems with any other file operations.

Please provide an example of some code that actually does this without causing an exception.

Thanks!

Brendan


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 7:59 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
I will usually create a function in globals that I use called FileExists. Here is the code.

Code:
func FileExists(fname as string) returns boolean
    dim size, ufs as integer
    dim flags as fileinfo_flags

    check error
        GetFileInfo(fname, size, ufs, flags)
    on error
        _clearException()
        return false
    enderr

    if flags == FILEINFO_ISNOT then
        return false
    endif

    return true
endfunc

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 8:05 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
As a philosophical note:

Qlarity APIs will generally throw exceptions for error conditions rather than return error codes. Nowhere is this more true than the file system APIs.

Whenever you use ANY file system API you should be prepared for it to throw an exception if something goes wrong.

Using GetFileInfo is a perfectly valid way to tell if a file exists, however you just need to deal with the exception case. As Ron pointed out, a simple helper function will wrap up what you are trying to do nicely and return a boolean result which is what you want.

Also, FILEINFO_ISNOT is not really a flag that would be set on any given file. Rather it is the hypothetical value that would be set if a file had none of the specified attributes. However since every file that exists must have either FILEIFNO_ISBINARY, FILEINFO_ISTEXT or FILEINFO_ISDIRECTORY (at a minimum), FILEINFO_ISNOT cannot actually be set.

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Jun 17, 2009 12:14 pm 
Offline

Joined: Sun Nov 09, 2008 7:01 pm
Posts: 21
Thanks guys!

Brendan


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group