testing the existance of a file...

Philippe Marschall philippe.marschall at gmail.com
Wed Mar 15 20:24:22 UTC 2006


2006/3/15, tim Rowledge <tim at rowledge.org>:
>
> 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.

To be honest I found out that the combination of OSProcess and *nix
tools (cp, stat, test, ...) works much better for tasks such as
querying filesize, querying file existence, copying large (15 MB)
files than "the Squeak way".

Cheers
Philippe



More information about the Squeak-dev mailing list