Filename.st
author claus
Fri, 25 Feb 1994 13:58:55 +0100
changeset 54 06dbdeeed4f9
parent 38 454b1b94a48e
child 68 59faa75185ba
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 1992 by Claus Gittinger
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

Object subclass:#Filename
         instanceVariableNames:'name'
         classVariableNames:''
         poolDictionaries:''
         category:'ST-80 compatibility'!

Filename comment:'

COPYRIGHT (c) 1992 by Claus Gittinger
             All Rights Reserved

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

$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.6 1994-02-25 12:58:46 claus Exp $
'!

!Filename class methodsFor:'instance creation'!

currentDirectory
    "return a filename for the current directory"

    ^ (self basicNew) name:(FileDirectory currentDirectory pathName)

    "Filename currentDirectory"
!

named:aString
    "return a filename for a directory named aString"

    ^ (self basicNew) name:aString

    "Filename named:'/tmp/fooBar'"
! !

!Filename class methodsFor:'queries'!

separator
    "return the file/directory separator."

     ^ OperatingSystem fileSeparator

     "Filename separator"
! !

!Filename methodsFor:'instance creation'!

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)."

    ^ (self class basicNew) name:(name , self class separator asString , subname)

    "('/tmp' asFilename construct:'foo') asString"
! !

!Filename methodsFor:'converting'!

asString
    "return the receiver converted to a string"

    ^ name
!

asFilename
    "return the receiver converted to a filename"

    ^ self
! !

!Filename methodsFor:'private accessing'!

name:aString
    "set the filename"

    name := aString
! !

!Filename methodsFor:'queries'!

directoryName
    "return the directoryName of the argument, aPath
     - thats the name of the directory where aPath is"

    ^ OperatingSystem directoryNameOf:name
!

baseName
    "return my baseName
     - thats the file/directory name without leading parent-dirs"

    ^ OperatingSystem baseNameOf:name
! !

!Filename methodsFor:'file access'!

renameTo:newName
    "rename the file - the argument must be convertable to a String"

    ^ OperatingSystem renameFile:name to:(newName asString)

    "'/tmp/foo asFileName renameTo:'/tmp/bar'"
!

exists
    "return true, if such a file exists"

    ^ OperatingSystem isValidPath:name
!

fileIn
    "load smalltalk code from the file"

    ^ self readStream fileIn
!

readStream
    "return a stream for reading"

    ^ FileStream readonlyFileNamed:name
!

writeStream
    "return a stream for writing"

    ^ FileStream newFileNamed:name
! !