Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Wed Nov 22, 2017 5:46 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 02, 2011 10:08 am 
Offline
User avatar

Joined: Mon Apr 10, 2006 6:44 pm
Posts: 12
Location: Costa Mesa, CA
I've found a number of posts here concerning methods to determine if a file exists in the filesystem. They go most of the way to answering my question, but I have a little twist (there's ALWAYS a twist, isn't there?):

In my G56 application, I load about 9 CSV files into the filesystem which are then parsed and used during initialization. I now have a requirement to optionally add a 10th file and use its data in a similar manner, if the file is present. The catch is that this new file can have a different filename each time it's included (it's customer-specific customization data).

The examples I've found all seem to rely on knowing the filename in advance when checking for file existence. While I can't guarantee the entire filename, I can guarantee a fixed prefix to the name. That is, the filename will always be something like "PNum_xxxx.csv", where the "xxxx" is a variable set of characters. I'm guessing that I'll have to iterate through the directory contents to look for this pattern, but any examples would be appreciated.

_________________
--Mike


Top
 Profile  
 
PostPosted: Wed Feb 02, 2011 10:14 am 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Here is an example of iterating over a directory. I just came up with this off the top of my head, so there could be some mistakes.

Code:
func f()
    dim name as string

    ChangeCurDir("/testDir")

    name = GetDirEntry(0) 'Get first directory entry
    while name <> "" do
        name = lowercase(name)
        if right(name, 4) == ".csv" then
            'Check here if this is the file we want
        endif
        name = GetDirEntry(-1) 'Get next entry
    next
endfunc

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Wed Feb 02, 2011 12:19 pm 
Offline
User avatar

Joined: Mon Apr 10, 2006 6:44 pm
Posts: 12
Location: Costa Mesa, CA
Thanks, Jeremy, I'm coding that and testing it now. When I do a GetDirEntry(), will the returned string include the pathname, or just the filename? For example, with files at the root, will the function return "/filename.csv" or just "filename.csv"?

Also, that should be "loop" at the end of the "while" block in your example instead of "next", right?

_________________
--Mike


Top
 Profile  
 
PostPosted: Wed Feb 02, 2011 12:25 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
Yeah, that should be a loop -- I was just winging that example.

All paths with GetDirEntry are relative to the current directory. In practice I use absolute paths throughout my Qlarity code. GetDirEntry is about the only place that I use relative paths (because you have to).

_________________
Jeremy
http://www.beijerinc.com


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