Greetings,
I am looking for some documentation or snippets of code for using the FileDirectory class. I want to check if a file exists before I try to read it. I also want to look at a list of files in the directory. I did search SBE and google but found nothing. Sincerely, Joe. _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Joe,
The hardest part of FileDirectory is understanding default. So start with: FileDirectory default. Note that default is on the class side. Once you inspect that you are now on the instance side. Have a look at the categories #enumeration, #'file status', and #'file operations', and #'file name utilities' when you get a file from that instance you are no longer on FileDirectory. What class are the file entries? Let me know if that helps. All the best, Ron Teitelbaum > -----Original Message----- > From: [hidden email] [mailto:beginners- > [hidden email]] On Behalf Of Joseph Alotta > Sent: Wednesday, May 25, 2016 3:22 PM > To: [hidden email] > Subject: [Newbies] FileDirectory > > Greetings, > > I am looking for some documentation or snippets of code for using the > FileDirectory class. > > I want to check if a file exists before I try to read it. > > I also want to look at a list of files in the directory. > > I did search SBE and google but found nothing. > > Sincerely, > > Joe. > > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
Hi Ron,
I get an instance of UnixFileDirectory. And there are only 6 methods for UnixFileDirectory, none of them doing what I want. Sincerely, Joe. > On May 25, 2016, at 2:43 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > Hi Joe, > > The hardest part of FileDirectory is understanding default. > > So start with: FileDirectory default. > > Note that default is on the class side. Once you inspect that you are now > on the instance side. Have a look at the categories #enumeration, #'file > status', and #'file operations', and #'file name utilities' > > when you get a file from that instance you are no longer on FileDirectory. > What class are the file entries? > > Let me know if that helps. > > All the best, > > Ron Teitelbaum > > > > > -----Original Message----- > > From: [hidden email] [mailto:beginners- > > [hidden email]] On Behalf Of Joseph Alotta > > Sent: Wednesday, May 25, 2016 3:22 PM > > To: [hidden email] > > Subject: [Newbies] FileDirectory > > > > Greetings, > > > > I am looking for some documentation or snippets of code for using the > > FileDirectory class. > > > > I want to check if a file exists before I try to read it. > > > > I also want to look at a list of files in the directory. > > > > I did search SBE and google but found nothing. > > > > Sincerely, > > > > Joe. > > > > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > If you reply to this email, your message will be added to the discussion below: > http://forum.world.st/FileDirectory-tp4897377p4897389.html > To start a new topic under Squeak - Beginners, email [hidden email] > To unsubscribe from Squeak - Beginners, click here. > NAML |
Have a look as well at http://wiki.squeak.org/squeak/2184
What exactly do you want to do? --Hannes On 5/25/16, Joseph Alotta <[hidden email]> wrote: > Hi Ron, > > I get an instance of UnixFileDirectory. And there are only 6 methods for > UnixFileDirectory, none of them doing what I want. > > Sincerely, > > Joe. > > > > >> On May 25, 2016, at 2:43 PM, Ron Teitelbaum [via Smalltalk] >> <[hidden email]> wrote: >> >> Hi Joe, >> >> The hardest part of FileDirectory is understanding default. >> >> So start with: FileDirectory default. >> >> Note that default is on the class side. Once you inspect that you are now >> >> on the instance side. Have a look at the categories #enumeration, #'file >> >> status', and #'file operations', and #'file name utilities' >> >> when you get a file from that instance you are no longer on FileDirectory. >> >> What class are the file entries? >> >> Let me know if that helps. >> >> All the best, >> >> Ron Teitelbaum >> >> >> >> > -----Original Message----- >> > From: [hidden email] [mailto:beginners- >> > [hidden email]] On Behalf Of Joseph Alotta >> > Sent: Wednesday, May 25, 2016 3:22 PM >> > To: [hidden email] >> > Subject: [Newbies] FileDirectory >> > >> > Greetings, >> > >> > I am looking for some documentation or snippets of code for using the >> > FileDirectory class. >> > >> > I want to check if a file exists before I try to read it. >> > >> > I also want to look at a list of files in the directory. >> > >> > I did search SBE and google but found nothing. >> > >> > Sincerely, >> > >> > Joe. >> > >> > >> > >> > _______________________________________________ >> > Beginners mailing list >> > [hidden email] >> > http://lists.squeakfoundation.org/mailman/listinfo/beginners >> >> _______________________________________________ >> Beginners mailing list >> [hidden email] >> http://lists.squeakfoundation.org/mailman/listinfo/beginners >> >> >> If you reply to this email, your message will be added to the discussion >> below: >> http://forum.world.st/FileDirectory-tp4897377p4897389.html >> To start a new topic under Squeak - Beginners, email >> [hidden email] >> To unsubscribe from Squeak - Beginners, click here. >> NAML > > > > > > -- > View this message in context: > http://forum.world.st/FileDirectory-tp4897377p4897398.html > Sent from the Squeak - Beginners mailing list archive at Nabble.com. Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Joseph Alotta
Hi Joe, Excellent. Remember that you should also look at the super classes for methods. UnixFileDirectory is the instance of “FileDirectory default” but it’s also a subclass of FileDirectory so the methods you can call include UnixFileDirectory and all the methods on the class hierarchy including the methods on FileDirectory. Please see the method categories on FileDirectory that I mentioned. The question I asked was a bit different. When you ask for the #entries of the instance “FileDirectory default” what class is each file? By the way, based on the question you asked there is a method on FileDirectory to determine if the file exists before you read it (it’s in the method categories I pointed out to you). What is that method? All the best, Ron Teitelbaum From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta Hi Ron, > On May 25, 2016, at 2:43 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > Hi Joe, > > The hardest part of FileDirectory is understanding default. > > So start with: FileDirectory default. > > Note that default is on the class side. Once you inspect that you are now > on the instance side. Have a look at the categories #enumeration, #'file > status', and #'file operations', and #'file name utilities' > > when you get a file from that instance you are no longer on FileDirectory. > What class are the file entries? > > Let me know if that helps. > > All the best, > > Ron Teitelbaum > > > > > -----Original Message----- > > From: [hidden email] [mailto:beginners- > > [hidden email]] On Behalf Of Joseph Alotta > > Sent: Wednesday, May 25, 2016 3:22 PM > > To: [hidden email] > > Subject: [Newbies] FileDirectory > > > > Greetings, > > > > I am looking for some documentation or snippets of code for using the > > FileDirectory class. > > > > I want to check if a file exists before I try to read it. > > > > I also want to look at a list of files in the directory. > > > > I did search SBE and google but found nothing. > > > > Sincerely, > > > > Joe. > > > > > > > > _______________________________________________ > > Beginners mailing list > > [hidden email] > > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > If you reply to this email, your message will be added to the discussion below: > http://forum.world.st/FileDirectory-tp4897377p4897389.html > To start a new topic under Squeak - Beginners, email [hidden email] > To unsubscribe from Squeak - Beginners, click here. > NAML View this message in context: Re: FileDirectory _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Hannes Hirzel
> On May 25, 2016, at 3:38 PM, Hannes Hirzel [via Smalltalk] <[hidden email]> wrote: > > Have a look as well at http://wiki.squeak.org/squeak/2184 > > What exactly do you want to do? > > —Hannes I saw that. It comes up first on google. It is 100% accurate and 100% useless. That is why the Terse Guide is the most popular documentation. As far as it goes. Sincerely, Joe. |
In reply to this post by Ron Teitelbaum
Hi Ron,
> Excellent. Remember that you should also look at the super classes for methods. UnixFileDirectory is the instance of “FileDirectory default” but it’s also a subclass of FileDirectory so the methods you can call include UnixFileDirectory and all the methods on the class hierarchy including the methods on FileDirectory. Please see the method categories on FileDirectory that I mentioned. Okay, thanks. I tried to do something with that, but I got an error. I think I was trying to use a class method on the instance. > The question I asked was a bit different. When you ask for the #entries of the instance “FileDirectory default” what class is each file? It is an Array of DirectoryEntry objects. > By the way, based on the question you asked there is a method on FileDirectory to determine if the file exists before you read it (it’s in the method categories I pointed out to you). What is that method? fileExists: I see what is happening. I thought the on: method changes the path, like cding a directory. But it gives a new instance. dir := FileDirectory default. dir on: '/Users/jja/Desktop’ ==> UnixFileDirectory on '/Users/jja/Desktop' dir fileExists: 'categories.CSV’ ==>false dir pathName ==>'/Users/jja/Desktop/Squeak-4.3-All-in-One.app/Contents/Resources' dir := FileDirectory on: '/Users/jja/Desktop’ ==> UnixFileDirectory on '/Users/jja/Desktop' dir pathName ==> '/Users/jja/Desktop' dir fileExists: 'categories.CSV’ ==> true So on: is the equivalent of new, in that it gives a new instance. Thank you, Sincerely, Joe. |
From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta Hi Ron, [Ron Teitelbaum] Exactly right. Notice the on: method on the class side, then look at #on: on the instance side. This is one of those “ah ha” moments. Classes create instances so when you see something like: “Class on:” you should automatically notice that the method is being sent to the class side since you are sending the message to the class directly. This can get confusing if there is a method that results in something like myClass := Class, or when a method calls “self class on:”. But again when it’s done the variable holds the class itself and you are still sending messages to a class when you use “myClass on:”. So when you are talking directly to a class the method is on the class side. Class side method (unless they are like the method above returning a class) usually return instances of the class, so method are now instance side methods. Returning instances is one of the main uses of class side methods. Lookup factory methods, abstract factory, and prototype, for a good example of software patterns that creates instances from the class side. Understanding polymorphism is now very important since all methods on the hierarchy are callable (on both the class and instance side). Even methods that are overridden on a subclass can still be called using “super method”. This is a fundamental piece of learning Smalltalk and not simple to understand, but it is also one of those things that is really easy to learn, and once you do you really don’t think about it anymore. It just seems natural. (and when it’s missing in other languages you go yuck! Why is this so difficult!). It also means that people that understand it think that it’s simple and natural and may not spend enough time talking about it. J One more question for you. I mentioned returning a newly created instance or a specific class from a class side method. Can you name another reason why you would write a method on the class side? Why would it be a good idea to put a method on the class side instead of the instance side? (a hint for you, I’m thinking of something where nothing is returned. (of course in Smalltalk if nothing is returned you get back self, what I mean is that nothing useful is returned)) Bonus points for 2 or more answers with or without returning something J. All the best, Ron Teitelbaum View this message in context: Re: FileDirectory _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
> On May 26, 2016, at 8:29 AM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > One more question for you. I mentioned returning a newly created instance or a specific class from a class side method. Can you name another reason why you would write a method on the class side? When you want the class as a whole to do something. When there is only one instance of an object and other is not desirable or logical. For example, one compiler: two is not practical. One instance of the number Pi. One instance of Nil. Why would you need another? > Why would it be a good idea to put a method on the class side instead of the instance side? (a hint for you, I’m thinking of something where nothing is returned. (of course in Smalltalk if nothing is returned you get back self, what I mean is that nothing useful is returned)) Bonus points for 2 or more answers with or without returning > something J. You would put a method on the class side when the method applies to all instances of the class. For example, Window closeAllWindows. Or Process stopAllProcesses. Or Smalltalk saveImage. I don’t think this is what you had in mind, though. Sincerely, Joe. |
From: Joseph Alotta
[Ron Teitelbaum] if there is one instance you would still write methods on the instance side. But yes having a class side method that provides your single instance makes sense. [Ron Teitelbaum] This was exactly what I had in mind. When you have a method that does something to all instances or is needed to find a specific instance it makes sense to implement that as a class side method. Extra credit: Why would you use a class variable? We know that an instance variable is used to store data within the context of an instance. Why would you want to store data in the context of a class? All the best, Ron Teitelbaum View this message in context: Re: FileDirectory _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
> Extra credit: Why would you use a class variable? We know that an instance variable is used to store data within the context of an instance. Why would you want to store data in the context of a class? Window closeAllWindows needs to have a list of all the windows, and sends each one the close message. Or if a instance of a class needed to communicate with other members of its class. For example, a class of helicopter bots that fly together as a group. They would need talk to each other to avoid collisions. Sincerely, Joe. |
From: Joseph Alotta
[Ron Teitelbaum] Exactly! Well done. Any dynamic information that is related to all or a collection of instances should be held on a class variable. You could of course create a framework by adding another object whose job it is to manage all these instances. Then your class variable becomes an instance variable on your manager class. It could also be used for a class with just one instance. Create it and store it so that it’s reused when asked for a second time. You will see that a lot, ^Instance ifNil: [Instance := self new. Instance]. Nice job! Ron
View this message in context: Re: FileDirectory _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
I saw a lot of code in FileDirectory for urls. What’s that all about? Can I use FileDirectory to browse the web? If not, is there another web browser object?
Sincerely, Joe. |
Have a look at the Hierarchy for the class Url Notice the class method: #urlClassForScheme: That should give you a better understanding of why url methods are in FileDirectory. For browser like methods see HTTPClient. All the best, Ron Teitelbaum From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta I saw a lot of code in FileDirectory for urls. What’s that all about? Can I use FileDirectory to browse the web? If not, is there another web browser object? View this message in context: Re: FileDirectory _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Joseph Alotta
On Fri, May 27, 2016 at 3:02 AM, Joseph Alotta <[hidden email]> wrote:
> >> On May 26, 2016, at 8:29 AM, Ron Teitelbaum [via Smalltalk] <[hidden >> email]> wrote: >> >> One more question for you. I mentioned returning a newly created instance >> or a specific class from a class side method. Can you name another reason >> why you would write a method on the class side? > > When there is only one > instance of an object and other is not desirable or logical. > > For example, one compiler: two is not practical. One instance of the number > Pi. One instance of Nil. Why would you need another? One downside of this approach is that it can make developing/running unit tests harder when your tests are changing global state - which is what class variables kind-of are. cheers -ben > >> Why would it be a good idea to put a method on the class side instead of >> the instance side? (a hint for you, I’m thinking of something where nothing >> is returned. (of course in Smalltalk if nothing is returned you get back >> self, what I mean is that nothing useful is returned)) Bonus points for 2 or >> more answers with or without returning >> something J. > > You would put a method on the class side when the method applies to all > instances of the class. For example, Window closeAllWindows. Or Process > stopAllProcesses. Or Smalltalk saveImage. > > I don’t think this is what you had in mind, though. > > Sincerely, > > Joe. > > > > ________________________________ > View this message in context: Re: FileDirectory > Sent from the Squeak - Beginners mailing list archive at Nabble.com. > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
In reply to this post by Ron Teitelbaum
> On May 26, 2016, at 5:50 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > Have a look at the Hierarchy for the class Url > > > > Notice the class method: #urlClassForScheme: > > > > That should give you a better understanding of why url methods are in FileDirectory. > > > > For browser like methods see HTTPClient. Sorry, Ron, all I got from this email after a day of trying to understand it, is that I do not have the background to grasp what you are trying to tell me. It seems you need to know all of this already before you know how to use it. I thought the purpose of encapsulation is that you do not need to know the inner workings of an object to use it. Is there something more basic about urls and httpclients that I can start with? Sincerely, Joe. |
Hi Joe, There are a number of different types of resource names. One of them is a URI the other is URL (I=Indenter L=Locator). They are ways for locating and identifying resources so that computers can find and work with them. I would recommend googling a bit about URI and URL to understand better what they are used for. The section I pointed out was a method that gave you the protocol (scheme) for the URL. URL class >> urlClassForScheme: scheme (scheme isNil or: [scheme = 'http']) ifTrue: [^HttpUrl]. scheme = 'https' ifTrue: [^HttpUrl]. scheme = 'ftp' ifTrue: [^FtpUrl]. scheme = 'file' ifTrue: [^FileUrl]. scheme = 'mailto' ifTrue: [^MailtoUrl]. scheme = 'browser' ifTrue: [^BrowserUrl]. ^GenericUrl This is a class side method that returns the class you should use to work with the resource. You asked why there were url methods on FileDirectory. The answer is that a url instead of starting with http as in http://mydomain.com/somefilename can start with file:// as in file://somefilename and this is how we get to FileDirectory (well eventually through FileUrl), that’s what I was trying to point out. All the best, Ron From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta > On May 26, 2016, at 5:50 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > Have a look at the Hierarchy for the class Url > > > > Notice the class method: #urlClassForScheme: > > > > That should give you a better understanding of why url methods are in FileDirectory. > > > > For browser like methods see HTTPClient. Sorry, Ron, all I got from this email after a day of trying to understand it, is that I do not have the background to grasp what you are trying to tell me. It seems you need to know all of this already before you know how to use it. I thought the purpose of encapsulation is that you do not need to know the inner workings of an object to use it. Is there something more basic about urls and httpclients that I can start with? Sincerely, Joe. View this message in context: Re: FileDirectory _______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners |
okay, thank you. And thank you for the wikipedia article.
sincerely, Joe. > On May 31, 2016, at 3:27 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > Hi Joe, > > > > There are a number of different types of resource names. One of them is a URI the other is URL (I=Indenter L=Locator). They are ways for locating and identifying resources so that computers can find and work with them. I would recommend googling a bit about URI and URL to understand better what they are used for. The section I pointed out was a method that gave you the protocol (scheme) for the URL. > > > > URL class >> urlClassForScheme: scheme > > (scheme isNil or: [scheme = 'http']) ifTrue: [^HttpUrl]. > > scheme = 'https' ifTrue: [^HttpUrl]. > > scheme = 'ftp' ifTrue: [^FtpUrl]. > > scheme = 'file' ifTrue: [^FileUrl]. > > scheme = 'mailto' ifTrue: [^MailtoUrl]. > > scheme = 'browser' ifTrue: [^BrowserUrl]. > > ^GenericUrl > > > > This is a class side method that returns the class you should use to work with the resource. You asked why there were url methods on FileDirectory. The answer is that a url instead of starting with http as in http://mydomain.com/somefilename can start with file:// as in file://somefilename and this is how we get to FileDirectory (well eventually through FileUrl), that’s what I was trying to point out. > > > > All the best, > > > > Ron > > > > > > > > From: [hidden email] [mailto:[hidden email]] On Behalf Of Joseph Alotta > Sent: Tuesday, May 31, 2016 2:16 PM > To: [hidden email] > Subject: [Newbies] Re: FileDirectory > > > > > > > On May 26, 2016, at 5:50 PM, Ron Teitelbaum [via Smalltalk] <[hidden email]> wrote: > > > > Have a look at the Hierarchy for the class Url > > > > > > > > Notice the class method: #urlClassForScheme: > > > > > > > > That should give you a better understanding of why url methods are in FileDirectory. > > > > > > > > For browser like methods see HTTPClient. > > > > Sorry, Ron, all I got from this email after a day of trying to understand it, is that I do not have the background to grasp what you are trying to tell me. It seems you need to know all of this already before you know how to use it. > > I thought the purpose of encapsulation is that you do not need to know the inner workings of an object to use it. > > Is there something more basic about urls and httpclients that I can start with? > > Sincerely, > > Joe. > > > > View this message in context: Re: FileDirectory > Sent from the Squeak - Beginners mailing list archive at Nabble.com. > > > _______________________________________________ > Beginners mailing list > [hidden email] > http://lists.squeakfoundation.org/mailman/listinfo/beginners > > > If you reply to this email, your message will be added to the discussion below: > http://forum.world.st/FileDirectory-tp4897377p4898441.html > To start a new topic under Squeak - Beginners, email [hidden email] > To unsubscribe from Squeak - Beginners, click here. > NAML |
Free forum by Nabble | Edit this page |