eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Filename':

Home

everywhere
www.exept.de
for:
[back]

Class: Filename


Inheritance:

   Object
   |
   +--Filename
      |
      +--AutoDeletedFilename
      |
      +--UnixFilename

Package:
stx:libbasic
Category:
System-Support
Version:
rev: 1.350 date: 2010/04/30 16:49:05
user: stefan
file: Filename.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


Filenames; originally added for ST-80 compatibility, is
taking over functionality from other classes (FileDirectory).

Instances of Filename do not nescessarily represent valid or existing
files - i.e. it is possible (and useful) to have instances for non-existing
files around. In other words: the name-string is not checked automatically
for being correct or existing.
Thus, it is possible to do queries such as:

    '/fee/foo/foe' asFilename exists     
    '/not_existing' asFilename isDirectory 
    '/foo/bar' asFilename isReadable 

(all of the above examples will probably return false on your machine ;-).

examples:

    'Makefile' asFilename readStream

    'newFile' asFilename writeStream

    Filename newTemporary writeStream

Beside lots of protocol to query for a files attributes, the class
protocol offers methods for filename completion, to construct pathes
(in an OS-independent way) and to create temporary files.
Especially the path-construction methods (i.e. #construct:) are highly
recommended in order to avoid having OS details (like directory separators
being slash or backslash) spreaded in your application.

Since Filenames have different semantics under different operating systems,
class methods are delegated to concrete implementations in various subclasses like
UnixFilename, PCFilename, ...
The delegation is implemented in a way, so that some methods of
specific OS Filenames might be used, even if ST/X is currently running 
on a different OS (as long as the method does not depend on the OperatingSystem class).


Related information:

    String
    FileStream
    DirectoryStream
    PipeStream
    Socket
    OperatingSystem
    Date
    Time

Class protocol:

defaults
o  concreteClass
different subclasses of Filename are used for different
OperatingSystems; concreteClass is supposed to return an appropriate class.

o  defaultClass
different subclasses of Filename are used for different
OperatingSystems; defaultClass is supposed to return an appropriate class

o  defaultTempDirectoryName
return the default temp directory as a filename.
This is used, if no special preferences were defined in
any of the TEMP-environment variables (see tempDirectory).

initialization
o  initialize
initialize for the OS we are running on

o  initializeConcreteClass
initialize for the OS we are running on

o  reinitialize
initialize for the OS we are running on (after a restart)

instance creation
o  currentDirectory
return a filename for the current directory

o  defaultDirectory
ST80 compatibility: same as currentDirectory

o  defaultTempDirectory
return the default temp directory as a filename.
That is the same as TempDirectory, except that TempDirectory can be changed
from the outside (via tempDirectory:).
Use this for files which MUST remain the same (stx_sourceCache)

o  desktopDirectory
return your desktop directory.
Under windows, thats the real desktop directory;
under other OperatingSystems, the home directory is returned.

o  documentsDirectory
return your documents directory.
Under windows, thats the real 'Documents' or 'My Documents';
under other OperatingSystems, the home directory is returned.

o  findDefaultDirectory
same as #defaultDirectory for ST80 compatibility

o  fromComponents: aCollectionOfDirectoryNames
create & return a new filename from components given in
aCollectionOfDirectoryNames. If the first component is the name of the
root directory (i.e. '/') an absolute path-filename is returned.

o  fromUser
show a box to enter a filename.
Return a filename instance or nil (if cancel was pressed).

o  homeDirectory
return your homeDirectory.
Some OperatingSystems do not support this - on those, the defaultDirectory
(which is the currentDirectory) is returned.

o  named: aString
return a filename for a directory named aString.
This is the same as 'aString asFilename'.

o  newTemporary
return a new unique filename - use this for temporary files.
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our
unix process id, and nn is a unique number, incremented with every
call to this method.
If any of the environment variables ST_TMPDIR or TMPDIR is set,
its value defines the temp directory.
Notice, that no file is created by this - only a unique name
is generated.

o  newTemporaryDirectory
return a new unique temporary directory - use this for temporary files.
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our
unix process id, and nn is a unique number, incremented with every
call to this method.
If any of the environment variables ST_TMPDIR or TMPDIR is set,
its value defines the temp directory.

o  newTemporaryDirectoryIn: aDirectoryOrNil
return a new unique temporary directory in another directory, or the current dir.
Use this for temporary files.
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our
unix process id, and nn is a unique number, incremented with every
call to this method.
If any of the environment variables ST_TMPDIR or TMPDIR is set,
its value defines the temp directory.

o  newTemporaryIn: aDirectoryOrNil
return a new unique filename - use this for temporary files.
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn',
where xx is our unix process id, and nn is a unique number, incremented
with every call to this method.
Notice: only a unique filename object is created and returned - no physical
file is created by this method (i.e. you have to send #writeStream or
whatever to it in order to really create something).
See also: #newTemporary which looks for a good temp directory.

o  newTemporaryIn: aDirectoryOrNil nameTemplate: template
return a new unique filename - use this for temporary files.
The filenames returned are in aDirectoryOrNil and named after the given template,
in which %1 and %2 are expanded to the unix process id, and a unique number, incremented
with every call to this method respectively.
Notice: only a unique filename object is created and returned - no physical
file is created by this method (i.e. you have to send #writeStream or
whatever to it in order to really create something).
See also: #newTemporary which looks for a good temp directory.

o  nullDevice
return the filename of the nullDevice (if available).
returns nil, if the OperatingSystem does not support this.

o  remoteHost: remoteHostString rootComponents: aCollectionOfDirectoryNames
create & return a new filename from components given in
aCollectionOfDirectoryNames on a host named remoteHostString.
An absolute network-filename is returned.

o  rootComponents: aCollectionOfDirectoryNames
create & return a new filename from components given in
aCollectionOfDirectoryNames.
An absolute path-filename is returned.

o  rootDirectory
return a filename for the root directory

o  rootDirectoryOnVolume: aVolumeName
return a filename for the root directory on some volume

o  tempDirectory
return the temp directory as a filename.
If any of the environment variables STX_TMPDIR, ST_TMPDIR,
TMPDIR or TEMPDIR is set, its value defines the name,
otherwise, '/tmp' is used. (at least on unix ...).

Notice: do not hardcode '/tmp' into your programs - things may be
different on other operating systems. Also, the user may want to set the
TMPDIR environment variable to have her temp files somewhere else.

o  tempDirectory: aFilename
set the xdefault temporary directory pathname

misc
o  canonicalize: aPathString
convert the argument, aPathString to a good format.
This should eliminate useless directory components (i.e. '././')
and useless tree walks (i.e. '../foo/..').

o  filterSeps: aFilenameString
ST80 compatibility:
filter out (invalid) separators in aFilenameString.
We recommend using #makeLegalFilename

o  suggest: aFilenameString
return a fileNamestring based on the argument,
which is legal on the current platform.

queries
o  components: aString
separate the pathName given by aString into
a collection containing the directory components and the files name as
the final component.
If the argument names an absolute path, the first component will be the
name of the root directory (i.e. '/').

o  currentDirectoryName
return a filename for the current directory

o  defaultDirectoryName
ST80 compatibility: return the defaultDirectories name (as a string)

o  directorySuffix
Return the OS dependent directory suffix string, or nil if there is none.
The default is nil here, redefined for VMS

o  errorReporter
who knows the signals to report errors?

o  filenameCompletionFor: aString directory: inDirectory directoriesOnly: directoriesOnly filesOnly: filesOnly ifMultiple: aBlock
perform filename completion on aString in some directory;
return the longest matching filename prefix as a string.
The boolean directoriesOnly and filesOnly control respectively,
if only directories or only regular files are to be considered for completion.
If multiple files match, the exception block aBlock is evaluated with a
filename representing the directory (where the match was done) as argument.
(this may be different from the inDirectory argument, if aString is absolute
or starts with ../)

o  filenameCompletionFor: aString directory: inDirectory directoriesOnly: directoriesOnly filesOnly: filesOnly ifMultiple: aBlock forMultipleDo: aMultipleBlock
perform filename completion on aString in some directory;
return the longest matching filename prefix as a string.
The boolean directoriesOnly and filesOnly control respectively,
if only directories or only regular files are to be considered for completion.
If multiple files match, the exception block aBlock is evaluated with a
filename representing the directory (where the match was done) as argument and the aMultipleBlock
is evaluated with both the directory (where the match was done) and the matchSet
(list of matched filenames) as arguments.
(this may be different from the inDirectory argument, if aString is absolute
or starts with ../)

o  filesMatching: aPattern
return a collection of strings, representing the names
of files matching aPattern.
If aPattern contains a directory path, files are tried there;
otherwise, files from the currentDirectory are tried.
The returned strings are the expanded names, in the same form
as given in pattern.
The pattern should be a simple pattern.

o  isAbstract
return true, if this is not a concrete class

o  isBadCharacter: aCharacter
return true, if aCharacter is unallowed in a filename.

o  isCaseSensitive
return true, if filenames are case sensitive.
We ask the OS about this, to be independent here.

o  localNameStringFrom: aString
ST-80 compatibility.
what does this do ? (used in FileNavigator-goody).
GUESS:
does it strip off any volume characters and make a path relative ?

o  maxComponentLength
return the maximum number of characters a filename component may
be in size. This depends on the OperatingSystem.

o  maxLength
return the maximum number of characters a filename may be in size.
This depends on the OperatingSystem.

o  nullFilename
Return the OS dependent filename for /dev/null, or nil if there is none.
The default is nil here

o  parentDirectoryName
return the name used for the parent directory.
This is '..' for unix and dos-like systems.
(there may be more in the future.

o  separator
return the file/directory separator.
This is to be redefined in concrete classes;
the following default usually leads to a flat view of
the fileSystem (huh - BS2000 ?)

o  separatorString
return the file/directory separator as a string.

o  suffixSeparator
return the filename suffix separator.
Usually, this is $. for unix-like and msdos systems
(there is currently no known system, where this differs)

o  tempFileNameTemplate
return a template for temporary files.
This is expanded with the current processID and a sequenceNumber
to generate a unique filename.

o  volumes
ST-80 compatibility.
GUESS: does it return the available drives on MSDOS systems ?
Q: what does this do on Unix systems ? (used in FileNavigator-goody).

utilities
o  nameFromComponents: aCollectionOfDirectoryNames
return a filenameString from components given in aCollectionOfDirectoryNames.
If the first component is the name of the root directory (i.e. '/'),
an absolute path-string is returned.

o  readingFile: aPathName do: aBlock
create a read-stream on a file, evaluate aBlock, passing that stream,
and return the blocks value.
Ensures that the stream is closed.


Instance protocol:

Compatibility-VW5.4
o  asLogicalFileSpecification

o  canBeWritten
same as isWritable - for ST-80 compatibility

o  definitelyExists
for now - a kludge

o  extension
return the receiver's extension;
that is the characters from and including
the last period or nil, if there is none.

comparing
o  = aFilename
return true, if the argument represents the same filename

o  contentsIsPrefixOf: aFilename
return true if the contents of the file represented by the receiver
is the same as or a prefix of the contents of the file represented by the argument, aFilename.
This compares the files actual contents; not the filenames.

o  contentsStartsWithContentsOf: aFilename
return true if the contents of the file represented by aFilename
is the same as or a prefix of the contents of the file represented by the receiver.
This compares the files actual contents; not the filenames.

o  hash
return an integer useful as a hash-key

o  sameContentsAs: aFilename
return true if the file represented by the receiver has the
same contents as the file represented by the argument, aFilename.
This compares the files actual contents; not the filenames.

converting
o  asAbsoluteFilename
return the receiver converted to a filename with
an absolute pathname.

o  asAutoDeletedFilename

o  asCanonicalizedFilename
return the receiver converted to a filename without intermediate ..'s and .'s
(similar to an absolute pathname, but symlinks are not resolved).

o  asFilename
return the receiver converted to a filename; here, thats the receiver itself.

o  asString
return the receiver converted to a string

o  asURI
return the receiver converted to a string

o  components
return the receivers filename components - that is the name of each directory
along the pathName (that DOES include the root directory)

o  makeLegalFilename
convert the receivers name to be a legal filename.
This removes/replaces invalid characters and/or compresses
the name as required by the OS.
The implementation may change in the future to be more
OS specific.

o  withEncoding: encodingSymbol
dummy for now - for ST80 compatibility

enumerating-contents
o  allDirectoriesDo: aBlock
evaluate aBlock for all (recursive) directories contained in the directory represented by the receiver.
The block is invoked with a filename-arguments.
The enumerations order within a directory is undefined - i.e. usually NOT sorted by
filenames (but by creation time - on some systems).
This excludes entries for '.' or '..'.
NoOp for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.

o  allParentDirectoriesDo: aBlock
evaluate aBlock for all (recursive) directories along the parent directory path.
The block is invoked with a filename-arguments.

o  directories
return a collection of directories contained in the directory represented by the receiver.

o  directoriesDo: aBlock
evaluate aBlock for directories contained in the directory represented by the receiver.
The block is invoked with a filename-arguments.
The enumerations order is undefined - i.e. usually NOT sorted by
filenames (but by creation time - on some systems).
This excludes entries for '.' or '..'.
NoOp for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.

o  directoryContentsAsFilenamesDo: aBlock
evaluate aBlock for each file in the directory represented by the receiver.
The block is invoked with a filename-argument.
The enumerations order is undefined - i.e. usually NOT sorted by
filenames (but by creation time - on some systems).
This excludes entries for '.' or '..'.
NoOp for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.
Notice: this enumerates fileName objects; see also
#directoryContentsDo:, which enumerates strings.

o  directoryContentsDo: aBlock
evaluate aBlock for each file in the directory represented by the receiver.
The block is invoked with a string as argument.
The enumerations order is undefined - i.e. usually NOT sorted by
filenames (but by creation time - on some systems).
This excludes entries for '.' or '..'.
An exception is raised it the directory does not exist..
So users of this method better test for existing directory before.
Notice: this enumerates strings; see also
#directoryContentsAsFilenamesDo:, which enumerates fileName objects.

o  files
return a collection of files contained in the directory represented by the receiver.

o  filesDo: aBlock
evaluate aBlock for all files contained in the directory represented by the receiver.

o  recursiveDirectoryContentsDo: aBlock
evaluate aBlock for all files and directories found under the receiver.
The block is invoked with a string-argument.
The walk is bread-first.
This excludes any entries for '.' or '..'.
Subdirectory files are included with a relative pathname.
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems).

o  recursiveDirectoryContentsDo: aBlock directoryPrefix: aPrefix
evaluate aBlock for all files and directories found under the receiver.
The block is invoked with a string-argument.
The walk is breadth-first.
This excludes any entries for '.' or '..'.
Subdirectory files are included with a relative pathname.
A proceedable exception is raised forn non-accessable directories.
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems).

o  withAllDirectoriesDo: aBlock
evaluate aBlock for myself and all (recursive) directories contained in the directory represented by the receiver.
The block is invoked with a filename-arguments.
The enumerations order within a directory is undefined - i.e. usually NOT sorted by
filenames (but by creation time - on some systems).
This excludes entries for '.' or '..'.
NoOp for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.

error handling
o  accessDeniedError: filename
report an error that access to some file was denied

o  fileCreationError: filename
report an error that some file could not be created

o  fileNotFoundError: filename
report an error that some file was not found

o  removeError: filename
report an error that some file could not be removed

o  reportError: string with: filename
report an error

file access
o  appendStream
return a stream for appending to the file represented by the receiver.
If the file does not already exist, it is created.
Same as #appendingWriteStream for ST-80 compatibility.

o  appendingWriteStream
return a stream for appending to the file represented by the receiver.
If the file does not already exist, it is created;
if it does exist, writes are appended at the end.

o  newReadWriteStream
return a stream for read/write the file represented by the receiver.
If the file does not already exist, it is created;
if it does exist, it is truncated.

o  readStream
return a stream for reading from the file represented by the receiver.
Raises an error if the file does not exist.

o  readWriteStream
return a stream for read/write the file represented by the receiver.
If the file does not already exist, it is created.
If the file does exist, it is NOT truncated, but rewritten at the beginning.

o  writeStream
return a stream for writing to the file represented by the receiver.
If the file does not already exist, it is created;
if it does exist, it is truncated.

file access - migration
o  appendingWriteStreamOrNil
return a stream for appending to the file represented by the receiver.
If the file does not already exist, it is created;
if it does exist, writes are appended at the end.

Return nil, if the file cannot be opened.
Use this method for migration of old smalltalk code that expects a nil return code
instead of an exception when an error occurs.

o  newReadWriteStreamOrNil
return a stream for read/write the file represented by the receiver.
If the file does not already exist, it is created;
if it does exist, it is truncated.

Return nil, if the file cannot be opened.
Use this method for migration of old smalltalk code that expects a nil return code
instead of an exception when an error occurs.

o  readStreamOrNil
return a stream for reading from the file represented by the receiver.
If the file does not already exist, nil is returned.

Return nil, if the file cannot be opened.
Use this method for migration of old smalltalk code that expects a nil return code
instead of an exception when an error occurs.

o  readWriteStreamOrNil
return a stream for read/write the file represented by the receiver.
If the file does not already exist, it is created.
If the file does exist, it is NOT truncated, but rewritten at the beginning

Return nil, if the file cannot be opened.
Use this method for migration of old smalltalk code that expects a nil return code
instead of an exception when an error occurs.

o  writeStreamOrNil
return a stream for writing to the file represented by the receiver.
If the file does not already exist, it is created;
if it does exist, it is truncated.

Return nil, if the file cannot be opened.
Use this method for migration of old smalltalk code that expects a nil return code
instead of an exception when an error occurs.

file accessRights
o  accessRights
return the access rights of the file as opaque data
(SmallInteger in unix/linux)

o  accessRights: opaqueData
set the access rights of the file to opaqueData,
which is normally retrieved by Filename>>#accessRights.

o  addAccessRights: aCollection
add the access rights as specified in aCollection for the file represented
by the receiver. The argument must be a collection of symbols,
such as #readUser, #writeGroup etc.

o  makeExecutable
make the file executable - you must have permission to do so.
For directories, execution means: 'allow changing into it'

o  makeExecutableForAll
make the file executable for all - you must have permission to do so.
For directories, execution means: 'allow changing into it'

o  makeExecutableForGroup
make the file executable for the group - you must have permission to do so.
For directories, execution means: 'allow changing into it'

o  makeReadable
make the file readable for the owner - you must have permission to do so.

o  makeReadableForAll
make the file readable for all - you must have permission to do so.

o  makeReadableForGroup
make the file readable for the group - you must have permission to do so.

o  makeUnwritable
make the file unwritable for all - you must have permission to do so.

o  makeWritable
make the file writableable for all - you must have permission to do so.

o  makeWritableForAll
make the file writable for all - you must have permission to do so.

o  makeWritableForGroup
make the file writable for the group - you must have permission to do so.

o  removeAccessRights: aCollection
remove the access rights as specified in aCollection for the file represented
by the receiver. The argument must be a collection of symbols,
such as #readUser, #writeGroup etc.
Raises an exception if not successful.

o  symbolicAccessRights
return the access rights of the file as a aCollection of access symbols.
The returned collection consists of symbols like:
#readUser, #writeGroup etc.

o  symbolicAccessRights: aCollectionOfSymbols
set the access rights of the file given a aCollection of access symbols.
The collection must consist of symbols like:
#readUser, #writeGroup etc.

file operations
o  appendTo: newNameOrStream
append the file - the argument must be convertable to a filename.
Raises an exception, if an error occurs.

o  basicMakeDirectory
create a directory with the receivers name.
Return true if successful, false if not.

o  copyTo: newNameArg
Copy the files contents into another file.
The argument must be convertable to a filename.
Raises an exception, if an error occurs.

o  createAsEmptyFile
create an empty file with the receivers name.
Raises an exception if not successful
(either already existing or creation not possible)

o  delete
remove the file - same as remove, for ST-80 compatibility

o  makeDirectory
create a directory with the receivers name.
Raises an exception if not successful

o  moveFileTo: newName
copy the file represented by the receiver, then delete it.
This is different to renaming in case of cross device moves.
Raise an exception if not successful.
(Notice, that a rename is tried first, in case of non-cross device move)

o  moveTo: newName
copy the file represented by the receiver, then delete it.
This is different to renaming in case of cross device moves.
Raise an exception if not successful.
(Notice, that a rename is tried first, in case of non-cross device move)

o  recursiveCopyTo: destination
if I represent a regular file, copy it.
Otherwise, copy the directory and recursively
and recursively all of its subfiles/subdirectories.
Raises an exception if not successful.

o  recursiveCopyWithoutOSCommandTo: destination
if I represent a regular file, copy it.
Otherwise, copy the directory and all of its subfiles/subdirectories.
This one walks down the directory hierarchy, not using any OS command to do the copy.
Raises an exception if not successful.

o  recursiveMakeDirectory
create a directory with the receivers name and all required intermediate
directories.
Raises an exception if not successful.

o  recursiveMoveDirectoryTo: newName
recursively copy the directory represented by the receiver, then delete it.
This is different to renaming in case of cross device moves.
Raise an exception if not successful.
(Notice, that a rename is tried first, in case of non-cross device move)

o  recursiveRemove
if I represent a regular file, remove it.
Otherwise, remove the directory and all of its subfiles/subdirectories.
Raise an exception if not successful.

o  recursiveRemoveWithoutOSCommand
if I represent a regular file, remove it.
Otherwise, remove the directory and all of its subfiles/subdirectories.
Raise an error if not successful.
This one walks down the directory hierarchy, not using any OS
command to do the remove.

o  remove
remove the file/directory.
Raises an exception if not successful.
Use #recursiveRemove in order to (recursively) remove non empty directories.

o  removeDirectory
remove the directory.
Raises an exception if not successful (or if its not a directory).
Use #remove if it is not known if the receiver is a directory or file.
Use #recursiveRemove in order to (recursively) remove non empty directories.

o  removeFile
remove the file.
Raises an exception if not successful (or if its not a file).
Use #remove if it is not known if the receiver is a directory or file.
Use #recursiveRemove in order to (recursively) remove non empty directories.

o  renameOrCopyTo: newName
rename or copy the file - the argument must be convertable to a String.
Raises an exception if not successful.
This does basically the same as #renameTo:, with one exception:
if, under unix, the new fileName is on another device, a rename operation
fails, and #renameTo: raises an exception;
in contrast, this method falls back to copying the file.

o  renameTo: newName
rename the file - the argument must be convertable to a String.
Raises an exception if not successful.

o  truncateTo: newSize
change the files size.
This may not be supported on all operating systems
(raises an exception, if not)

file queries
o  accessTime
return a timeStamp containing the files last access time.

o  creationTime
return a timeStamp containing the files creation time.
NOTICE: only windoof distinguishes creation from modification;
under unix, nil is returned (callers should fall back and use mod-time then

o  dates
return the files modification and access times as an object (currently a dictionary)
that responds to the at: message with arguments
#modified, #accessed or #statusChanged.

o  fileSize
return the size of the file in bytes

o  fileType
this returns a string describing the type of contents of
the file. This is done using the unix 'file' command,
(which usually is configurable by /etc/magic).
On non-unix systems, this may simply return 'file',
not knowning about the contents.
Warning:
Since the returned string differs among systems (and language settings),
it is only useful for user-information;
NOT as a tag to be used by a program.

o  id
return the files/directories file-id (inode number)

o  info
return some object filled with the files info;
the info (for which corresponding access methods are understood by
the returned object) is:

type - a symbol giving the files fileType
mode - numeric access mode
uid - owners user id
gid - owners group id
size - files size
id - files number (i.e. inode number)
accessed - last access time (as osTime-stamp)
modified - last modification time (as osTime-stamp)
statusChanged - last staus change (as osTime-stamp)

Some of the fields may be returned as nil on systems which do not provide
all of the information.
The minimum returned info (i.e. on all OS's) will consist of at least:
modified
size
type

Dont expect things like uid/gid/mode to be non-nil; write your application
to either handle nil values,
or (better) use one of isXXXX query methods. (Be prepared for DOS ...)
(i.e. instead of:
someFilename type == #directory
use
someFilename isDirectory

o  linkInfo
return the files info. If it is a symbolic link return the info of the link itself
instead of the link's target.
The information is the same as returned by #info, except that if the
receiver represents a symbolic link, the links information
is returned
(while in this case, #info returns the info of the target file,
which is accessed via the symbolic link).

In addition to the normal entries, Unix returns an additional entry:
path -> the target files pathname

See the comment in #info for more details.

o  modificationTime
return a timeStamp containing the files modification time.

o  type
return the symbolic type of the file

file utilities
o  edit
start an editView on the file represented by the receiver

o  fileIn
load smalltalk code from the file

instance creation
o  / subname
Same as construct: Taking the receiver as a directory name, construct a new
filename for an entry within this directory
(i.e. for a file or a subdirectory in that directory).
The argument may not specify an absolute path name.
Please do not use this to create filenames with suffixes,
since some systems require special naming conventions.
See also: #withSuffix: (which is different, but often needed).
Thanks to Jan Vrany for this idea.

o  construct: subname
taking the receiver as a directory name, construct a new
filename for an entry within this directory
(i.e. for a file or a subdirectory in that directory).
The argument may not specify an absolute path name.
Please do not use this to create filenames with suffixes,
since some systems require special naming conventions.
See also: #withSuffix: (which is different, but often needed).

o  constructDirectory: subname
same as #construct: on most systems.
(may allow different/relaxed name syntax of the argument on some systems)

o  constructDirectoryString: subName
same as #constructString: on most systems.
(may allow different/relaxed name syntax of the argument on some systems)

o  constructString: subName
taking the receiver as a directory name, construct a new
filename-string for an entry within this directory
(i.e. for a file or a subdirectory in that directory).
The argument may not specify an absolute path name.
The code below works for UNIX & MSDOS;
other filename classes (i.e. VMS) may want to redefine this method.

o  filenameFor: fileName
return a filename representing the argument, fileName
either in myself (if the arg is a releative path) or absolute otherwise.

o  secureConstruct: subname
taking the receiver as a directory name, construct a new
filename for an entry within this directory
(i.e. for a file or a subdirectory in that directory).
The argument may not specify an absolute path name.
Please do not use this to create filenames with suffixes,
since some systems require special naming conventions.
See also: #withSuffix: (which is different, but often needed).

This method differs from #construct:, by not permitting subName
to navigate above (via ..) the current filename.

o  secureConstructString: subName
taking the receiver as a directory name, construct a new
filename-string for an entry within this directory
(i.e. for a file or a subdirectory in that directory).

This method differs from #constructString, by not permitting subName
to navigate above (via ..) the current filename.

The code below works for UNIX & MSDOS;
other filename classes (i.e. VMS) may want to redefine this method.

misc
o  , aString
this allows filenames to understand how names are concatenated.
Returns a string consisting of the receivers name, concatenated
by aString. Notice this is NOT the same as construct:, which inserts
a directory delimiter and returns a new fileName instance.
See also: #withSuffix: which is new and better.

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  canonicalize
normalize a filename by removing all empty path components or dots,
and by resolving parent directory '..' references.

The code below works for UNIX & MSDOS;
other filename classes (i.e. VMS) may want to redefine this method.

printing & storing
o  printOn: aStream
append a user printed representation of the receiver to aStream.
The format is suitable for a human - not meant to be read back.

o  storeOn: aStream
append a printed representation of the receiver to aStream,
which allows reconstructing it via readFrom:

private-accessing
o  getName
get the raw filename

o  setName: aString
set the filename

queries
o  exists
return true, if such a file exists.

o  filenamesMatching: aPattern
VW compatibility

o  filesMatching: aPattern
given the receiver, representing a directory;
return a collection of files matching a pattern.
The pattern may be a simple matchPattern, or a set of
multiple patterns separated by semicolons.

o  filesMatchingWithoutDotDirs: aPattern
given the receiver, representing a directory;
return a collection of files matching a pattern.
Exclude '.' and '..' from the returned list.
The pattern may be a simple matchPattern, or a set of
multiple patterns separated by semicolons.

o  fullAlternativePathName

o  isExecutable
return true, if such a file exists and is executable (by Unix's definition).
For directories, true is returned if the directory can be entered.
See isExecutableProgram for a related check.

o  isExecutableProgram
return true, if such a file exists and is an executable program.
(i.e. for directories, false is returned.)

o  isHidden
return true, if the receiver represents a hidden file.
The definitions of hidden files depends on the OS used;
on UNIX, a name starting with a period is considered hidden;
on MSDOS, the files hidden attribute is also used.
VMS has no concept of hidden files.

o  isMountPoint: aPathName
return true, if I represent a mount-point.
Warning:
the receiver must be an absolute pathname,
because a realPath is not used/generated for the query (to avoid automounting).
Aka: do not ask: '../../' asFilename isMountPoint;

o  isReadable
return true, if such a file exists and is readable.

o  isSharedLibrary
return true, if such a file exists and is a shared library.

o  isWritable
return true, if such a file exists and is writable.

o  nameWithSpecialExpansions: aString
return the nameString, expanding any OS specific macros.
Here, a ~\ prefix is expanded to the users home dir (as in csh)

o  separator
return the directory-separator character

o  species

o  withSpecialExpansions
return a new filename, expanding any OS specific macros.
Here, a ~\ prefix is expanded to the users home dir (as in csh)

queries-contents
o  mimeTypeFromName
return the mimeType as guessed from the files name/and or extension.
This could be less accurate than mimeTypeOfContents, but avoids
reading the file (is therefore much faster).
Also it works with non-existing files.
Returns nil for directories and other non-regular files.

o  mimeTypeOfContents
this tries to guess the mime type of contents of
the file. Returns nil, if the file is unreadable, not a plain file
or the contents is unknown.
This is done using some heuristics, and may need some improvement

queries-path & name
o  baseName
return my baseName as a string.
- thats the file/directory name without leading parent-dirs.
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file'
and '/usr/lib' asFilename baseName -> lib).
This method does not check if the path is valid.
The code here should work for Unix and MSDOS, but needs to be redefined
for VMS (and maybe others as well).
See also: #pathName, #directoryName and #directoryPathName.
Compatibility note: use #tail for ST-80 compatibility.

o  directory
return the directory name part of the file/directory as a new filename.
- thats a filename for the directory where the file/dir represented by
the receiver is contained in.
(this is almost equivalent to #directoryName or #head, but returns
a Filename instance instead of a string ).

o  directoryName
return the directory name part of the file/directory as a string.
- thats the name of the directory where the file/dir represented by
the receiver is contained in.
This method does not check if the path is valid.

(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
and '/usr/lib' asFilename directoryName -> /usr').

(this is almost equivalent to #directory, but returns
a string instead of a Filename instance).

See also: #pathName, #directoryPathName and #baseName.
Compatibility note: use #head for ST-80 compatibility.

o  directoryPathName
return the full directory pathname part of the file/directory as a string.
- thats the full pathname of the directory where the file/dir represented by
the receiver is contained in.
See also: #pathName, #directoryName, #directory and #baseName

o  filenameCompletion
try to complete the receiver filename.
BAD DESIGN: has side effect on the receiver.
This method has both a return value and a side effect on the receiver:
it returns a collection of matching filename objects,
and changes the receivers filename-string to the longest common
match.
If none matches, the returned collection is empty and the recevier is unchanged.
If there is only one match, the size of the returned collection is exactly 1,
containing the fully expanded filename and the receivers name is changed to it.

o  filenameCompletionIn: aDirectory
try to complete the receiver filename.

BAD DESIGN: has side effect on the receiver.
This method has both a return value and a side effect on the receiver:
it returns a collection of matching filename objects,
and changes the receiver's filename-string to the longest common match.
If none matches, the returned collection is empty and the receiver is unchanged.
If there is only one match, the size of the returned collection is exactly 1,
containing the fully expanded filename and the receiver's name is changed to it.
An empty baseName pattern (i.e. giving the name of a directory) will also return an empty matchset.

o  head
return the directory name as a string.
An alias for directoryName, for ST-80 compatiblity.
(this is almost equivalent to #directory, but returns
a string instead of a Filename instance)

o  isAbsolute
return true, if the receiver represents an absolute pathname
(in contrast to one relative to the current directory).

o  isExplicitRelative
return true, if this name is an explicit relative name
(i.e. starts with './' or '../', to avoid path-prepending)

o  isImplicit
return true, if the receiver represents a builtin file.
The definitions of builtin files depends on the OS used;
on UNIX, '.' and '..' are builtin names.

o  isParentDirectoryOf: aFilenameOrString
warning: may lead to automounting

o  isRelative
return true, if this name is interpreted relative to some
directory (opposite of absolute)

o  isRootDirectory
return true, if I represent the root directory
(i.e. I have no parentDir)

o  isVolumeAbsolute
return true, if the receiver represents an absolute pathname
on some disk volume (MSDOS only)

o  localPathName
return the full pathname of the file represented by the receiver,
but without any volume information.
Only makes a difference on MSDOS & VMS systems.

o  name
return the name of the file represented by the receiver as a string.
This may or may not be a relative name (i.e. include ..'s).
See also: pathName

o  nameString
raw access to nameString - req'd for xml-store/reload

o  nameString: aString
raw access to nameString - req'd for xml-store/reload

o  pathName
return the full pathname of the file represented by the receiver,
as a string. This will not include ..'s.
If the path represented by the receiver does NOT represent a valid path,
no compression will be done (for now; this may change).
See also: name

o  physicalFilename
return the fileName representing the physical file as represented by the receiver,
If the receiver represents a symbolic link, thats the fileName of the
final target. Otherwise, its the receivers pathName itself.
If any file along the symbolic path does not exist (i.e. is a broken link),
nil is returned.

o  physicalPathName
return the full pathname of the physical file represented by the receiver,
If the receiver represents a symbolic link, thats the fileName of the
final target. Otherwise, its the receivers pathName itself.
If any file along the symbolic path does not exist (i.e. is a broken link),
nil is returned.

o  tail
the files name without directory prefix as a string.
An alias for baseName, for ST-80 compatiblity.

o  tail: nComponents
return the last n components of myself.
- thats the file/directory name without leading parent-dirs.
(i.e. '/usr/lib/st/file' asFilename tail:2 -> 'st/file'
and '/usr/lib' asFilename tail:1 -> lib).
This method does not check if the path is valid.
The code here should work for Unix and MSDOS, but needs to be redefined
for VMS (and maybe others as well).
See also: #pathName, #directoryName and #directoryPathName.

o  volume
return the disc volume part of the name or an empty string.
This is only used with MSDOS and VMS filenames
- by default (and on unix), an empty string is returned

queries-type
o  isDirectory
return true, if the receiver represents an existing,
readable directories pathname.

o  isNonEmptyDirectory
return true, if the receiver represents an existing,
readable directories pathname, and the directory is not empty.

o  isRegularFile
return true, if the receiver represents a plain, regular file

o  isSpecialFile
return true, if the receiver represents a socket, named pipe, fifo
or device special file (i.e. anything non regular and non-directory)

o  isSymbolicLink
return true, if the file represented by the receiver is a symbolic
link. Notice that not all OS's support symbolic links; those that do
not will always return false.

reading-directories
o  directoryContents
return the contents of the directory as a collection of strings.
This excludes any entries for '.' or '..'.
Returns nil for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.
Notice:
this returns the file-names as strings;
see also #directoryContentsAsFilenames, which returns fileName instances.

o  directoryContentsAsFilenames
return the contents of the directory as a collection of filenames.
This excludes any entries for '.' or '..'.
Returns nil for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.
Notice:
this returns the file-names as fileName instances;
see also #directoryContents, which returns strings.

o  fullDirectoryContents
return the full contents of the directory as a collection of strings.
This is much like #directoryContents, but includes an entry for the
parent directory, if there is one.
Returns nil for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.

o  recursiveDirectoryContents
return the contents of the directory and all subdirectories
as a collection of strings.
This excludes any entries for '.' or '..'.
Subdirectory files are included with a relative pathname.
Notice:
this returns the file-names as strings;
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances.

Warning: this may take a long time to execute.

o  recursiveDirectoryContentsAsFilenames
return the contents of the directory and all subdirectories
as a collection of filenames.
This excludes any entries for '.' or '..'.
Returns nil for non-existing directories; however, this behavior
may be changed in the near future, to raise an exception instead.
So users of this method better test for existing directory before.
Notice:
this returns the file-names as fileName instances;
see also #recursiveDirectoryContents, which returns strings.

Warning: this may take a long time to execute.

reading-files
o  binaryContentsOfEntireFile
return the binary contents of the file (as a byteArray);
Raises an error, if the file is unreadable/non-existing.

o  contents
return the contents of the file as a collection of lines;
Raises an error, if the file is unreadable/non-existing.
See also #contentsOfEntireFile, which returns a string for textFiles.
CAVEAT: bad naming - but req'd for VW compatibility.

o  contentsAsString
to compensate for the bad naming, use this to make things explicit.
See also #contents, which returns the lines as stringCollection for textFiles.

o  contentsOfEntireFile
return the contents of the file as a string;
Raises an error, if the file is unreadable/non-existing.
See also #contents, which returns the lines as stringCollection for textFiles.
CAVEAT: bad naming - but req'd for VW compatibility.

o  readingFileDo: aBlock
create a read-stream on the receiver file, evaluate aBlock, passing that stream as arg,
and return the blocks value.
If the file cannot be opened, an exception is raised or
(old behavior, will vanish:)the block is evaluated with a nil argument.
Ensures that the stream is closed.

o  readingLinesDo: aBlock
create a read-stream on the receiver file,
evaluate aBlock for each line read from the stream.
If the file cannot be opened, an error is raised.
Ensures that the stream is closed.

special accessing
o  osName
special - return the OS's name for the receiver.

o  osNameForAccess
internal - return the OS's name for the receiver to
access its fileInfo.
This may be redefined for systems, where a special suffix must be
added in order to access directories (or others) as a file.
(i.e. under VMS, a '.dir' suffix is added to access directories)

o  osNameForDirectory
internal - return the OS's name for the receiver to
access it as a directory.

o  osNameForDirectoryContents
internal - return the OS's name for the receiver to
access it as a directory when reading its contents.

o  osNameForFile
internal - return the OS's name for the receiver to
access it as a file.

suffixes
o  addSuffix: aSuffix
return a new filename for the receivers name with a different suffix.
If the name already has a suffix, the new suffix replaces it;
otherwise, the new suffix is simply appended to the name.

o  hasSuffix: aSuffixString
return true if my suffix is the same as aString.
This cares for systems, where case is ignored in filenames

o  nameWithoutSuffix
return the receivers name without the suffix.
If the name has no suffix, the original name is returned.

o  prefix
return my prefix.
The suffix is the namepart after the final period character,
or the empty string, if the name does not contain a period.

o  prefixAndSuffix
return an array consisting of my prefix and suffix.
The suffix is the namepart after the final period character,
the prefix everything before, except for the period.
The directory name part is stripped off (i.e. the returned prefix
will consist of the files basename only.)
(on some systems, the suffix-character may be different from a period).
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'.
An exception to the above: if the name starts with the suffixCharacter,
that part is NOT considered a suffix. Thus, '.foorc' has no suffix and a prefix of
'.foorc'.
See also: #withoutSuffix and #withSuffix
Notice:
there is currently no known system which uses other than
the period character as suffixCharacter.

o  suffix
return my suffix.
The suffix is the namepart after the final period character,
or the empty string, if the name does not contain a period.

o  withSuffix: aSuffix
return a new filename for the receivers name with a different suffix.
If the name already has a suffix, the new suffix replaces it;
otherwise, the new suffix is simply appended to the name.

o  withoutSuffix
return a new filename for the receivers name without the suffix.
If the name has no suffix, a filename representing the same file as the receiver is returned.

testing
o  isFilename
return true, if the receiver is some kind of filename;
false is returned here - the method is redefined from Object.

writing-files
o  contents: aStringOrCollectionOfLines
create (or overwrite) a file given its contents as a collection of lines.
Raises an error, if the file is unwritable.

o  writingFileDo: aBlock
create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg,
and return the blocks value.
If the file cannot be opened, an exception is raised.
Ensures that the stream is closed.


Examples:


does a file/directory exist ?:


    |f|

    f := 'foobar' asFilename.
    ^ f exists  
is it a directory ?:


    |f|

    f := '/tmp' asFilename.
    ^ f isDirectory.   
get the working directory:


    ^ Filename defaultDirectory
get a files full pathname (caring for relative names or symbolic links):


    |f|

    f := '..' asFilename.
    ^ f pathName  
get a directories directory:


    |f|

    f := Filename defaultDirectory.
    ^ f directory 
get a files directory:


    |f|

    f := './smalltalk' asFilename.
    ^ f directory 
getting access & modification times:


    |f|

    f := '/tmp' asFilename.
    ^ f dates
access time only:


    |f|

    f := '/tmp' asFilename.
    ^ f dates at:#accessed  
getting all information on a file/directory:


    |f|

    f := '/tmp' asFilename.
    ^ f info
getting a temporary file (unique name):


    |f|

    f := Filename newTemporary.
    ^ f    
creating, writing, reading and removing a temporary file:


    |f writeStream readStream|

    f := Filename newTemporary.
    writeStream := f writeStream.
    writeStream nextPutAll:'hello world'.
    writeStream cr.
    writeStream close.

    'contents (as seen by unix''s cat command:' printNL.
    OperatingSystem executeCommand:('cat ' , f pathName).

    readStream := f readStream.
    Transcript showCR:'contents as seen by smalltalk:'.
    Transcript showCR:(readStream upToEnd).
    readStream close.

    f delete.
getting a directories contents:


    |f files|

    f := Filename currentDirectory.
    files := f directoryContents.
    Transcript showCR:'the files are:'.
    Transcript showCR:(files printString).
editing a file:


    |f|

    f := Filename newTemporary.
    (f writeStream) nextPutAll:'hello world'; close.

    f edit


ST/X 6.1.1; WebServer 1.620 at exept:8081; Mon, 21 May 2012 16:38:18 GMT