Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Porting code to Pharo 2.0

Pharo 2.0 changed some basic API bits, and I cannot found the new way of doing the following:

  1. FileDirectory default directoryNamed: aFolderString.
  2. FileDirectory on: aFilename.
  3. FileDirectory default assureExistenceOfPath: aString.
  4. ReferenceStream on: stream.

What would be the new equivalent code? Is there an update guide available describing how to translate or port code?

like image 733
user183928 Avatar asked Apr 02 '13 06:04

user183928


2 Answers

The following statements correspond do the ones you put in your question.

  1. FileSystem workingDirectory / aFolderString
  2. aFilename asFileReference
  3. aString asFileReference ensureDirectory
  4. ReferenceStream does no longer exist in 2.0.

aPathString asFileReference resolves aPathString, so if there are slashes in your name you will end up in a subdirectory.

/ on the other hand takes a single directory or file name as an argument, and does not resolve further subdirectories. Depending on your platform you can easily refer to a file named foo/bar with a slash in the name with FileSystem workingDirectory / 'foo/bar'.

like image 105
camillobruni Avatar answered Oct 04 '22 20:10

camillobruni


I have collected some translations you may find useful:

+------------------------------------------------------+---------------------------------------------------------------------------+
|                    FileDirectory                     |                                FileSystem                                 |
+------------------------------------------------------+---------------------------------------------------------------------------+
| FileDirectory assureExistence.                       | aString asFileReference ensureDirectory.                                  |
| FileDirectory baseNameFor: aString.                  | aString asFileReference base.                                             |
| FileDirectory containingDirectory.                   | Path parent asFileReference pathString.                                   |
| FileDirectory default deleteFileNamed: aString.      | aString asFileReference ensureDeleted.                                    |
| FileDirectory default directoryExists: aString.      | aString asFileReference exists.                                           |
| FileDirectory default directoryNamed: aFolderString. | FileSystem disk / aFolderString.                                          |
| FileDirectory directoryEntryFor: aString.            | aString asFilereference.                                                  |
| (FileDirectory entryFor: aString) / 'filename'.      | aString asFileReference / 'filename'.                                     |
| FileDirectory extensionFor: aString.                 | aString asFileReference extension.                                        |
| FileDirectory default fileExists: aString.           | aString asFileReference exists. " or " DiskStore current isFile: aString. |
| FileDirectory default fullNameFor: aString.          | aString asFileReference fullName.                                                         |
| FileDirectory default pathName.                      | FileSystem disk workingDirectory fullName.                                |
| FileDirectory on: aFilename.                         | aFilename asFileReference.                                                |
| (FileDirectory on: aString) entries collect: #name.  | aString asFileReference children collect: #basename.                      |
| (FileDirectory on: aString) entryAt: 'filename'.     | aString asFileReference / 'filename'.                                     |
| FileDirectory oldFileNamed: aString.                 | aString asFileReference readStream.                                       |
| FileDirectory slash.                                 | FileSystem disk separator. " or " DiskStore delimiter asString.           |
+------------------------------------------------------+---------------------------------------------------------------------------+
like image 31
Hernán Avatar answered Oct 04 '22 21:10

Hernán