1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Filename
|
|
14 |
instanceVariableNames:'name'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'ST-80 compatibility'!
|
|
18 |
|
|
19 |
Filename comment:'
|
|
20 |
|
5
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
22 |
All Rights Reserved
|
|
23 |
|
2
|
24 |
Filenames; originally added for ST-80 compatibility, is
|
|
25 |
taking over functionality from other classes (FileDirectory).
|
1
|
26 |
|
54
|
27 |
$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.6 1994-02-25 12:58:46 claus Exp $
|
1
|
28 |
'!
|
|
29 |
|
|
30 |
!Filename class methodsFor:'instance creation'!
|
|
31 |
|
2
|
32 |
currentDirectory
|
38
|
33 |
"return a filename for the current directory"
|
|
34 |
|
2
|
35 |
^ (self basicNew) name:(FileDirectory currentDirectory pathName)
|
38
|
36 |
|
|
37 |
"Filename currentDirectory"
|
2
|
38 |
!
|
|
39 |
|
1
|
40 |
named:aString
|
38
|
41 |
"return a filename for a directory named aString"
|
|
42 |
|
1
|
43 |
^ (self basicNew) name:aString
|
38
|
44 |
|
|
45 |
"Filename named:'/tmp/fooBar'"
|
1
|
46 |
! !
|
|
47 |
|
2
|
48 |
!Filename class methodsFor:'queries'!
|
|
49 |
|
|
50 |
separator
|
|
51 |
"return the file/directory separator."
|
|
52 |
|
|
53 |
^ OperatingSystem fileSeparator
|
38
|
54 |
|
|
55 |
"Filename separator"
|
2
|
56 |
! !
|
|
57 |
|
|
58 |
!Filename methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
construct:subname
|
38
|
61 |
"taking the receiver as a directory name, construct a new
|
|
62 |
filename for an entry within this directory (i.e. for a file
|
|
63 |
or a subdirectory in that directory)."
|
|
64 |
|
|
65 |
^ (self class basicNew) name:(name , self class separator asString , subname)
|
|
66 |
|
|
67 |
"('/tmp' asFilename construct:'foo') asString"
|
2
|
68 |
! !
|
|
69 |
|
1
|
70 |
!Filename methodsFor:'converting'!
|
|
71 |
|
|
72 |
asString
|
38
|
73 |
"return the receiver converted to a string"
|
|
74 |
|
1
|
75 |
^ name
|
|
76 |
!
|
|
77 |
|
|
78 |
asFilename
|
38
|
79 |
"return the receiver converted to a filename"
|
|
80 |
|
1
|
81 |
^ self
|
|
82 |
! !
|
|
83 |
|
|
84 |
!Filename methodsFor:'private accessing'!
|
|
85 |
|
|
86 |
name:aString
|
38
|
87 |
"set the filename"
|
|
88 |
|
1
|
89 |
name := aString
|
|
90 |
! !
|
|
91 |
|
2
|
92 |
!Filename methodsFor:'queries'!
|
|
93 |
|
|
94 |
directoryName
|
|
95 |
"return the directoryName of the argument, aPath
|
|
96 |
- thats the name of the directory where aPath is"
|
|
97 |
|
|
98 |
^ OperatingSystem directoryNameOf:name
|
|
99 |
!
|
|
100 |
|
|
101 |
baseName
|
|
102 |
"return my baseName
|
|
103 |
- thats the file/directory name without leading parent-dirs"
|
|
104 |
|
|
105 |
^ OperatingSystem baseNameOf:name
|
|
106 |
! !
|
|
107 |
|
1
|
108 |
!Filename methodsFor:'file access'!
|
|
109 |
|
2
|
110 |
renameTo:newName
|
|
111 |
"rename the file - the argument must be convertable to a String"
|
|
112 |
|
54
|
113 |
^ OperatingSystem renameFile:name to:(newName asString)
|
2
|
114 |
|
|
115 |
"'/tmp/foo asFileName renameTo:'/tmp/bar'"
|
|
116 |
!
|
|
117 |
|
1
|
118 |
exists
|
|
119 |
"return true, if such a file exists"
|
|
120 |
|
|
121 |
^ OperatingSystem isValidPath:name
|
|
122 |
!
|
|
123 |
|
|
124 |
fileIn
|
2
|
125 |
"load smalltalk code from the file"
|
|
126 |
|
|
127 |
^ self readStream fileIn
|
1
|
128 |
!
|
|
129 |
|
|
130 |
readStream
|
2
|
131 |
"return a stream for reading"
|
|
132 |
|
1
|
133 |
^ FileStream readonlyFileNamed:name
|
|
134 |
!
|
|
135 |
|
|
136 |
writeStream
|
2
|
137 |
"return a stream for writing"
|
|
138 |
|
1
|
139 |
^ FileStream newFileNamed:name
|
|
140 |
! !
|