Greetings,
I am trying to get a list of the files that are in a directory using:
'/home/cpulo/data' asFileName fileNames.
Inspecting this line of code shows me that the pathname is a ByteString which is a subclass of String. String has a method called fileNames.
Three questions:
Why does the pathname evaluate as a ByteString?
Why doesn't the ByteString respond to the fileNames message?
How do I do this?
Thanks, Chris
Hi Chris,
Welcome to the Beginners list. Like you I've had some difficulty with the file handling of Squeak. From the format of your question it appears that you are on something other then Windows but the methodology should be similar.
There are two pieces to getting at files first the directory piece.
You can access directories and enumerate entries in directories by using:
FileDirectory FileDirectory default <- will get you the directory that squeak is running in FileDirectory on: '/home/cpulo/data' <- will get you the directory specified.
From this point if you need to access files you will need to use FileStream.
For Windows we use: CrLfFileStream fileNamed: aFullPathName
Look at the hierarchy for the stream you need.
To put it all together you could get the contents of readme.txt by doing the following.
"return the contents of a file 'readme.txt' in the current directory" aDirectory := FileDirectory default. aStream := CrLfFileStream fileNamed: (aDirectory fullNameFor: 'readme.txt'). ^aStream contents.
Hope that helps.
Happy coding!
Ron Teitelbaum President / Principal Software Engineer US Medical Record Specialists Ron@USMedRec.com
-----Original Message----- From: Chris Kassopulo Sent: Monday, May 01, 2006 6:02 PM
Greetings,
I am trying to get a list of the files that are in a directory using:
'/home/cpulo/data' asFileName fileNames.
Inspecting this line of code shows me that the pathname is a ByteString which is a subclass of String. String has a method called fileNames.
Three questions:
Why does the pathname evaluate as a ByteString?
Why doesn't the ByteString respond to the fileNames message?
How do I do this?
Thanks, Chris
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Hello Ron,
Thanks for the direction.
To get the list of filenames in a directory, I do:
"return the list of file names from a directory" aDirectory := FileDirectory on: '/home/cpulo/data'. aDirectory fileNames.
or
aDirectory := (FileDirectory on: '/home/cpulo/data') fileNames.
Without the parens the path is taken as a ByteString.
It Squeaks!
Chris
On Tue, 2006-05-02 at 08:19 -0400, Ron Teitelbaum wrote:
Hi Chris,
Welcome to the Beginners list. Like you I've had some difficulty with the file handling of Squeak. From the format of your question it appears that you are on something other then Windows but the methodology should be similar.
There are two pieces to getting at files first the directory piece.
You can access directories and enumerate entries in directories by using:
FileDirectory FileDirectory default <- will get you the directory that squeak is running in FileDirectory on: '/home/cpulo/data' <- will get you the directory specified.
From this point if you need to access files you will need to use FileStream.
For Windows we use: CrLfFileStream fileNamed: aFullPathName
Look at the hierarchy for the stream you need.
To put it all together you could get the contents of readme.txt by doing the following.
"return the contents of a file 'readme.txt' in the current directory" aDirectory := FileDirectory default. aStream := CrLfFileStream fileNamed: (aDirectory fullNameFor: 'readme.txt'). ^aStream contents.
Hope that helps.
Happy coding!
Ron Teitelbaum President / Principal Software Engineer US Medical Record Specialists Ron@USMedRec.com
Le 2 mai 06 à 19:53, Chris Kassopulo a écrit :
Hello Ron,
Thanks for the direction.
To get the list of filenames in a directory, I do:
"return the list of file names from a directory" aDirectory := FileDirectory on: '/home/cpulo/data'. aDirectory fileNames.
or
aDirectory := (FileDirectory on: '/home/cpulo/data') fileNames.
Without the parens the path is taken as a ByteString.
For the french-speaking guys, i start to add the reply to the FAQ on our Wiki : http://community.ofset.org/wiki/FAQ_d%C3%A9veloppeur_Squeak
Maybe someone could do the same thing in english ?
-- oooo Dr. Serge Stinckwich OOOOOOOO Université de Caen>CNRS UMR 6072>GREYC>MAD OOESUGOO http://purl.org/net/SergeStinckwich oooooo Smalltalkers do: [:it | All with: Class, (And love: it)] \ / ##
beginners@lists.squeakfoundation.org