testing the existance of a file...

tim Rowledge tim at rowledge.org
Wed Mar 15 20:11:30 UTC 2006


On 15-Mar-06, at 10:32 AM, Tom Phoenix wrote:

> On 3/15/06, nelson - <nelson1977 at gmail.com> wrote:
>
>>     i can't figure out how to test the existance of a file.
>
> You can ask the directory whether it contains the file, if you send
> #fileExists: to an instance of FileDirectory.
>
>     FileDirectory default fileExists: SmalltalkImage current  
> sourcesName

You can also use
	FileStream isAFileNamed:myfilenameinfull

or if you already know the directory for some reason
	myDirectory isAFileNamed: localfilename

To be honest they're all awful. The fileExists: version actually  
takes your path, splits it to work out which directory to pretend to  
make, then reads *all* the filenames in that directory and then  
scanns the list for a string match with the purported filename.  The  
isAFileNamed: version - aside from having a terrible name - actually  
*opens the file* to try to get a prim fail asa way of deciding the  
file doesn't exist. Good Grief.

We've been pontificating about Doing Something About This for a long  
time. Lack of time available for the people that feel they have  
better ideas (that would be people like me and Cees for example, the  
IO Team)has so far prevented any real progress.

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Klingon Code Warrior:- 2) "My program has just dumped Stova Core!"





More information about the Squeak-dev mailing list