Object » FileDirectory AcornFileDirectoy DosFileDirectory MacFileDirectory MacHFSPlusFileDirectory UnixFileDirectory
Class FileDirectory implements the interface to the file systems of your computer. The subclasses implement access support for the file systems of various operating systems, but there is normally no need to use any of these subclasses.
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 instance of DirectoryEntry, a structure that contains 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.
default
answers the working directory of the currently used Squeak instance.
forFileName: aString
takes the directory part of aString and answers a FileDirectory
for it. FileDirectory default is answered when the string does
not contain a directory part. This method is usually called with
fully qualified file names.
It should be noted that in the methods that follow, file names and directory names are always strings. Some oher Smalltalk systems provide a class FileName that is used to manipulate file names. Such a class is not part of Squeak.
directoryExists: aDirectoryName
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 the directory that
the receiver represents.
directoryNamed: aDirectoryName
Return a new instance of the receiver which allows access to the directory
entries in the subdirectory aDirectoryName of the receiver.
This method does not check the existence of the subdirectory. It also
does not throw an exception when the subdirectory does not exist. It is
recommended to use the method directoryExists: to check the existence
of the subdirectory.
entries
answers an array of items in the directory. The items are
either directories or files. Each item is represented by an instance
of DirectoryEntry.
fullNameFor: aFileName
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.
fileExists: fileNameOrPath
Answer true if a file with the given name exists. The given name may be
either a full path name or a local file within this directory.
Example:
FileDirectory default fileExists: SmalltalkImage current sourcesName
fileNamed: aLocalFileName
opens the file with the given name in this directory for writing.
The method answers an instance of StandardFileStream
that is subsequently used for writing.
newFileNamed: aFileName
creates a new file with the given local name in the receiver directory.
The exception FileExistsException is signalled when a file with the
same local name already exists.
After successful file creation the method answers an instance of
StandardFileStream
that is subsequently used for writing.
forceNewFileNamed: aFileName
creates a new file with the given local name in the receiver directory.
An already existing file with the same local name is deleted without
prior warning.
After successful file creation the method answers an instance of
StandardFileStream
that is subsequently used for writing.
oldFileNamed: aFileName
opens an existing file with the given local name in the receiver directory.
The exception FileDoesNotExistException is signalled when a file with the
same local name does not exist.
After successful file creation the method answers an instance of
StandardFileStream
that is subsequently used for writing.
oldFileOrNoneNamed: aFileName
tries to open an existing file with the given local name in the receiver directory.
After successful file opening the method answers an instance of
StandardFileStream. The value nil
is answered if the file does not exist.
readOnlyFileNamed: aFileName
opens an existing file with the given local name in the receiver directory.
The file is opened with read permission but without write permission.
The exception FileDoesNotExistException is signalled when a file with the
same local name does not exist.
After successful file creation the method answers an instance of
StandardFileStream
that is subsequently used for reading.