author | Claus Gittinger <cg@exept.de> |
Mon, 04 Dec 1995 11:25:22 +0100 | |
changeset 672 | 964a9e78398a |
parent 671 | 53de87163ad5 |
child 844 | 8833550c4e01 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
|
159 | 14 |
instanceVariableNames:'nameString' |
276 | 15 |
classVariableNames:'NextTempFilenameIndex' |
159 | 16 |
poolDictionaries:'' |
615 | 17 |
category:'System-Support' |
18 |
! |
|
1 | 19 |
|
88 | 20 |
!Filename class methodsFor:'documentation'! |
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 25 |
All Rights Reserved |
1 | 26 |
|
88 | 27 |
This software is furnished under a license and may be used |
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
Filenames; originally added for ST-80 compatibility, is |
|
39 |
taking over functionality from other classes (FileDirectory). |
|
92 | 40 |
|
41 |
Instances of Filename do not nescessarily represent valid or existing |
|
42 |
files - i.e. it is possible (and useful) to have instances for non-existing |
|
43 |
files around. In other words: the name-string is not checked automatically |
|
44 |
for being correct or existing. |
|
45 |
Thus, it is possible to do queries such as: |
|
46 |
||
159 | 47 |
'/fee/foo/foe' asFilename exists |
48 |
'/not_existing' asFilename isDirectory |
|
49 |
'/foo/bar' asFilename isReadable |
|
92 | 50 |
|
195 | 51 |
(all of the above examples will probably return false on your machine ;-). |
276 | 52 |
|
53 |
examples: |
|
54 |
||
55 |
'Makefile' asFilename readStream |
|
56 |
||
57 |
'newFile' asFilename writeStream |
|
58 |
||
59 |
Filename newTemporary writeStream |
|
88 | 60 |
" |
360 | 61 |
! |
62 |
||
63 |
examples |
|
64 |
" |
|
65 |
does a file/directory exist ?: |
|
66 |
||
67 |
|f| |
|
68 |
||
69 |
f := 'foobar' asFilename. |
|
70 |
^ f exists |
|
71 |
||
72 |
||
73 |
is it a directory ?: |
|
74 |
||
75 |
|f| |
|
76 |
||
77 |
f := '/tmp' asFilename. |
|
78 |
^ f isDirectory. |
|
79 |
||
80 |
||
81 |
get the working directory: |
|
82 |
||
83 |
^ Filename defaultDirectory |
|
84 |
||
85 |
||
86 |
get a files full pathname |
|
87 |
(caring for relative names or symbolic links): |
|
88 |
||
89 |
|f| |
|
90 |
||
91 |
f := '..' asFilename. |
|
92 |
^ f pathName |
|
93 |
||
94 |
||
95 |
get a directories directory: |
|
96 |
||
97 |
|f| |
|
98 |
||
99 |
f := Filename defaultDirectory. |
|
100 |
^ f directory |
|
101 |
||
102 |
||
103 |
get a files directory: |
|
104 |
||
105 |
|f| |
|
106 |
||
107 |
f := './smalltalk' asFilename. |
|
108 |
^ f directory |
|
109 |
||
110 |
||
111 |
getting access & modification times: |
|
112 |
||
113 |
||
114 |
|f| |
|
115 |
||
116 |
f := '/tmp' asFilename. |
|
117 |
^ f dates |
|
118 |
||
119 |
access time only: |
|
120 |
||
121 |
|f| |
|
122 |
||
123 |
f := '/tmp' asFilename. |
|
124 |
^ f dates at:#accessed |
|
125 |
||
126 |
||
127 |
getting all information on a file/directory: |
|
128 |
||
129 |
||
130 |
|f| |
|
131 |
||
132 |
f := '/tmp' asFilename. |
|
133 |
^ f info |
|
134 |
||
135 |
||
136 |
getting a temporary file (unique name): |
|
137 |
||
138 |
|f| |
|
139 |
||
140 |
f := Filename newTemporary. |
|
141 |
^ f |
|
142 |
||
143 |
||
144 |
creating, writing, reading and removing a temporary file: |
|
145 |
||
146 |
||
147 |
|f writeStream readStream| |
|
148 |
||
149 |
f := Filename newTemporary. |
|
150 |
writeStream := f writeStream. |
|
151 |
writeStream nextPutAll:'hello world'. |
|
152 |
writeStream cr. |
|
153 |
writeStream close. |
|
154 |
||
155 |
'contents (as seen by unix''s cat command:' printNL. |
|
156 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
157 |
||
158 |
readStream := f readStream. |
|
159 |
Transcript showCr:'contents as seen by smalltalk:'. |
|
160 |
Transcript showCr:(readStream upToEnd). |
|
161 |
readStream close. |
|
162 |
||
163 |
f delete. |
|
164 |
||
165 |
||
166 |
getting a directories contents: |
|
167 |
||
168 |
|f files| |
|
169 |
||
170 |
f := '.' asFilename. |
|
171 |
files := f directoryContents. |
|
172 |
Transcript showCr:'the files are:'. |
|
173 |
Transcript showCr:(files printString). |
|
174 |
||
175 |
||
176 |
editing a file: |
|
177 |
||
178 |
|f| |
|
179 |
||
180 |
f := '/tmp/fooBar' asFilename. |
|
181 |
(f writeStream) nextPutAll:'hello world'; close. |
|
182 |
||
183 |
f edit |
|
184 |
" |
|
88 | 185 |
! ! |
1 | 186 |
|
187 |
!Filename class methodsFor:'instance creation'! |
|
188 |
||
276 | 189 |
currentDirectory |
190 |
"return a filename for the current directory" |
|
191 |
||
192 |
^ self named:(FileDirectory currentDirectory pathName) |
|
193 |
||
194 |
" |
|
195 |
Filename currentDirectory |
|
196 |
" |
|
197 |
! |
|
198 |
||
328 | 199 |
defaultDirectory |
200 |
"ST80 compatibility: same as currentDirectory" |
|
201 |
||
202 |
^ self currentDirectory |
|
203 |
||
204 |
" |
|
205 |
Filename defaultDirectory |
|
206 |
" |
|
207 |
! |
|
208 |
||
542 | 209 |
defaultDirectoryName |
210 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
|
211 |
||
212 |
^ self defaultDirectory name |
|
213 |
||
214 |
" |
|
215 |
Filename defaultDirectoryName |
|
216 |
" |
|
217 |
! |
|
218 |
||
615 | 219 |
fromUser |
220 |
"show a box to enter a filename. Return a filename instance or |
|
221 |
nil (if cancel was pressed)." |
|
222 |
||
223 |
|name| |
|
224 |
||
225 |
name := FileSelectionBox requestFilename. |
|
226 |
name notNil ifTrue:[^ self named:name]. |
|
227 |
^ nil |
|
228 |
||
229 |
" |
|
230 |
Filename fromUser |
|
231 |
" |
|
232 |
! |
|
233 |
||
234 |
named:aString |
|
235 |
"return a filename for a directory named aString. |
|
236 |
This is the same as 'aString asFilename'." |
|
237 |
||
238 |
^ (self basicNew) setName:aString |
|
239 |
||
240 |
" |
|
241 |
Filename named:'/tmp/fooBar' |
|
242 |
" |
|
243 |
! |
|
244 |
||
276 | 245 |
newTemporary |
325 | 246 |
"return a new unique filename - use this for temporary files. |
247 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
248 |
unix process id, and nn is a unique number, incremented with every |
|
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
249 |
call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
250 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
251 |
its value defines the temp directory." |
276 | 252 |
|
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
253 |
|tempDir| |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
254 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
255 |
tempDir := OperatingSystem getEnvironment:'ST_TMPDIR'. |
422 | 256 |
tempDir isNil ifTrue:[ |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
257 |
tempDir := OperatingSystem getEnvironment:'TMPDIR'. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
258 |
tempDir isNil ifTrue:[ |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
259 |
tempDir := '/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
260 |
]. |
422 | 261 |
]. |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
262 |
^ self newTemporaryIn:tempDir |
276 | 263 |
|
264 |
" |
|
422 | 265 |
Filename newTemporary |
266 |
Filename newTemporary |
|
276 | 267 |
" |
422 | 268 |
|
269 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
270 |
"Modified: 4.11.1995 / 20:08:51 / cg" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
271 |
! |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
272 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
273 |
newTemporaryIn:aDirectoryPrefix |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
274 |
"return a new unique filename - use this for temporary files. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
275 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
276 |
where xx is our unix process id, and nn is a unique number, incremented |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
277 |
with every call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
278 |
Notice: only a filename object is created and returned - no physical |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
279 |
file is created by this method (i.e. you have to send #writeStream or |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
280 |
whatever to it in order to really create something). |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
281 |
See also: #newTemporary which looks for a good temp directory." |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
282 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
283 |
|pid nm| |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
284 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
285 |
NextTempFilenameIndex isNil ifTrue:[ |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
286 |
NextTempFilenameIndex := 1. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
287 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
288 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
289 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
290 |
the following has to be made OS independent ... |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
291 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
292 |
pid := OperatingSystem getProcessId printString. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
293 |
nm := 'stxtmp_' , pid , '_' , NextTempFilenameIndex printString. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
294 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
295 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
296 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
297 |
nm := aDirectoryPrefix asFilename construct:nm |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
298 |
] ifTrue:[ |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
299 |
nm := nm asFilename |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
300 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
301 |
^ nm |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
302 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
303 |
"temp files in '/tmp': |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
304 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
305 |
Filename newTemporary |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
306 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
307 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
308 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
309 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
310 |
"temp files somewhere (not recommended): |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
311 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
312 |
Filename newTemporaryIn:'/usr/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
313 |
Filename newTemporaryIn:'/' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
314 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
315 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
316 |
"a local temp file: |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
317 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
318 |
Filename newTemporaryIn:'' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
319 |
Filename newTemporaryIn:nil |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
320 |
Filename newTemporaryIn:'.' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
321 |
Filename newTemporaryIn:('source' asFilename) |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
322 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
323 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
324 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
325 |
"Modified: 4.11.1995 / 20:26:23 / cg" |
1 | 326 |
! ! |
327 |
||
2 | 328 |
!Filename class methodsFor:'queries'! |
329 |
||
326 | 330 |
defaultClass |
331 |
"ST-80 compatibility: |
|
422 | 332 |
in ST-80, different subclasses of Filename are used for different |
333 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
|
326 | 334 |
Since in ST/X, there is (currently) only one Filename class, return it here." |
335 |
||
336 |
^ self |
|
328 | 337 |
! |
338 |
||
440 | 339 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
340 |
"perform filename completion on aString in some directory; |
|
341 |
return the longest matching filename prefix as a string. |
|
342 |
If directoriesOnly and filesOnly are true, only directories and files |
|
343 |
are considered respectively. If multiple files match, the exception |
|
344 |
block aBlock is evaluated with a filename representing the directory |
|
345 |
(where the match was done) as argument. |
|
346 |
(this may be different from the inDirectory argument, if aString is absolute |
|
347 |
or starts with ../)" |
|
348 |
||
349 |
|s f matchSet nMatch name words dir| |
|
350 |
||
351 |
s := aString. |
|
352 |
" |
|
353 |
find the last word ... |
|
354 |
" |
|
355 |
words := s asCollectionOfWords. |
|
356 |
words size == 0 ifTrue:[ |
|
473
f92507d781d2
filenameCompletion: bad return value when called with empty string
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
357 |
aBlock value:'.' asFilename. |
f92507d781d2
filenameCompletion: bad return value when called with empty string
Claus Gittinger <cg@exept.de>
parents:
441
diff
changeset
|
358 |
^ '' |
440 | 359 |
]. |
360 |
||
361 |
f := words last asFilename. |
|
362 |
||
363 |
matchSet := f filenameCompletionIn:inDirectory. |
|
364 |
||
365 |
dir := f directory. |
|
366 |
||
367 |
directoriesOnly ifTrue:[ |
|
368 |
matchSet := matchSet select:[:aFilename | |
|
369 |
(dir construct:aFilename) isDirectory |
|
370 |
]. |
|
371 |
] ifFalse:[ |
|
372 |
filesOnly ifTrue:[ |
|
373 |
matchSet := matchSet select:[:aFilename | |
|
374 |
(dir construct:aFilename) isDirectory not |
|
375 |
]. |
|
376 |
] |
|
377 |
]. |
|
378 |
||
379 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
380 |
" |
|
381 |
more than one possible completion - |
|
382 |
" |
|
383 |
aBlock value:f |
|
384 |
]. |
|
385 |
" |
|
386 |
even with more than one possible completion, |
|
387 |
f's name is now the common prefix |
|
388 |
" |
|
389 |
name := f asString. |
|
390 |
nMatch == 1 ifTrue:[ |
|
391 |
" |
|
392 |
exactly one possible completion - |
|
393 |
" |
|
394 |
f := dir construct:matchSet first. |
|
395 |
||
396 |
directoriesOnly ifFalse:[ |
|
397 |
f isDirectory ifTrue:[ |
|
398 |
(name endsWith:(Filename separator)) ifFalse:[ |
|
399 |
name := name , '/' |
|
400 |
]. |
|
401 |
]. |
|
402 |
] |
|
403 |
]. |
|
404 |
||
405 |
" |
|
406 |
construct new contents, by taking |
|
407 |
last words completion |
|
408 |
" |
|
409 |
s := ''. |
|
410 |
1 to:(words size - 1) do:[:idx | |
|
411 |
s := s , (words at:idx) , ' ' |
|
412 |
]. |
|
413 |
s := s , name. |
|
414 |
||
415 |
"/ special: if there was no change, and the string represented |
|
416 |
"/ is a directories name, add a directory separator |
|
417 |
s = aString ifTrue:[ |
|
418 |
(s endsWith:Filename separator) ifFalse:[ |
|
419 |
s asFilename isDirectory ifTrue:[ |
|
420 |
^ s , Filename separator asString |
|
421 |
] |
|
422 |
] |
|
423 |
]. |
|
424 |
||
425 |
^ s |
|
615 | 426 |
! |
427 |
||
428 |
isCaseSensitive |
|
429 |
"return true, if filenames are case sensitive. |
|
430 |
We ask the OS about this, to be independent here." |
|
431 |
||
432 |
^ OperatingSystem caseSensitiveFilenames |
|
433 |
! |
|
434 |
||
435 |
localNameStringFrom:aString |
|
436 |
"ST-80 compatibility. |
|
437 |
what does this do ? (used in FileNavigator-goody). |
|
438 |
GUESS: does it strip off the voulume-character on MSDOS systems ?" |
|
439 |
||
440 |
(aString startsWith:'/') ifTrue:[ |
|
441 |
^ aString copyFrom:2 |
|
442 |
]. |
|
443 |
^ aString |
|
444 |
||
445 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
446 |
! |
|
447 |
||
448 |
parentDirectoryName |
|
449 |
"return the name used for the parent directory. |
|
450 |
This is '..' for unix and dos-like systems. |
|
451 |
(there may be more in the future." |
|
452 |
||
453 |
^ OperatingSystem parentDirectoryName |
|
454 |
||
455 |
" |
|
456 |
Filename parentDirectoryName |
|
457 |
" |
|
458 |
! |
|
459 |
||
460 |
separator |
|
461 |
"return the file/directory separator. |
|
462 |
Usually, this is $/ for unix-like systems |
|
463 |
and $\ for dos-like ones (there may be more in the future)." |
|
464 |
||
465 |
^ OperatingSystem fileSeparator |
|
466 |
||
467 |
" |
|
468 |
Filename separator |
|
469 |
" |
|
470 |
! |
|
471 |
||
472 |
suffixSeparator |
|
473 |
"return the filename suffix separator. |
|
474 |
Usually, this is $. for unix-like and msdos systems |
|
475 |
(there is currently no knowns system, where this differs)" |
|
476 |
||
477 |
^ $. |
|
478 |
||
479 |
" |
|
480 |
Filename suffixSeparator |
|
481 |
" |
|
482 |
||
483 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
484 |
! |
|
485 |
||
486 |
volumes |
|
487 |
"ST-80 compatibility. |
|
488 |
what does this do ? (used in FileNavigator-goody). |
|
489 |
GUESS: does it return the available drives on MSDOS systems ?" |
|
490 |
||
491 |
^ #('/') |
|
492 |
||
493 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
494 |
! ! |
|
495 |
||
496 |
!Filename methodsFor:'comparing'! |
|
497 |
||
498 |
= aFilename |
|
499 |
"return true, if the argument represents the same filename" |
|
500 |
||
501 |
|str| |
|
502 |
||
503 |
self species == aFilename species ifTrue:[ |
|
504 |
str := aFilename asString. |
|
505 |
self class isCaseSensitive ifTrue:[ |
|
506 |
^ nameString = str |
|
507 |
]. |
|
508 |
^ nameString sameAs:str |
|
509 |
]. |
|
510 |
^ false |
|
511 |
! |
|
512 |
||
513 |
hash |
|
514 |
"return an integer useful as a hash-key" |
|
515 |
||
516 |
^ nameString hash |
|
517 |
! ! |
|
518 |
||
519 |
!Filename methodsFor:'converting'! |
|
520 |
||
521 |
asAbsoluteFilename |
|
522 |
"return the receiver converted to a filename with |
|
523 |
an absolute pathname." |
|
524 |
||
525 |
^ self pathName asFilename |
|
526 |
! |
|
527 |
||
528 |
asFilename |
|
529 |
"return the receiver converted to a filename." |
|
530 |
||
531 |
"Thats pretty easy here :-)" |
|
532 |
^ self |
|
533 |
! |
|
534 |
||
535 |
asString |
|
536 |
"return the receiver converted to a string" |
|
537 |
||
538 |
^ nameString |
|
539 |
! |
|
540 |
||
541 |
makeLegalFilename |
|
542 |
"convert the receveivers name to be a legal filename. |
|
543 |
The implementation may change in the future to be more |
|
544 |
OS specific." |
|
545 |
||
546 |
" |
|
547 |
actually, in Unix spaces are allowed - but it makes life |
|
548 |
so hard; therefore, replace them by underscores ... |
|
549 |
" |
|
550 |
nameString replaceAll:(Character space) by:$_. |
|
551 |
" |
|
552 |
need more - especially on SYS5.3 type systems, |
|
553 |
we may want to contract the fileName to 14 characters. |
|
554 |
" |
|
555 |
^ self |
|
556 |
||
557 |
" |
|
558 |
'hello world' asFilename makeLegalFilename |
|
559 |
" |
|
2 | 560 |
! ! |
561 |
||
542 | 562 |
!Filename methodsFor:'error handling'! |
563 |
||
615 | 564 |
accessDeniedError:filename |
565 |
^ OperatingSystem accessDeniedErrorSignal |
|
542 | 566 |
raiseRequestWith:filename |
615 | 567 |
errorString:('access denied: ' , filename asString) |
568 |
! |
|
569 |
||
570 |
fileCreationError:filename |
|
571 |
^ OperatingSystem accessDeniedErrorSignal |
|
572 |
raiseRequestWith:filename |
|
573 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 574 |
! |
575 |
||
576 |
fileNotFoundError:filename |
|
577 |
^ OperatingSystem fileNotFoundErrorSignal |
|
578 |
raiseRequestWith:filename |
|
579 |
errorString:('file not found: ' , filename asString) |
|
580 |
! |
|
581 |
||
582 |
removeError:filename |
|
583 |
^ OperatingSystem accessDeniedErrorSignal |
|
584 |
raiseRequestWith:filename |
|
585 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 586 |
! |
587 |
||
588 |
reportError:string with:filename |
|
589 |
^ OperatingSystem errorSignal |
|
590 |
raiseRequestWith:filename |
|
591 |
errorString:string |
|
592 |
! ! |
|
593 |
||
594 |
!Filename methodsFor:'file access'! |
|
595 |
||
596 |
appendingWriteStream |
|
597 |
"return a stream for appending to the file represented by the receiver. |
|
598 |
If the file does not already exist, it is created." |
|
599 |
||
600 |
^ FileStream appendingOldFileNamed:nameString |
|
601 |
! |
|
602 |
||
603 |
newReadWriteStream |
|
604 |
"return a stream for read/write the file represented by the receiver. |
|
605 |
If the file does not already exist, it is created." |
|
606 |
||
607 |
^ FileStream newFileNamed:nameString |
|
608 |
! |
|
609 |
||
610 |
readStream |
|
611 |
"return a stream for reading from the file represented by the receiver. |
|
612 |
If the file does not already exist, nil is returned." |
|
613 |
||
614 |
^ FileStream readonlyFileNamed:nameString |
|
615 |
||
616 |
" |
|
617 |
'/tmp/foo' asFilename readStream |
|
618 |
" |
|
619 |
! |
|
620 |
||
621 |
readWriteStream |
|
622 |
"return a stream for read/write the file represented by the receiver. |
|
623 |
If the file does not already exist, nil is returned." |
|
624 |
||
625 |
^ FileStream oldFileNamed:nameString |
|
626 |
! |
|
627 |
||
628 |
writeStream |
|
629 |
"return a stream for writing to the file represented by the receiver. |
|
630 |
If the file does not already exist, it is created." |
|
631 |
||
632 |
^ FileStream newFileForWritingNamed:nameString |
|
633 |
||
634 |
" |
|
635 |
'/tmp/foo' asFilename writeStream |
|
636 |
" |
|
637 |
! ! |
|
638 |
||
639 |
!Filename methodsFor:'file operations'! |
|
640 |
||
641 |
addAccessRights:aCollection |
|
642 |
"add the access rights as specified in aCollection for the file represented |
|
643 |
by the receiver. The argument must be a collection of symbols, |
|
644 |
such as #readUser, #writeGroup etc." |
|
645 |
||
646 |
|access| |
|
647 |
||
648 |
access := OperatingSystem accessModeOf:nameString. |
|
649 |
aCollection do:[:accessSymbol | |
|
650 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
651 |
]. |
|
652 |
(OperatingSystem changeAccessModeOf:nameString to:access) ifFalse:[ |
|
653 |
^ self accessDeniedError:self |
|
654 |
] |
|
655 |
||
656 |
" |
|
657 |
'foo' asFilename writeStream close. |
|
658 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
659 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
660 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
661 |
" |
|
662 |
! |
|
663 |
||
664 |
copyTo:newName |
|
665 |
"copy the file - the argument must be convertable to a filename. |
|
671 | 666 |
Return true if successful, false if not." |
615 | 667 |
|
668 |
|inStream outStream buffer bufferSize count newFile| |
|
669 |
||
670 |
bufferSize := 8 * 1024. |
|
671 |
buffer := ByteArray new:bufferSize. |
|
672 |
inStream := self readStream. |
|
673 |
inStream isNil ifTrue:[ |
|
674 |
^ self fileNotFoundError:self |
|
675 |
]. |
|
676 |
||
677 |
outStream := (newFile := newName asFilename) writeStream. |
|
678 |
outStream isNil ifTrue:[ |
|
679 |
^ self fileCreationError:newFile |
|
680 |
]. |
|
681 |
||
682 |
[inStream atEnd] whileFalse:[ |
|
683 |
count := inStream nextBytes:bufferSize into:buffer. |
|
684 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
|
685 |
^ self fileCreationError:newFile |
|
686 |
] |
|
687 |
]. |
|
688 |
outStream close. |
|
689 |
inStream close. |
|
690 |
||
691 |
" |
|
692 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
693 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
694 |
" |
|
695 |
! |
|
696 |
||
697 |
delete |
|
698 |
"remove the file - same as remove, for ST-80 compatibility" |
|
699 |
||
700 |
self remove |
|
701 |
! |
|
702 |
||
703 |
makeDirectory |
|
704 |
"create a directory with the receivers name. |
|
671 | 705 |
Return true if successful, false if not." |
615 | 706 |
|
707 |
(OperatingSystem createDirectory:nameString) ifFalse:[ |
|
708 |
^ self fileCreationError:self |
|
709 |
] |
|
710 |
! |
|
711 |
||
712 |
makeReadable |
|
713 |
"make the file readable for the owner - you must have permission to do so." |
|
714 |
||
715 |
^ self addAccessRights:#(readUser) |
|
716 |
! |
|
717 |
||
718 |
makeReadableForAll |
|
719 |
"make the file readable for all - you must have permission to do so." |
|
720 |
||
721 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
722 |
! |
|
723 |
||
724 |
makeUnwritable |
|
725 |
"make the file unwritable for all - you must have permission to do so." |
|
726 |
||
727 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
728 |
! |
|
729 |
||
730 |
makeWritable |
|
731 |
"make the file writableable for all - you must have permission to do so." |
|
732 |
||
733 |
^ self addAccessRights:#(writeUser) |
|
734 |
! |
|
735 |
||
736 |
makeWritableForAll |
|
737 |
"make the file writable for all - you must have permission to do so." |
|
738 |
||
739 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
740 |
! |
|
741 |
||
742 |
moveTo:newName |
|
743 |
"copy the file represented by the receiver, then delete it. |
|
744 |
This is different to renaming in case of cross device moves. |
|
671 | 745 |
Raise an error if not successful." |
615 | 746 |
|
747 |
self copyTo:newName. |
|
748 |
self remove |
|
749 |
! |
|
750 |
||
659 | 751 |
recursiveMakeDirectory |
752 |
"create a directory with the receivers name and all required intermediate |
|
753 |
directories. |
|
671 | 754 |
Raise an error if not successful." |
659 | 755 |
|
756 |
(OperatingSystem recursiveCreateDirectory:nameString) ifFalse:[ |
|
671 | 757 |
^ self fileCreationError:self |
659 | 758 |
] |
759 |
||
760 |
"Created: 27.11.1995 / 23:36:40 / cg" |
|
761 |
! |
|
762 |
||
615 | 763 |
recursiveRemove |
671 | 764 |
"remove the directory and all of its subfiles/subdirectories. |
765 |
Raise an error if not successful." |
|
615 | 766 |
|
767 |
|ok| |
|
768 |
||
769 |
ok := OperatingSystem recursiveRemoveDirectory:nameString. |
|
770 |
ok ifFalse:[ |
|
771 |
self removeError:self |
|
772 |
]. |
|
773 |
||
774 |
" |
|
775 |
'foo' asFilename makeDirectory. |
|
776 |
'foo/bar' asFilename writeStream close. |
|
777 |
('foo' asFilename remove) ifFalse:[ |
|
778 |
Transcript showCr:'could not remove foo' |
|
779 |
] |
|
780 |
" |
|
781 |
" |
|
782 |
'foo' asFilename makeDirectory. |
|
783 |
'foo/bar' asFilename writeStream close. |
|
784 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
785 |
Transcript showCr:'could not remove foo' |
|
786 |
] |
|
787 |
" |
|
788 |
||
789 |
"Created: 14.11.1995 / 11:19:29 / cg" |
|
790 |
! |
|
791 |
||
792 |
remove |
|
793 |
"remove the file/directory - the argument must be convertable to a String. |
|
672 | 794 |
Raise an error if not successful. |
615 | 795 |
Use recursiveRemove in order to (recursively) remove non empty directories." |
796 |
||
797 |
|ok| |
|
798 |
||
799 |
self exists ifFalse:[ ^ self]. |
|
800 |
self isDirectory ifTrue:[ |
|
801 |
ok := OperatingSystem removeDirectory:nameString |
|
802 |
] ifFalse:[ |
|
803 |
ok := OperatingSystem removeFile:nameString |
|
804 |
]. |
|
805 |
ok ifFalse:[ |
|
806 |
self removeError:self |
|
807 |
]. |
|
808 |
||
809 |
" |
|
810 |
(FileStream newFileNamed:'foo') close. |
|
811 |
'foo' asFilename remove |
|
812 |
" |
|
813 |
||
814 |
" |
|
815 |
'foo' asFilename makeDirectory. |
|
816 |
'foo/bar' asFilename writeStream close. |
|
817 |
('foo' asFilename remove) ifFalse:[ |
|
818 |
Transcript showCr:'could not remove foo' |
|
819 |
] |
|
820 |
" |
|
821 |
||
822 |
"Modified: 14.11.1995 / 11:18:26 / cg" |
|
823 |
! |
|
824 |
||
825 |
removeAccessRights:aCollection |
|
826 |
"remove the access rights as specified in aCollection for the file represented |
|
827 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 828 |
such as #readUser, #writeGroup etc. |
829 |
Raise an error if not successful." |
|
615 | 830 |
|
831 |
|access| |
|
832 |
||
833 |
access := OperatingSystem accessModeOf:nameString. |
|
834 |
aCollection do:[:accessSymbol | |
|
835 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
|
836 |
]. |
|
837 |
(OperatingSystem changeAccessModeOf:nameString to:access) ifFalse:[ |
|
838 |
^ self accessDeniedError:self |
|
839 |
]. |
|
840 |
||
841 |
" |
|
842 |
'foo' asFilename writeStream close. |
|
843 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
844 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
845 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
846 |
" |
|
847 |
! |
|
848 |
||
849 |
renameTo:newName |
|
671 | 850 |
"rename the file - the argument must be convertable to a String. |
851 |
Raise an error if not successful." |
|
615 | 852 |
|
853 |
|ok| |
|
854 |
||
855 |
ok := OperatingSystem renameFile:nameString to:(newName asString). |
|
856 |
ok ifFalse:[ |
|
857 |
self exists ifFalse:[ |
|
858 |
^ self fileNotFoundError:self |
|
859 |
]. |
|
860 |
^ self accessDeniedError:newName asFilename. |
|
861 |
]. |
|
862 |
||
863 |
" |
|
864 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
865 |
" |
|
866 |
! ! |
|
867 |
||
868 |
!Filename methodsFor:'file queries'! |
|
869 |
||
870 |
dates |
|
871 |
"return the files modification and access times as an object (currently a dictionary) |
|
872 |
that responds to the at: message with arguments |
|
873 |
#modified, #accessed or #statusChanged." |
|
874 |
||
875 |
|info dates| |
|
876 |
||
877 |
info := OperatingSystem infoOf:nameString. |
|
878 |
info isNil ifTrue:[ |
|
879 |
info := OperatingSystem linkInfoOf:nameString. |
|
880 |
info isNil ifTrue:[ |
|
881 |
^ nil |
|
882 |
] |
|
883 |
]. |
|
884 |
dates := IdentityDictionary new. |
|
885 |
dates at:#modified put:(info at:#modified). |
|
886 |
dates at:#accessed put:(info at:#accessed). |
|
887 |
dates at:#statusChanged put:(info at:#statusChanged). |
|
888 |
^ dates |
|
889 |
||
890 |
" |
|
891 |
Filename currentDirectory dates |
|
892 |
'../regression' asFilename dates |
|
893 |
" |
|
894 |
! |
|
895 |
||
896 |
fileSize |
|
897 |
"return the size of the file in bytes" |
|
898 |
||
899 |
|info| |
|
900 |
||
901 |
info := self info. |
|
902 |
info isNil ifTrue:[^ nil]. |
|
903 |
^ info at:#size |
|
904 |
! |
|
905 |
||
906 |
fileType |
|
907 |
"this returns a string describing the type of contents of |
|
908 |
the file. This is done using the unix 'file' command, |
|
909 |
(which usually is configurable by /etc/magic). |
|
910 |
On non-unix systems, this may return an empty string, not knowning |
|
911 |
about the contents." |
|
912 |
||
913 |
|stream typeString| |
|
914 |
||
915 |
typeString := ''. |
|
916 |
stream := PipeStream readingFrom:('file ' , self pathName). |
|
917 |
stream notNil ifTrue:[ |
|
918 |
typeString := stream contents asString. |
|
919 |
stream close. |
|
920 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
|
921 |
typeString := typeString withoutSeparators |
|
922 |
] ifFalse:[ |
|
923 |
" |
|
924 |
could add some fallback code here, for systems, where no |
|
925 |
file command is avaliable ... |
|
926 |
... or at least analyze directory info. |
|
927 |
" |
|
928 |
]. |
|
929 |
^ typeString |
|
930 |
||
931 |
" |
|
932 |
'Makefile' asFilename fileType |
|
933 |
'.' asFilename fileType |
|
934 |
'/dev/null' asFilename fileType |
|
935 |
'smalltalk.rc' asFilename fileType |
|
936 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
937 |
" |
|
938 |
! |
|
939 |
||
940 |
info |
|
941 |
"return the files info; that is a collection of file attributes, |
|
942 |
(actually a dictionary) where the keys are #type, #uid, #gid, #size etc. |
|
943 |
The actual amount and detail returned may depend on the OS used. |
|
944 |
On unix, if you ask for the info of a symbolic link, the target |
|
945 |
files info is returned. (see also: #linkInfo) |
|
946 |
||
947 |
On unix, the contents is: |
|
948 |
id -> the inode number (integer) |
|
949 |
uid -> the numeric user id of the files owner |
|
950 |
gid -> the numeric group id of the files owner |
|
951 |
statusChanged -> the absoluteTime when the files status changed last |
|
952 |
(i.e. protection change, owner change etc.) |
|
953 |
accessed -> the absoluteTime when the file was last accessed |
|
954 |
modified -> the absoluteTime when the file was last modified |
|
955 |
size -> the size (in bytes) of the file |
|
956 |
type -> the files type (#regular, #directory, #characterSpecial) |
|
957 |
mode -> the files access protection bits (rwxrwxrwx mask). |
|
958 |
||
959 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
|
960 |
modified |
|
961 |
size |
|
962 |
type |
|
963 |
||
964 |
Some OS's (VMS) may return more info. |
|
965 |
||
966 |
Dont expect things like uid/gid/mode to be there; write your application |
|
967 |
to either handle the cases where info-entries are not present, |
|
968 |
or (better) use one of isXXXX query methods. (Be prepared for DOS ...) |
|
969 |
" |
|
970 |
||
971 |
^ OperatingSystem infoOf:nameString |
|
972 |
||
973 |
" |
|
974 |
Filename currentDirectory info |
|
975 |
'/dev/null' asFilename info |
|
976 |
'Make.proto' asFilename info |
|
977 |
'source/Point.st' asFilename info |
|
978 |
'source/Point.st' asFilename linkInfo |
|
979 |
'../../libbasic/Point.st' asFilename info |
|
980 |
" |
|
981 |
! |
|
982 |
||
983 |
linkInfo |
|
984 |
"return the files info if its a symbolic link; nil otherwise. |
|
985 |
On OS's which do not support symbolic links, nil is always returned. |
|
986 |
The information is the same as returned by #info, except that if the |
|
987 |
receiver represents a symbolic link, the links information |
|
988 |
is returned |
|
989 |
(while in this case, #info returns the info of the target file, |
|
990 |
which is accessed via the symbolic link). |
|
991 |
||
992 |
In addition to the normal entries, Unix returns an additional entry: |
|
993 |
path -> the target files pathname |
|
994 |
||
995 |
See the comment in #info for more details." |
|
996 |
||
997 |
^ OperatingSystem linkInfoOf:nameString |
|
998 |
||
999 |
" |
|
1000 |
Filename currentDirectory linkInfo |
|
1001 |
'/dev/null' asFilename linkInfo |
|
1002 |
'Make.proto' asFilename linkInfo |
|
1003 |
'Make.proto' asFilename linkInfo at:#path |
|
1004 |
'source/Point.st' asFilename linkInfo |
|
1005 |
'../../libbasic/Point.st' asFilename linkInfo |
|
1006 |
" |
|
1007 |
! ! |
|
1008 |
||
1009 |
!Filename methodsFor:'file utilities'! |
|
1010 |
||
1011 |
contentsOfEntireFile |
|
1012 |
"return the contents of the file as a string" |
|
1013 |
||
1014 |
|s contents| |
|
1015 |
||
1016 |
s := self readStream. |
|
1017 |
[ |
|
1018 |
contents := s contents |
|
1019 |
] valueNowOrOnUnwindDo:[s close]. |
|
1020 |
^ contents |
|
1021 |
! |
|
1022 |
||
1023 |
edit |
|
1024 |
"start an editView on the file represented by the receiver" |
|
1025 |
||
1026 |
EditTextView openOn:self asString |
|
1027 |
||
1028 |
" |
|
1029 |
'smalltalk.rc' asFilename edit |
|
1030 |
" |
|
1031 |
! |
|
1032 |
||
1033 |
fileIn |
|
1034 |
"load smalltalk code from the file" |
|
1035 |
||
1036 |
^ self readStream fileIn |
|
542 | 1037 |
! ! |
1038 |
||
2 | 1039 |
!Filename methodsFor:'instance creation'! |
1040 |
||
615 | 1041 |
construct:subname |
1042 |
"taking the receiver as a directory name, construct a new |
|
1043 |
filename for an entry within this directory (i.e. for a file |
|
1044 |
or a subdirectory in that directory)." |
|
1045 |
||
1046 |
^ (self constructString:subname) asFilename |
|
1047 |
||
1048 |
" |
|
1049 |
'/tmp' asFilename construct:'foo' |
|
1050 |
'/' asFilename construct:'foo' |
|
1051 |
'/usr/tmp' asFilename construct:'foo' |
|
1052 |
'/foo/bar' asFilename construct:'baz' |
|
1053 |
" |
|
1054 |
! |
|
1055 |
||
249 | 1056 |
constructString:subname |
38 | 1057 |
"taking the receiver as a directory name, construct a new |
249 | 1058 |
filenames string for an entry within this directory (i.e. for a file |
38 | 1059 |
or a subdirectory in that directory)." |
1060 |
||
276 | 1061 |
|sepString| |
202 | 1062 |
|
1063 |
sepString := self class separator asString. |
|
1064 |
nameString = sepString ifTrue:[ |
|
159 | 1065 |
"I am the root" |
276 | 1066 |
^ sepString , subname |
85 | 1067 |
]. |
422 | 1068 |
^ nameString , sepString , subname asString |
38 | 1069 |
|
85 | 1070 |
" |
249 | 1071 |
'/tmp' asFilename constructString:'foo' |
1072 |
'/' asFilename constructString:'foo' |
|
1073 |
'/usr/tmp' asFilename constructString:'foo' |
|
328 | 1074 |
'/foo/bar' asFilename constructString:'baz' |
249 | 1075 |
" |
422 | 1076 |
|
1077 |
"Modified: 7.9.1995 / 10:15:22 / claus" |
|
2 | 1078 |
! ! |
1079 |
||
195 | 1080 |
!Filename methodsFor:'misc'! |
1081 |
||
1082 |
, aString |
|
1083 |
"this allows filenames to understand how names are concatenated. |
|
308 | 1084 |
Returns a string consisting of the receivers name, concatenated |
195 | 1085 |
by aString. Notice this is NOT the same as construct:, which inserts |
308 | 1086 |
a directory delimiter and returns a new fileName instance." |
195 | 1087 |
|
308 | 1088 |
^ (nameString , aString asString) |
195 | 1089 |
|
1090 |
" |
|
1091 |
'Makefile' asFilename , '.bak' |
|
1092 |
'Makefile' asFilename construct:'.bak' |
|
1093 |
" |
|
1094 |
! ! |
|
1095 |
||
615 | 1096 |
!Filename methodsFor:'printing & storing'! |
174 | 1097 |
|
615 | 1098 |
printOn:aStream |
1099 |
"append a printed representation of the receiver to aStream." |
|
174 | 1100 |
|
615 | 1101 |
aStream nextPutAll:'FileName('''. |
1102 |
nameString printOn:aStream. |
|
1103 |
aStream nextPutAll:''')' |
|
1 | 1104 |
! |
1105 |
||
615 | 1106 |
storeOn:aStream |
1107 |
"append a printed representation of the receiver to aStream, |
|
1108 |
which allows reconstructing it via readFrom:" |
|
328 | 1109 |
|
615 | 1110 |
aStream nextPut:$(. |
1111 |
nameString storeOn:aStream. |
|
1112 |
aStream nextPutAll:' asFilename)' |
|
1 | 1113 |
! ! |
1114 |
||
202 | 1115 |
!Filename methodsFor:'private accessing'! |
1 | 1116 |
|
68 | 1117 |
setName:aString |
38 | 1118 |
"set the filename" |
1119 |
||
68 | 1120 |
nameString := aString |
1 | 1121 |
! ! |
1122 |
||
2 | 1123 |
!Filename methodsFor:'queries'! |
1124 |
||
615 | 1125 |
baseName |
1126 |
"return my baseName as a string. |
|
1127 |
- thats the file/directory name without leading parent-dirs." |
|
159 | 1128 |
|
615 | 1129 |
^ OperatingSystem baseNameOf:nameString "/ (self pathName) |
422 | 1130 |
|
1131 |
" |
|
615 | 1132 |
'/foo/bar' asFilename baseName |
1133 |
'.' asFilename baseName |
|
1134 |
'..' asFilename baseName |
|
1135 |
'../..' asFilename baseName |
|
1136 |
'../../libbasic' asFilename baseName |
|
1137 |
'../../libpr' asFilename baseName |
|
1138 |
'../../libbasic/Object.st' asFilename baseName |
|
422 | 1139 |
" |
1140 |
! |
|
1141 |
||
615 | 1142 |
canBeWritten |
1143 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 1144 |
|
615 | 1145 |
^ self isWritable |
92 | 1146 |
|
328 | 1147 |
" |
615 | 1148 |
'/foo/bar' asFilename canBeWritten |
1149 |
'/tmp' asFilename canBeWritten |
|
1150 |
'Makefile' asFilename canBeWritten |
|
328 | 1151 |
" |
1152 |
! |
|
1153 |
||
1154 |
directory |
|
422 | 1155 |
"return the directory name part of the file/directory as a filename. |
328 | 1156 |
- thats a filename for the directory where the file/dir represented by |
1157 |
the receiver is contained in." |
|
1158 |
||
1159 |
^ self directoryName asFilename |
|
2 | 1160 |
|
92 | 1161 |
" |
174 | 1162 |
'/foo/bar' asFilename directory |
1163 |
'.' asFilename directory |
|
1164 |
'..' asFilename directory |
|
1165 |
'../..' asFilename directory |
|
92 | 1166 |
" |
2 | 1167 |
! |
1168 |
||
308 | 1169 |
directoryContents |
1170 |
"return the contents of the directory as a collection of strings" |
|
1171 |
||
1172 |
^ (FileDirectory directoryNamed:self asString) contents |
|
1173 |
||
1174 |
" |
|
1175 |
'.' asFilename directoryContents |
|
1176 |
" |
|
1177 |
! |
|
1178 |
||
615 | 1179 |
directoryName |
1180 |
"return the directory name part of the file/directory as a string. |
|
1181 |
- thats the name of the directory where the file/dir represented by |
|
1182 |
the receiver is contained in. |
|
1183 |
See also: #directoryPathName" |
|
174 | 1184 |
|
615 | 1185 |
^ OperatingSystem directoryNameOf:nameString "/ (self pathName) |
68 | 1186 |
|
85 | 1187 |
" |
615 | 1188 |
'/foo/bar/' asFilename directoryName |
1189 |
'/foo/bar' asFilename directoryName |
|
1190 |
'bitmaps' asFilename directoryName |
|
1191 |
'bitmaps' asFilename directoryPathName |
|
1192 |
'.' asFilename directoryName |
|
1193 |
'..' asFilename directoryName |
|
1194 |
'../..' asFilename directoryName |
|
1195 |
'../..' asFilename directoryPathName |
|
422 | 1196 |
" |
1197 |
||
615 | 1198 |
"Modified: 7.9.1995 / 10:42:03 / claus" |
422 | 1199 |
! |
1200 |
||
615 | 1201 |
directoryPathName |
1202 |
"return the full directory pathname part of the file/directory as a string. |
|
1203 |
- thats the full pathname of the directory where the file/dir represented by |
|
1204 |
the receiver is contained in. |
|
1205 |
See also: directoryName" |
|
216 | 1206 |
|
615 | 1207 |
^ OperatingSystem directoryNameOf:(self pathName) |
92 | 1208 |
|
1209 |
" |
|
615 | 1210 |
'/foo/bar/' asFilename directoryPathName |
1211 |
'/foo/bar' asFilename directoryPathName |
|
1212 |
'.' asFilename directoryPathName |
|
1213 |
'..' asFilename directoryPathName |
|
1214 |
'../..' asFilename directoryPathName |
|
85 | 1215 |
" |
422 | 1216 |
|
615 | 1217 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
68 | 1218 |
! |
1219 |
||
1220 |
exists |
|
92 | 1221 |
"return true, if such a file exists." |
68 | 1222 |
|
1223 |
^ OperatingSystem isValidPath:nameString |
|
1224 |
||
85 | 1225 |
" |
92 | 1226 |
'/foo/bar' asFilename exists |
1227 |
'/tmp' asFilename exists |
|
1228 |
'Makefile' asFilename exists |
|
85 | 1229 |
" |
77 | 1230 |
! |
1231 |
||
92 | 1232 |
filenameCompletion |
440 | 1233 |
"try to complete the recevier filename. |
1234 |
This method has both a return value and a side effect on the receiver: |
|
1235 |
it returns a collection of matching filename objects, |
|
1236 |
and leaves changes the receivers filename-string to the longest common |
|
1237 |
match. |
|
1238 |
If none matches, the returned collection is empty and the recevier is unchanged. |
|
1239 |
If there is only one match, the size of the returned collection is exactly 1, |
|
1240 |
containing the fully expanded filename and the receivers name is changed to it." |
|
92 | 1241 |
|
440 | 1242 |
^ self filenameCompletionIn:nil |
216 | 1243 |
|
440 | 1244 |
" |
1245 |
'mak' asFilename filenameCompletion |
|
1246 |
'Make' asFilename filenameCompletion |
|
1247 |
'Makef' asFilename filenameCompletion;yourself |
|
1248 |
'/u' asFilename filenameCompletion |
|
1249 |
'../../libpr' asFilename inspect filenameCompletion |
|
1250 |
" |
|
1251 |
! |
|
92 | 1252 |
|
440 | 1253 |
filenameCompletionIn:aDirectory |
1254 |
"try to complete the recevier filename. |
|
1255 |
This method has both a return value and a side effect on the receiver: |
|
1256 |
it returns a collection of matching filename objects, |
|
1257 |
and leaves changes the receivers filename-string to the longest common |
|
1258 |
match. |
|
1259 |
If none matches, the returned collection is empty and the recevier is unchanged. |
|
1260 |
If there is only one match, the size of the returned collection is exactly 1, |
|
1261 |
containing the fully expanded filename and the receivers name is changed to it." |
|
1262 |
||
1263 |
|dir baseName matching matchLen try allMatching |
|
1264 |
sepString parentString prefix nMatch| |
|
1265 |
||
1266 |
sepString := self class separator asString. |
|
1267 |
(nameString endsWith:sepString) ifTrue:[ |
|
1268 |
^ #() |
|
328 | 1269 |
]. |
1270 |
||
440 | 1271 |
parentString := self class parentDirectoryName. |
1272 |
baseName := self baseName. |
|
1273 |
baseName ~= nameString ifTrue:[ |
|
1274 |
prefix := self directoryName. |
|
1275 |
]. |
|
1276 |
||
441 | 1277 |
self isAbsolute ifTrue:[ |
440 | 1278 |
dir := self directory |
1279 |
] ifFalse:[ |
|
441 | 1280 |
aDirectory isNil ifTrue:[ |
1281 |
dir := self directory |
|
1282 |
] ifFalse:[ |
|
1283 |
dir := (aDirectory construct:nameString) directory |
|
1284 |
] |
|
328 | 1285 |
]. |
216 | 1286 |
|
92 | 1287 |
matching := OrderedCollection new. |
440 | 1288 |
dir directoryContents do:[:fileName | |
1289 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
|
1290 |
(fileName startsWith:baseName) ifTrue:[ |
|
216 | 1291 |
matching add:fileName |
1292 |
] |
|
159 | 1293 |
] |
92 | 1294 |
]. |
440 | 1295 |
(nMatch := matching size) > 1 ifTrue:[ |
1296 |
" |
|
1297 |
find the longest common prefix |
|
1298 |
" |
|
1299 |
matchLen := baseName size. |
|
1300 |
matchLen > matching first size ifTrue:[ |
|
1301 |
try := baseName. |
|
1302 |
allMatching := false |
|
1303 |
] ifFalse:[ |
|
1304 |
try := matching first copyTo:matchLen. |
|
1305 |
allMatching := true. |
|
1306 |
]. |
|
1307 |
||
1308 |
[allMatching] whileTrue:[ |
|
1309 |
matching do:[:aName | |
|
1310 |
(aName startsWith:try) ifFalse:[ |
|
1311 |
allMatching := false |
|
1312 |
] |
|
1313 |
]. |
|
1314 |
allMatching ifTrue:[ |
|
1315 |
matchLen < matching first size ifTrue:[ |
|
1316 |
matchLen := matchLen + 1. |
|
1317 |
try := matching first copyTo:matchLen. |
|
1318 |
] ifFalse:[ |
|
1319 |
allMatching := false |
|
1320 |
] |
|
1321 |
] ifFalse:[ |
|
1322 |
try := matching first copyTo:matchLen - 1. |
|
1323 |
] |
|
1324 |
]. |
|
1325 |
" |
|
1326 |
and set my name to the last full match |
|
1327 |
" |
|
1328 |
nameString := try |
|
1329 |
]. |
|
1330 |
||
92 | 1331 |
" |
440 | 1332 |
if I had a directory-prefix, change names in collection ... |
1333 |
" |
|
1334 |
prefix notNil ifTrue:[ |
|
1335 |
prefix = '/' ifTrue:[ |
|
1336 |
"/ avoid introducing double slashes |
|
1337 |
prefix := '' |
|
159 | 1338 |
]. |
440 | 1339 |
matching := matching collect:[:n | prefix , '/' , n]. |
1340 |
nMatch == 1 ifTrue:[ |
|
1341 |
nameString := matching first |
|
1342 |
] ifFalse:[ |
|
1343 |
nMatch > 1 ifTrue:[ |
|
1344 |
nameString := prefix , '/' , nameString |
|
159 | 1345 |
] |
1346 |
] |
|
92 | 1347 |
] ifFalse:[ |
440 | 1348 |
nMatch == 1 ifTrue:[ |
1349 |
nameString := matching first |
|
159 | 1350 |
] |
92 | 1351 |
]. |
440 | 1352 |
|
92 | 1353 |
" |
1354 |
return the match-set, so caller can decide what to do |
|
1355 |
(i.e. show the matches, output a warning etc ...) |
|
1356 |
" |
|
1357 |
^ matching |
|
1358 |
||
440 | 1359 |
" trivial cases: |
1360 |
||
1361 |
'../' asFilename filenameCompletion |
|
1362 |
'/' asFilename filenameCompletion |
|
1363 |
'/usr/' asFilename filenameCompletion |
|
1364 |
||
1365 |
'mak' asFilename filenameCompletion |
|
1366 |
'Make' asFilename filenameCompletion |
|
1367 |
'Makef' asFilename filenameCompletion |
|
1368 |
'/u' asFilename filenameCompletion |
|
1369 |
'../../libpr' asFilename filenameCompletion |
|
85 | 1370 |
" |
615 | 1371 |
! |
174 | 1372 |
|
615 | 1373 |
filesMatching:aPattern |
1374 |
^ self directoryContents select:[:name | aPattern match:name] |
|
356 | 1375 |
|
615 | 1376 |
" |
1377 |
Filename currentDirectory filesMatching:'M*' |
|
1378 |
" |
|
1379 |
! |
|
356 | 1380 |
|
615 | 1381 |
isAbsolute |
1382 |
"return true, if the receiver represents an absolute pathname |
|
1383 |
(in contrast to one relative to the current directory)." |
|
356 | 1384 |
|
615 | 1385 |
^ (nameString startsWith:self class separator) |
328 | 1386 |
|
1387 |
" |
|
615 | 1388 |
'/foo/bar' asFilename isAbsolute |
1389 |
'..' asFilename isAbsolute |
|
1390 |
'..' asAbsoluteFilename isAbsolute |
|
1391 |
'source/SBrowser.st' asFilename isAbsolute |
|
1392 |
" |
|
1393 |
! |
|
1394 |
||
1395 |
isDirectory |
|
1396 |
"return true, if the receiver represents an existing, |
|
1397 |
readable directories pathname." |
|
1398 |
||
1399 |
^ OperatingSystem isDirectory:nameString |
|
1400 |
||
1401 |
" |
|
1402 |
'/foo/bar' asFilename isDirectory |
|
1403 |
'/tmp' asFilename isDirectory |
|
1404 |
'Makefile' asFilename isDirectory |
|
1405 |
" |
|
1406 |
! |
|
1407 |
||
1408 |
isExecutable |
|
1409 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
1410 |
For directories, true is returned if the directory can be entered. |
|
1411 |
See isExecutableProgram for a related check." |
|
1412 |
||
1413 |
^ OperatingSystem isExecutable:nameString |
|
1414 |
||
1415 |
" |
|
1416 |
'/foo/bar' asFilename isExecutable |
|
1417 |
'/tmp' asFilename isExecutable |
|
1418 |
'Makefile' asFilename isExecutable |
|
1419 |
'/bin/ls' asFilename isExecutable |
|
356 | 1420 |
" |
1421 |
! |
|
1422 |
||
615 | 1423 |
isExecutableProgram |
1424 |
"return true, if such a file exists and is an executable program. |
|
1425 |
(i.e. for directories, false is returned.)" |
|
356 | 1426 |
|
615 | 1427 |
^ (OperatingSystem isExecutable:nameString) |
1428 |
and:[(OperatingSystem isDirectory:nameString) not] |
|
356 | 1429 |
|
1430 |
" |
|
615 | 1431 |
'/tmp' asFilename isExecutable |
1432 |
'/bin/ls' asFilename isExecutable |
|
1433 |
'/tmp' asFilename isExecutableProgram |
|
1434 |
'/bin/ls' asFilename isExecutableProgram |
|
1435 |
" |
|
1436 |
! |
|
1437 |
||
1438 |
isReadable |
|
1439 |
"return true, if such a file exists and is readable." |
|
1440 |
||
1441 |
^ OperatingSystem isReadable:nameString |
|
1442 |
||
1443 |
" |
|
1444 |
'/foo/bar' asFilename isReadable |
|
1445 |
'/tmp' asFilename isReadable |
|
1446 |
'Makefile' asFilename isReadable |
|
328 | 1447 |
" |
1448 |
! |
|
1449 |
||
615 | 1450 |
isRelative |
1451 |
"return true, if this name is interpreted relative to some |
|
1452 |
directory (opposite of absolute)" |
|
328 | 1453 |
|
615 | 1454 |
^ self isAbsolute not |
1455 |
! |
|
328 | 1456 |
|
615 | 1457 |
isSymbolicLink |
1458 |
"return true, if the file represented by the receiver is a symbolic |
|
1459 |
link. Notice that not all OS's support symbolic links; those that do |
|
1460 |
not will always return false." |
|
1461 |
||
1462 |
^ OperatingSystem isSymbolicLink:nameString |
|
328 | 1463 |
|
1464 |
" |
|
615 | 1465 |
'Make.proto' asFilename isSymbolicLink |
1466 |
'Makefile' asFilename isSymbolicLink |
|
1467 |
" |
|
1468 |
! |
|
1469 |
||
1470 |
isWritable |
|
1471 |
"return true, if such a file exists and is writable." |
|
1472 |
||
1473 |
^ OperatingSystem isWritable:nameString |
|
1474 |
||
1475 |
" |
|
1476 |
'/foo/bar' asFilename isWritable |
|
1477 |
'/tmp' asFilename isWritable |
|
1478 |
'Makefile' asFilename isWritable |
|
328 | 1479 |
" |
174 | 1480 |
! |
1481 |
||
615 | 1482 |
name |
1483 |
"return the name of the file represented by the receiver as a string. |
|
1484 |
This may or may not be a relative name. |
|
1485 |
See also: pathName" |
|
174 | 1486 |
|
615 | 1487 |
self isAbsolute ifTrue:[^ self pathName]. |
1488 |
^ nameString |
|
174 | 1489 |
|
1490 |
" |
|
615 | 1491 |
'/foo/bar' asFilename name |
1492 |
'/foo/bar' asFilename pathName |
|
1493 |
'.' asFilename name |
|
1494 |
'.' asFilename pathName |
|
1495 |
'../..' asFilename name |
|
1496 |
'../..' asFilename pathName |
|
1497 |
'bitmaps' asFilename name |
|
1498 |
'bitmaps' asFilename pathName |
|
1499 |
'/tmp/../usr' asFilename name |
|
1500 |
'/tmp/../usr' asFilename pathName |
|
92 | 1501 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1502 |
|
615 | 1503 |
"Modified: 7.9.1995 / 10:41:14 / claus" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1504 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1505 |
|
615 | 1506 |
pathName |
1507 |
"return the full pathname of the file represented by the receiver, |
|
1508 |
as a string. See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1509 |
|
615 | 1510 |
|parentName sep| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1511 |
|
615 | 1512 |
sep := self class separator. |
1513 |
(nameString startsWith:sep) ifTrue:[ |
|
1514 |
parentName := self class parentDirectoryName. |
|
1515 |
(nameString findString:parentName) == 0 ifTrue:[ |
|
1516 |
^ nameString |
|
1517 |
] |
|
542 | 1518 |
]. |
615 | 1519 |
^ (FileDirectory directoryNamed:nameString) pathName |
2 | 1520 |
|
92 | 1521 |
" |
615 | 1522 |
'/foo/bar' asFilename pathName |
1523 |
'.' asFilename pathName |
|
1524 |
'../..' asFilename pathName |
|
1525 |
'../..' asFilename name |
|
1526 |
'/tmp/../usr' asFilename pathName |
|
92 | 1527 |
" |
159 | 1528 |
|
615 | 1529 |
"Modified: 7.9.1995 / 10:42:39 / claus" |
174 | 1530 |
! |
1531 |
||
615 | 1532 |
prefixAndSuffix |
1533 |
"return an array consisting of my prefix and suffix. |
|
1534 |
The suffix is the namepart after the final period character, |
|
1535 |
the prefix everything before, except for the period. |
|
1536 |
(on some systems, the suffix-character may be different from a period). |
|
1537 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
|
174 | 1538 |
|
615 | 1539 |
Notice: there is currently no known system which uses other than |
1540 |
the period character as suffixCharacter." |
|
174 | 1541 |
|
615 | 1542 |
|nm idx| |
174 | 1543 |
|
615 | 1544 |
nm := self baseName. |
1545 |
idx := nm lastIndexOf:(self class suffixSeparator). |
|
1546 |
idx == 0 ifTrue:[ |
|
1547 |
^ Array with:nm with:'' |
|
174 | 1548 |
]. |
615 | 1549 |
^ Array |
1550 |
with:(nm copyTo:idx-1) |
|
1551 |
with:(nm copyFrom:idx+1) |
|
174 | 1552 |
|
1553 |
" |
|
615 | 1554 |
'abc.st' asFilename prefixAndSuffix |
1555 |
'abc' asFilename prefixAndSuffix |
|
1556 |
'a.b.c' asFilename prefixAndSuffix |
|
1557 |
||
1558 |
|parts| |
|
1559 |
parts := 'Object.st' asFilename prefixAndSuffix. |
|
1560 |
((parts at:1) , '.o') asFilename |
|
174 | 1561 |
" |
615 | 1562 |
|
1563 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
|
174 | 1564 |
! |
1565 |
||
615 | 1566 |
separator |
1567 |
"return the directory-separator character (or string)" |
|
174 | 1568 |
|
615 | 1569 |
^ self class separator |
174 | 1570 |
! |
1571 |
||
615 | 1572 |
suffix |
1573 |
"return my suffix. |
|
1574 |
The suffix is the namepart after the final period character, |
|
1575 |
or the empty string, if the name does not contain a period." |
|
1576 |
||
1577 |
^ self prefixAndSuffix at:2 |
|
174 | 1578 |
|
615 | 1579 |
" |
1580 |
'abc.st' asFilename suffix |
|
1581 |
'abc' asFilename suffix |
|
1582 |
'a.b.c' asFilename suffix |
|
1583 |
" |
|
174 | 1584 |
|
615 | 1585 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
174 | 1586 |
! |
1587 |
||
615 | 1588 |
tail |
1589 |
"the files name without directory prefix as a string. |
|
1590 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 1591 |
|
615 | 1592 |
^ self baseName |
174 | 1593 |
! ! |
1594 |
||
630 | 1595 |
!Filename class methodsFor:'documentation'! |
1596 |
||
1597 |
version |
|
672 | 1598 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.46 1995-12-04 10:25:22 cg Exp $' |
630 | 1599 |
! ! |