Path: utzoo!utgpu!watserv1!watmath!att!occrsh!uokmax!apple!usc!wuarchive!uunet!mcsun!ukc!strath-cs!cs.glasgow.ac.uk!kww From: kww@cs.glasgow.ac.uk (Dr Kevin Waite) Newsgroups: comp.lang.smalltalk Subject: File-List Goodie Message-ID: <6254@vanuata.cs.glasgow.ac.uk> Date: 10 Sep 90 14:55:08 GMT Organization: Computing Sci, Glasgow Univ, Scotland Lines: 56 The following file-in allows UNIX shell environment variables to be entered as the root of a file name in a FileListView. For example, if I enter: $HOME/bin I get to browse the files in directory /users/iii/kww/bin. This greatly simplifies the browsing of files in important directories. Note that the file-in extends only the UnixFilename class. The code was developed under ObjectWorks-2.5 for Smalltalk. ------------------------------ CUT HERE ------------------------------- 'From Objectworks for Smalltalk-80(tm), Version 2.5 of 29 July 1989 on 10 September 1990 at 3:55:59 pm'! !UnixFilename class methodsFor: 'private'! baseDirectoryForList: list ^list first = (String with: self separator) ifTrue: [self named: list removeFirst] ifFalse: [list first first = $$ ifTrue: [self lookupEnvironment: list] ifFalse: [self currentDirectory]]! lookupEnvironment: list "The first member of this list starts with a dollar sign and therefore could be a dereferencing of a UNIX environment variable. Lookup this variable in the current environment and if it is there use its value as the directory root, otherwise treat the dollar as an ordinary character." | environ key value root | environ := CEnvironment userEnvironment. key := list first copyFrom: 2 to: list first size. value := environ at: key ifAbsent: [^self currentDirectory]. root := self named: value. (root exists and: [root isDirectory]) ifFalse: [ ^self currentDirectory]. "The first part of the given name did correspond to an environment variable with a legal directory name as its value. Use that directory as the base directory and strip off the name from the component list." list removeFirst. ^root! ! --------------------------------------- CUT ------------------------------- -- Email: kww@uk.ac.glasgow.cs (JANET) kww%cs.glasgow.ac.uk@nsfnet-relay.ac.uk (INTERNET) Address: Dept. of Computing Science, University of Glasgow, 17 Lilybank Gardens, Glasgow, United Kingdom. G12 8QQ