Tuesday, January 1, 2008

How many licks does it take....

So let's see....new job, new field....that'll be 4 months of your blogging life, please.

So, at the end of August, I started a new job as a database programmer. A pretty significant step up from my previous position as a report writer not just in database but in automation as well. The shop I moved to is using the Opalis Robot as their automation/scheduling core. A nice product with some kickin' features; however, we are a full version behind and really need to move to get caught up and take advantage of their new version.

Anyway, I'm back and just posted a new category of articles. There are so many dialogs in QM that help you build code and make it much easier, I thought I'd start going over them. I call them 'Code Grinders'. And like a saugsage grinder, you put a bunch of unrealated food products into the top, flip the switch, and it mashes them all together into a nice neat stretched intestinal package. Anyway, the first in on File Enumeration. Ever need to get the list of files in a directory one at a time? Now you can with the Code Grinder:File Enumeration.

Code Grinder 1: File Enumeration

Code Grinders: File Enumeration

So, a buddy of mine was talking to me the other day, and he was needing to get all the names of the files in a certain directory. I told him, easy, just use the 'Code Grinder' File Enumeration that's in the main QM Toolbar under 'Files, Web'. A 'Code Grinder' is a term I came up with to describe dialogs that help you come up with pre-formatted code with just a little bit of info from you. In the same way that you drop some meat, garlic, pepper, salt, sage into the hopper, turn it on and shove it all down the grinder's throat. It's the same here in QM. The grinder is usually a dialog of some kind and the meat and spices are locations or variable names.

Let's take a look at the File Enumeration grinder and see what we can come up with (or is that, ...'see with what we can come up'....no, that's not right either... ummmm....'see what can come up from ourselves'...yeah, that's totally not the right direction....man, I hate that whole, "you can't end a sentence with a preposition" thing...is it any better going on and on like this at the end of a sentence rather than a preposition?). Anyway, so start up that dialog and lets take a look. Click the File Enumeration icon in the 'Files, Web' menu and here's what we've got.

As you can see, it's a pretty straight forward dialog but there are some real useful features. First, you can browse to the folder you are looking for or you can choose 'Special Folders' that will be the same on all computers. It looks like this.

I've circled some of the things that are a real pain when moving from computer to computer, but with 'Special Folders' you can make it quite easy to get to those directories no matter who is logged in (doh, preposition again!). You can set date/time qualifiers as well as 'this folder/subfolders' options as well. Now where this grinder really gets cooking is in the 'Variables' section. If you need just filenames, just put in your variable name in the field. If you need the path, just put in your variable name in that field. If you need the size etc, etc, etc.

Here's the code I get from asking it to list the filenames on the desktop.

Dir d
foreach(d "$Desktop$\*" FE_Dir)
str sPath=d.FileName()
out sPath


Go ahead and dump that into your QM and see what happens. It's that easy. Now 'sPath' has the filename of each file as it loops through the directory. So, now you have a way to get some or all that info automatically (or at least so close to automatically that it makes little difference).