Squeak equivalent for Filename

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

Squeak equivalent for Filename

Doug Edmunds
Cincom VisualWorks has this code to read the names of the
files in a directory:

(Filename named: '.') directoryContents   "returns an array of string"

What is the equivalent in Squeak?

--dae
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent for Filename

Bert Freudenberg
On Dec 23, 2007, at 7:51 , Doug Edmunds wrote:

> Cincom VisualWorks has this code to read the names of the
> files in a directory:
>
> (Filename named: '.') directoryContents   "returns an array of string"
>
> What is the equivalent in Squeak?

(FileDirectory on: '.') fileAndDirectoryNames

(also #fileNames, #directoryNames, #entries, etc)

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent for Filename

Doug Edmunds
Bert Freudenberg wrote:

> On Dec 23, 2007, at 7:51 , Doug Edmunds wrote:
>
>> Cincom VisualWorks has this code to read the names of the
>> files in a directory:
>>
>> (Filename named: '.') directoryContents   "returns an array of string"
>>
>> What is the equivalent in Squeak?
>
> (FileDirectory on: '.') fileAndDirectoryNames
>
Didn't work. I get a walkback
"Error: Fully qualified path expected"

I am using Windows XP, and bumped into this:

DosFileDirectory>>>setPathName: pathString
        "Ensure pathString is absolute - relative directories aren't supported
on all platforms."

        (pathString isEmpty
                or: [pathString first = $\
                        or: [pathString size >= 2 and: [pathString second = $: and:
[pathString first isLetter]]]])
                                ifTrue: [^ super setPathName: pathString].

        self error: 'Fully qualified path expected'

-------
dae
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent for Filename

Doug Edmunds
In reply to this post by Doug Edmunds
Frank Urbach wrote:
> > Hi Dae,
> >
> > to use the FileDirectory you have to use the full pathname on your
system e.g. C:\temp.


How then do I find out what the full pathname
is of the current directory (the equivalent to '.')?

--
dae
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Re: Squeak equivalent for Filename

David T. Lewis
On Sun, Dec 23, 2007 at 10:31:37AM -0800, Doug Edmunds wrote:
> Frank Urbach wrote:
> > >
> > > to use the FileDirectory you have to use the full pathname on your
> system e.g. C:\temp.
>
> How then do I find out what the full pathname
> is of the current directory (the equivalent to '.')?

"FileDirectory default pathName" will give you the path to the
default directory that is being used by Squeak. The actual directory
is "FileDirectory default".  And of course this is the same thing as
"FileDirectory on: FileDirectory default pathName".

The default Squeak directory is actually not the same thing as "." at
all. Different operating systems and file systems have different notions
of what "current directory" means. For example, on Windows, the default
current working directory is different for each individual volume
(C:, D:, etc), and to evaluate a relative path name you would need
to know both current volume and a current working directory for that
volume. Since other operating systems (e.g. Unix) do not use the
concept of different volumes, supporting this sort of thing within
Squeak could get messy in a hurry.

For that reason, Squeak basically just ignores the issue and uses
its own default, which may or may not happen to be the same as
"." depending on how Squeak is installed and what OS you are using.
The concept of a default Squeak directory is generic enough to
make sense on most operating systems, and serves well enough for
most purposes.

Dave

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Squeak equivalent for Filename

Bert Freudenberg
In reply to this post by Doug Edmunds

On Dec 23, 2007, at 19:02 , Doug Edmunds wrote:

> Bert Freudenberg wrote:
>> On Dec 23, 2007, at 7:51 , Doug Edmunds wrote:
>>
>>> Cincom VisualWorks has this code to read the names of the
>>> files in a directory:
>>>
>>> (Filename named: '.') directoryContents   "returns an array of  
>>> string"
>>>
>>> What is the equivalent in Squeak?
>>
>> (FileDirectory on: '.') fileAndDirectoryNames
>>
> Didn't work. I get a walkback
> "Error: Fully qualified path expected"


Well, '.' was just a place holder. You need to give a full path.

Squeak does not have a notion of a "current working directory". Try  
this instead:

FileDirectory default fileAndDirectoryNames

... which usually refers to the directory the image is in.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners