directorysmalltalkgnu-smalltalk

Object: Directory error: did not understand #name


Following simple code to list files in a directory is from here:

(Directory name: '.')  
allFilesMatching: '*.st' 
do: [ :f | (f name) displayNl ]

However, it is not working and giving following error:

$ gst mysrc.st
Object: Directory error: did not understand #name:
MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
Directory class(Object)>>doesNotUnderstand: #name: (SysExcept.st:1448)
UndefinedObject>>executeStatements (firstline.st:1)

I am working on GNU Smalltalk version 3.2.5 on Debian Stable Linux.

Where is the problem and how can it be solved?


Solution

  • I don't know who has written it on the rosettacode, but the #name: selector is incorrect (does not exist in the Directory class). If you check the Directory class you won't find such selector there. Instead you will find a #working: selector. The selector has a description:

    working: dirName
        Change the current working directory to dirName.
    

    Your code will then look like this:

    (Directory working: '.') allFilesMatching: '*.st' do: [ :f | 
       (f name) displayNl
    ]