Squeak Class Documentation category index | class index  
 
FileDirectory
  category: System-Files
  superclass: Object
  subclasses: UnixFileDirectory AcornFileDirectory MacFileDirectory DosFileDirectory

A FileDirectory represents a folder or directory in the underlying platform's file system. It carries a fully-qualified path name for the directory it represents, and can enumerate the files and directories within that directory.

A FileDirectory can be thought of as a Dictionary whose keys are the local names of files in that directory, and whose values are directory "entries". Each entry is an array of five items:

<name> <creationTime> <modificationTime> <dirFlag> <fileSize>

The times are given in seconds, and can be converted to a time and date via Time>dateAndTimeFromSeconds:. See the comment in lookupEntry:... which provides primitive access to this information.

instance methods
  enumeration
  containingDirectory
directoryEntry
directoryNamed:
directoryNames
entries
fileAndDirectoryNames
fileNames
fullName
fullNamesOfAllFilesInSubtree
keysDo:
localName
matchingEntries:
statsForDirectoryTree:

  file directory
  assureExistance
assureExistanceOfPath:
localNameFor:
sleep
wakeUp

  file name utilities
  checkName:fixErrors:
fileNamesMatching:
fullNameFor:
isLegalFileName:
isTypeFile
nextNameFor:extension:
realUrl
splitNameVersionExtensionFor:
url

  file operations
  copyFile:toFile:
copyFileNamed:toFileNamed:
copyFileWithoutOverwriteConfirmationNamed:toFileNamed:
createDirectory:
deleteDirectory:
deleteFileNamed:
deleteFileNamed:ifAbsent:
getMacFileTypeAndCreator:
mimeTypesFor:
putFile:named:
putFile:named:retry:
rename:toBe:
setMacFileNamed:type:creator:
upLoadProject:named:resourceUrl:retry:

  file status
  entryAt:
entryAt:ifAbsent:

  file stream creation
  fileNamed:
forceNewFileNamed:
newFileNamed:
oldFileNamed:
oldFileOrNoneNamed:
readOnlyFileNamed:

  path access
  fullPathFor:
on:
pathName
pathNameDelimiter
pathParts
slash

  printing
  printOn:

  private
  directoryContentsFor:
primCreateDirectory:
primDeleteDirectory:
primDeleteFileNamed:
primGetMacFileNamed:type:creator:
primLookupEntryIn:index:
primRename:to:
primSetMacFileNamed:type:creator:
setPathName:
storeServerEntryOn:

  school support
  eToyBaseFolderSpec
eToyBaseFolderSpec:
eToyUserList
eToyUserListUrl
eToyUserListUrl:
eToyUserName:
hasEToyUserList

  searching
  filesContaining:caseSensitive:
withAllFilesDo:andDirectoriesDo:

  squeaklets
  directoryObject
downloadUrl
updateProjectInfoFor:

  testing
  acceptsUploads
directoryExists:
fileExists:
fileOrDirectoryExists:
includesKey:
isAFileNamed:
isCaseSensitive

class methods
  class initialization
  initializeStandardMIMETypes

  create/delete file
  deleteFilePath:

  instance creation
  default
forFileName:
on:
root

  name utilities
  baseNameFor:
changeSuffix
checkName:fixErrors:
dirPathFor:
extensionFor:
fileName:extension:
imageSuffix
isLegalFileName:
localNameFor:
searchAllFilesForAString
splitName:to:
startUp
urlForFileNamed:

  platform specific
  dot
extensionDelimiter
isCaseSensitive
maxFileNameLength
pathNameDelimiter
slash

  private
  activeDirectoryClass
isActiveDirectoryClass
primPathNameDelimiter

  system start up
  openChanges:forImage:
openSources:andChanges:forImage:
openSources:forImage:
setDefaultDirectory:
setDefaultDirectoryFrom:
shutDown

instance methods
  enumeration top  
 

containingDirectory

Return the directory containing this directory.


 

directoryEntry


 

directoryNamed:

Return the subdirectory of this directory with the given name.


 

directoryNames

Return a collection of names for the subdirectories of this directory.


 

entries

Return a collection of directory entries for the files and directories in this directory. Each entry is a five-element array: (<name><creationTime><modificationTime><dirFlag><fileSize>). See primLookupEntryIn:index: for further details.


 

fileAndDirectoryNames

FileDirectory default fileAndDirectoryNames


 

fileNames

Return a collection of names for the files (but not directories) in this directory.


 

fullName

Return the full name of this directory.


 

fullNamesOfAllFilesInSubtree

Answer a collection containing the full names of all the files in the subtree of the file system whose root is this directory.


 

keysDo:

Evaluate the given block for each file or directory name in this directory.


 

localName

Return the local name of this directory.


 

matchingEntries:

Ignore the filter criteria for now


 

statsForDirectoryTree:

Return the size statistics for the entire directory tree starting at the given root. The result is a three element array of the form: (<number of folders><number of files><total bytes in all files>). This method also serves as an example of how recursively enumerate a directory tree.


  file directory top  
 

assureExistance

Make sure the current directory exists. If necessary, create all parts inbetween


 

assureExistanceOfPath:

Make sure the local directory exists. If necessary, create all parts inbetween


 

localNameFor:

Return the local part the given name.


 

sleep

Leave the FileList window. Do nothing. Disk directories do not have to be shut down.


 

wakeUp

Entering a FileList window. Do nothing. Disk directories do not have to be awakened.


  file name utilities top  
 

checkName:fixErrors:

Check a string aFileName for validity as a file name. Answer the original file name if it is valid. If the name is not valid (e.g., it is too long or contains illegal characters) and fixing is false, raise an error. If fixing is true, fix the name (usually by truncating and/or tranforming characters), and answer the corrected name. The default behavior is just to truncate the name to the maximum length for this platform. Subclasses can do any kind of checking and correction appropriate for their platform.


 

fileNamesMatching:

FileDirectory default fileNamesMatching: '*'


 

fullNameFor:

Return a corrected, fully-qualified name for the given file name. If the given name is already a full path (i.e., it contains a delimiter character), assume it is already a fully-qualified name. Otherwise, prefix it with the path to this directory. In either case, correct the local part of the file name.


 

isLegalFileName:

Answer true if the given string is a legal file name.


 

isTypeFile


 

nextNameFor:extension:

Assumes a file name includes a version number encoded as '.' followed by digits
preceding the file extension. Increment the version number and answer the new file name.
If a version number is not found, set the version to 1 and answer a new file name


 

realUrl

Senders expect url without trailing slash - #url returns slash


 

splitNameVersionExtensionFor:

answer an array with the root name, version # and extension.
See comment in nextSequentialNameFor: for more details


 

url

Convert my path into a file:// type url. Use slash instead of the local delimiter (:), and convert odd characters to %20 notation.


  file operations top  
 

copyFile:toFile:


 

copyFileNamed:toFileNamed:

Copy the contents of the existing file with the first name into a new file with the second name. Both files are assumed to be in this directory.


 

copyFileWithoutOverwriteConfirmationNamed:toFileNamed:

Copy the contents of the existing file with the first name into a file with the second name (which may or may not exist). If the second file exists, force an overwrite without confirming. Both files are assumed to be in this directory.


 

createDirectory:

Create a directory with the given name in this directory. Fail if the name is bad or if a file or directory with that name already exists.


 

deleteDirectory:

Delete the directory with the given name in this directory. Fail if the path is bad or if a directory by that name does not exist.


 

deleteFileNamed:

Delete the file with the given name in this directory.


 

deleteFileNamed:ifAbsent:

Delete the file of the given name if it exists, else evaluate failBlock.
If the first deletion attempt fails do a GC to force finalization of any lost references. ar 3/21/98 17:53


 

getMacFileTypeAndCreator:

get the Macintosh file type and creator info for the file with the given name. Fails if the file does not exist or if the type and creator type arguments are not strings of length 4. Does nothing on other platforms (where the underlying primitive is a noop).


 

mimeTypesFor:

Return a list of MIME types applicable to the receiver. This default implementation uses the file name extension to figure out what we're looking at but specific subclasses may use other means of figuring out what the type of some file is. Some systems like the macintosh use meta data on the file to indicate data type


 

putFile:named:

Copy the contents of the existing fileStream into the file destinationFileName in this directory. fileStream can be anywhere in the fileSystem.


 

putFile:named:retry:

Copy the contents of the existing fileStream into the file destinationFileName in this directory. fileStream can be anywhere in the fileSystem. No retrying for local file systems.


 

rename:toBe:

Rename the file of the given name to the new name. Fail if there is no file of the old name or if there is an existing file with the new name.


 

setMacFileNamed:type:creator:

Set the Macintosh file type and creator info for the file with the given name. Fails if the file does not exist or if the type and creator type arguments are not strings of length 4. Does nothing on other platforms (where the underlying primitive is a noop).


 

upLoadProject:named:resourceUrl:retry:

Copy the contents of the existing fileStream into the file destinationFileName in this directory. fileStream can be anywhere in the fileSystem. No retrying for local file systems.


  file status top  
 

entryAt:

find the entry with local name fileName


 

entryAt:ifAbsent:

Find the entry with local name fileName and answer it.
If not found, answer the result of evaluating aBlock.


  file stream creation top  
 

fileNamed:

Open the file with the given name in this directory for writing.


 

forceNewFileNamed:

Open the file with the given name in this directory for writing. If it already exists, delete it first without asking.


 

newFileNamed:

Create a new file with the given name in this directory.


 

oldFileNamed:

Open the existing file with the given name in this directory.


 

oldFileOrNoneNamed:

If the file exists, answer a read-only FileStream on it. If it doesn't, answer nil.


 

readOnlyFileNamed:

Open the existing file with the given name in this directory for read-only access.


  path access top  
 

fullPathFor:


 

on:

Return another instance


 

pathName

Return the path from the root of the file system to this directory.


 

pathNameDelimiter

Return the delimiter character for this kind of directory. This depends on the current platform.


 

pathParts

Return the path from the root of the file system to this directory as an array of directory names.


 

slash


  printing top  
 

printOn:

Refer to the comment in Object|printOn:.


  private top  
 

directoryContentsFor:

Return a collection of directory entries for the files and directories in the directory with the given path. See primLookupEntryIn:index: for further details.


 

primCreateDirectory:

Create a directory named by the given path. Fail if the path is bad or if a file or directory by that name already exists.


 

primDeleteDirectory:

Delete the directory named by the given path. Fail if the path is bad or if a directory by that name does not exist.


 

primDeleteFileNamed:

Delete the file of the given name. Return self if the primitive succeeds, nil otherwise.


 

primGetMacFileNamed:type:creator:

Get the Macintosh file type and creator info for the file with the given name. Fails if the file does not exist or if the type and creator type arguments are not strings of length 4. This primitive is Mac specific; it is a noop on other platforms.


 

primLookupEntryIn:index:

Look up the index-th entry of the directory with the given fully-qualified path (i.e., starting from the root of the file hierarchy) and return an array containing:

<name> <creationTime> <modificationTime> <dirFlag> <fileSize>

The empty string enumerates the top-level files or drives. (For example, on Unix, the empty path enumerates the contents of '/'. On Macs and PCs, it enumerates the mounted volumes/drives.)

The creation and modification times are in seconds since the start of the Smalltalk time epoch. DirFlag is true if the entry is a directory. FileSize the file size in bytes or zero for directories. The primitive returns nil when index is past the end of the directory. It fails if the given path is bad.


 

primRename:to:

Rename the file of the given name to the new name. Fail if there is no file of the old name or if there is an existing file with the new name.
Changed to return nil instead of failing ar 3/21/98 18:04


 

primSetMacFileNamed:type:creator:

Set the Macintosh file type and creator info for the file with the given name. Fails if the file does not exist or if the type and creator type arguments are not strings of length 4. This primitive is Mac specific; it is a noop on other platforms.


 

setPathName:


 

storeServerEntryOn:


  school support top  
 

eToyBaseFolderSpec


 

eToyBaseFolderSpec:


 

eToyUserList


 

eToyUserListUrl


 

eToyUserListUrl:


 

eToyUserName:

Set the default directory from the given user name


 

hasEToyUserList


  searching top  
 

filesContaining:caseSensitive:

Search the contents of all files in the receiver and its subdirectories for the search string. Return a list of paths found. Make the search case sensitive if aBoolean is true.


 

withAllFilesDo:andDirectoriesDo:

For the receiver and all it's subdirectories evaluate directoryBlock.
For a read only file stream on each file within the receiver
and it's subdirectories evaluate fileStreamBlock.


  squeaklets top  
 

directoryObject


 

downloadUrl


 

updateProjectInfoFor:

only swiki servers for now


  testing top  
 

acceptsUploads


 

directoryExists:

Answer true if a directory of the given name exists. The given name may be either a full path name or a local directory within this directory.


 

fileExists:

Answer true if a file of the given name exists. The given name may be either a full path name or a local file within this directory.


 

fileOrDirectoryExists:

Answer true if either a file or a directory file of the given name exists. The given name may be either a full path name or a local name within this directory.


 

includesKey:

Answer true if this directory includes a file or directory of the given name. Note that the name should be a local file name, in contrast with fileExists:, which takes either local or full-qualified file names.


 

isAFileNamed:


 

isCaseSensitive

Return true if file names are treated case sensitive


class methods
  class initialization top  
 

initializeStandardMIMETypes

FileDirectory initializeStandardMIMETypes


  create/delete file top  
 

deleteFilePath:

Delete the file after finding its directory


  instance creation top  
 

default

Answer the default directory.


 

forFileName:


 

on:

Return a new file directory for the given path, of the appropriate FileDirectory subclass for the current OS platform.


 

root

Answer the root directory.


  name utilities top  
 

baseNameFor:

Return the given file name without its extension, if any.


 

changeSuffix

if 'changes' is not suitable, override this message to return something that is ok


 

checkName:fixErrors:

Check a string aFileName for validity as a file name. Answer the original file name if it is valid. If the name is not valid (e.g., it is too long or contains illegal characters) and fixing is false, raise an error. If fixing is true, fix the name (usually by truncating and/or tranforming characters), and answer the corrected name. The default behavior is to truncate the name to 31 chars. Subclasses can do any kind of checking and correction appropriate to the underlying platform.


 

dirPathFor:

Return the directory part the given name.


 

extensionFor:

Return the extension of given file name, if any.


 

fileName:extension:


 

imageSuffix

if 'image' is not suitable, override this message to return something that is ok


 

isLegalFileName:

Return true if the given string is a legal file name.


 

localNameFor:

Return the local part the given name.


 

searchAllFilesForAString

Prompt the user for a search string, and a starting directory. Search the contents of all files in the starting directory and its subdirectories for the search string (case-insensitive search.)
List the paths of files in which it is found on the Transcript.
By Stewart MacLean 5/00; subsequently moved to FileDirectory class-side, and refactored to call FileDirectory.filesContaining:caseSensitive:


 

splitName:to:

Take the file name and convert it to the path name of a directory and a local file name within that directory. FileName must be of the form: <dirPath><delimiter><localName>, where <dirPath><delimiter> is optional. The <dirPath> part may contain delimiters.


 

startUp

Establish the platform-specific FileDirectory subclass. Do any platform-specific startup.


 

urlForFileNamed:

Create a URL for the given fully qualified file name


  platform specific top  
 

dot

Return a one-character string containing the filename extension delimiter for this platform (i.e., the local equivalent of 'dot')


 

extensionDelimiter

Return the character used to delimit filename extensions on this platform. Most platforms use the period (.) character.


 

isCaseSensitive

Return true if file names are treated case sensitive


 

maxFileNameLength


 

pathNameDelimiter

return the active directory class's directory seperator character


 

slash


  private top  
 

activeDirectoryClass

Return the concrete FileDirectory subclass for the platform on which we are currently running.


 

isActiveDirectoryClass

Does this class claim to be that properly active subclass of FileDirectory for this platform?
Default test is whether the primPathNameDelimiter matches the one for this class. Other tests are possible


 

primPathNameDelimiter

Return the path delimiter for the underlying platform's file system.


  system start up top  
 

openChanges:forImage:

Initialize the default directory to the image directory and open the
sources and changes files, if possible. Look for the changes file in
image directory. Look for the system sources (or an alias to it) first in
the VM directory, then in the image directory. Open the changes and
sources files and install them in SourceFiles.


 

openSources:andChanges:forImage:

Initialize the default directory to the image directory and open the
sources and changes files, if possible. Look for the changes file in
image directory. Look for the system sources (or an alias to it) first in
the VM directory, then in the image directory. Open the changes and
sources files and install them in SourceFiles.


 

openSources:forImage:

Initialize the default directory to the image directory and open the
sources and changes files, if possible. Look for the changes file in
image directory. Look for the system sources (or an alias to it) first in
the VM directory, then in the image directory. Open the changes and
sources files and install them in SourceFiles.


 

setDefaultDirectory:

Initialize the default directory to the directory supplied. This method is called when the image starts up.


 

setDefaultDirectoryFrom:

Initialize the default directory to the directory containing the Squeak image file. This method is called when the image starts up.


 

shutDown

This message is sent on system shutdown to registered classes