testing the existance of a file...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

testing the existance of a file...

nelson -
Hi all,
   i can't figure out how to test the existance of a file. The book i'm reading says to use

aFileName exists

but if i create a filename from a string sending the message

aString asFilename

Squeak says that it doesn't understand the exists message..

any help?


thanks,
  nelson


Reply | Threaded
Open this post in threaded view
|

Re: testing the existance of a file...

Ken Causey-3
If you look at the comment for String>>asFileName it just returns
another String after doing some checks and conversions as needed.  What
you want I believe is something like

FileDirectory default fileExists: (filename asFileName).

Where filename is a string containing the filename.

Ken

On Wed, 2006-03-15 at 15:41 +0100, nelson - wrote:

> Hi all,
>    i can't figure out how to test the existance of a file. The book
> i'm reading says to use
>
> aFileName exists
>
> but if i create a filename from a string sending the message
>
> aString asFilename
>
> Squeak says that it doesn't understand the exists message..
>
> any help?
>
>
> thanks,
>   nelson



signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: testing the existance of a file...

Tom Phoenix
In reply to this post by nelson -
On 3/15/06, nelson - <[hidden email]> 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

Does that give you what you need? Good luck with it!

--Tom Phoenix

Reply | Threaded
Open this post in threaded view
|

Re: testing the existance of a file...

timrowledge

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

> On 3/15/06, nelson - <[hidden email]> 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; [hidden email]; http://www.rowledge.org/tim
Klingon Code Warrior:- 2) "My program has just dumped Stova Core!"



Reply | Threaded
Open this post in threaded view
|

Re: testing the existance of a file...

Philippe Marschall
2006/3/15, tim Rowledge <[hidden email]>:

>
> On 15-Mar-06, at 10:32 AM, Tom Phoenix wrote:
>
> > On 3/15/06, nelson - <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|

Re: testing the existance of a file...

Edgar J. De Cleene
Philippe Marschall puso en su mail :

> 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
You could combine Squeak and Unix in OS X via Applescript too.


terminal
"Applescript terminal"

    self doIt: '

tell application "Terminal"
   
     do script  "cd ~/SqueakDevelop
    grep -l ''Morph'' *.st "


end tell'



       
       
               
___________________________________________________________
1GB gratis, Antivirus y Antispam
Correo Yahoo!, el mejor correo web del mundo
http://correo.yahoo.com.ar


Reply | Threaded
Open this post in threaded view
|

Re: testing the existance of a file...

Hans-Martin Mosner
In reply to this post by nelson -
nelson - wrote:

> Hi all,
>    i can't figure out how to test the existance of a file. The book
> i'm reading says to use
>
> aFileName exists
>
> but if i create a filename from a string sending the message
>
> aString asFilename

That works in the VisualWorks dialect. They have a class Filename with
appropriate platform subclasses, and Filename objects can do all sorts
of filesystem-related tasks (such as checking for existence, enumerating
directory contents, creating streams etc).
I like the concept - it makes dealing with files pretty easy.
But Squeak does not implement it that way, although it, too, has evolved
quite a bit relative to the original Smalltalk-80 file handling.

Cheers,
Hans-Martin