How to search the file system from Glamorous Toolkit

One question people ask when they start with Glamorous Toolkit, is how to search the file system. Indeed, GT is a Smalltalk system, which is image based, but that does not mean it does not work well with the surrounding file system.

Let's look at two simple entry points.

First, is the global Spotter. If you add any path in there, it will allow you to search through the file system.

The interface also allows you to dive into any of the directories and, once you do, you can search in context.

Another option is to inspect a FileReference AbstractFileReference subclass: #FileReference instanceVariableNames: 'filesystem' classVariableNames: '' package: 'FileSystem-Core-Public' class. For example to inspect the directory of the image do this:

'.' asFileReference
  

Once you do that, you can use the API offered by the FileReference AbstractFileReference subclass: #FileReference instanceVariableNames: 'filesystem' classVariableNames: '' package: 'FileSystem-Core-Public' model to programmatically manipulate the file system. For example, executing this snippet gives me the PNGs from the image directory, which happen to be the screenshots that I took for this very blog post:

'.' asFileReference files select: [ :each | each extension = 'png' ]
  

And one more thing. If you inspect a FileReference AbstractFileReference subclass: #FileReference instanceVariableNames: 'filesystem' classVariableNames: '' package: 'FileSystem-Core-Public' , you also get a contextual Spotter, too.

These are a couple of easy ways to get into the file system. GT does offer an interesting world, but this is not an isolated one. In fact there are quite a number of ways to interact with external worlds and systems, but we leave those for another time. In the meantime, enjoy your file system!