author | Claus Gittinger <cg@exept.de> |
Sat, 22 Mar 1997 14:14:21 +0100 | |
changeset 2481 | bb9bc51ce5f6 |
parent 2175 | a3fe5ef27022 |
child 2503 | 279c9f6a99c9 |
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 |
|
844 | 14 |
instanceVariableNames:'nameString' |
15 |
classVariableNames:'NextTempFilenameIndex' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'System-Support' |
|
615 | 18 |
! |
1 | 19 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
20 |
!Filename class methodsFor:'documentation'! |
88 | 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 |
||
1286 | 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 |
||
1286 | 55 |
'Makefile' asFilename readStream |
56 |
||
57 |
'newFile' asFilename writeStream |
|
58 |
||
59 |
Filename newTemporary writeStream |
|
276 | 60 |
|
1318 | 61 |
Beside lots of protocol to query for a files attributes, the class |
62 |
protocol offers methods for filename completion, to construct pathes |
|
63 |
(in an OS-independent way) and to create temporary files. |
|
64 |
Especially the path-construction methods (i.e. #construct:) is highly |
|
65 |
recommended in order to avoid having OS details (like directory separators |
|
66 |
being slash or backslash) spreaded in your application. |
|
67 |
||
1286 | 68 |
[author:] |
69 |
Claus Gittinger |
|
276 | 70 |
|
1286 | 71 |
[see also:] |
72 |
String |
|
73 |
FileStream DirectoryStream PipeStream Socket |
|
74 |
OperatingSystem |
|
75 |
Date Time |
|
88 | 76 |
" |
360 | 77 |
! |
78 |
||
79 |
examples |
|
80 |
" |
|
81 |
does a file/directory exist ?: |
|
82 |
||
1317 | 83 |
|f| |
360 | 84 |
|
1317 | 85 |
f := 'foobar' asFilename. |
86 |
^ f exists |
|
360 | 87 |
|
88 |
||
89 |
is it a directory ?: |
|
90 |
||
1317 | 91 |
|f| |
360 | 92 |
|
1317 | 93 |
f := '/tmp' asFilename. |
94 |
^ f isDirectory. |
|
360 | 95 |
|
96 |
||
97 |
get the working directory: |
|
98 |
||
1317 | 99 |
^ Filename defaultDirectory |
360 | 100 |
|
101 |
||
102 |
get a files full pathname |
|
103 |
(caring for relative names or symbolic links): |
|
104 |
||
1317 | 105 |
|f| |
360 | 106 |
|
1317 | 107 |
f := '..' asFilename. |
108 |
^ f pathName |
|
360 | 109 |
|
110 |
||
111 |
get a directories directory: |
|
112 |
||
1317 | 113 |
|f| |
360 | 114 |
|
1317 | 115 |
f := Filename defaultDirectory. |
116 |
^ f directory |
|
360 | 117 |
|
118 |
||
119 |
get a files directory: |
|
120 |
||
1317 | 121 |
|f| |
360 | 122 |
|
1317 | 123 |
f := './smalltalk' asFilename. |
124 |
^ f directory |
|
360 | 125 |
|
126 |
||
127 |
getting access & modification times: |
|
128 |
||
129 |
||
1317 | 130 |
|f| |
360 | 131 |
|
1317 | 132 |
f := '/tmp' asFilename. |
133 |
^ f dates |
|
360 | 134 |
|
135 |
access time only: |
|
136 |
||
1317 | 137 |
|f| |
360 | 138 |
|
1317 | 139 |
f := '/tmp' asFilename. |
140 |
^ f dates at:#accessed |
|
360 | 141 |
|
142 |
||
143 |
getting all information on a file/directory: |
|
144 |
||
145 |
||
1317 | 146 |
|f| |
360 | 147 |
|
1317 | 148 |
f := '/tmp' asFilename. |
149 |
^ f info |
|
360 | 150 |
|
151 |
||
152 |
getting a temporary file (unique name): |
|
153 |
||
1317 | 154 |
|f| |
360 | 155 |
|
1317 | 156 |
f := Filename newTemporary. |
157 |
^ f |
|
360 | 158 |
|
159 |
||
160 |
creating, writing, reading and removing a temporary file: |
|
1317 | 161 |
[exBegin] |
162 |
|f writeStream readStream| |
|
360 | 163 |
|
1317 | 164 |
f := Filename newTemporary. |
165 |
writeStream := f writeStream. |
|
166 |
writeStream nextPutAll:'hello world'. |
|
167 |
writeStream cr. |
|
168 |
writeStream close. |
|
360 | 169 |
|
1317 | 170 |
'contents (as seen by unix''s cat command:' printNL. |
171 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
360 | 172 |
|
1317 | 173 |
readStream := f readStream. |
1422 | 174 |
Transcript showCR:'contents as seen by smalltalk:'. |
175 |
Transcript showCR:(readStream upToEnd). |
|
1317 | 176 |
readStream close. |
360 | 177 |
|
1317 | 178 |
f delete. |
179 |
[exEnd] |
|
360 | 180 |
|
181 |
||
182 |
getting a directories contents: |
|
1317 | 183 |
[exBegin] |
184 |
|f files| |
|
360 | 185 |
|
1317 | 186 |
f := '.' asFilename. |
187 |
files := f directoryContents. |
|
1422 | 188 |
Transcript showCR:'the files are:'. |
189 |
Transcript showCR:(files printString). |
|
1317 | 190 |
[exEnd] |
360 | 191 |
|
192 |
||
193 |
editing a file: |
|
1317 | 194 |
[exBegin] |
195 |
|f| |
|
360 | 196 |
|
1317 | 197 |
f := '/tmp/fooBar' asFilename. |
198 |
(f writeStream) nextPutAll:'hello world'; close. |
|
360 | 199 |
|
1317 | 200 |
f edit |
201 |
[exEnd] |
|
360 | 202 |
" |
88 | 203 |
! ! |
1 | 204 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
205 |
!Filename class methodsFor:'instance creation'! |
1 | 206 |
|
276 | 207 |
currentDirectory |
208 |
"return a filename for the current directory" |
|
209 |
||
210 |
^ self named:(FileDirectory currentDirectory pathName) |
|
211 |
||
212 |
" |
|
213 |
Filename currentDirectory |
|
214 |
" |
|
215 |
! |
|
216 |
||
328 | 217 |
defaultDirectory |
218 |
"ST80 compatibility: same as currentDirectory" |
|
219 |
||
220 |
^ self currentDirectory |
|
221 |
||
222 |
" |
|
223 |
Filename defaultDirectory |
|
224 |
" |
|
225 |
! |
|
226 |
||
542 | 227 |
defaultDirectoryName |
228 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
|
229 |
||
230 |
^ self defaultDirectory name |
|
231 |
||
232 |
" |
|
233 |
Filename defaultDirectoryName |
|
234 |
" |
|
235 |
! |
|
236 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
237 |
fromComponents:aCollectionOfDirectoryNames |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
238 |
"create & return a new filename from components given in |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
239 |
aCollectionOfDirectoryNames. If the first component is the name of the |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
240 |
root directory (i.e. '/') an absolute path-filename is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
241 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
242 |
|sep s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
243 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
244 |
sep := self separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
245 |
s := ''. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
246 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
247 |
index == 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
248 |
(component ~= sep |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
249 |
or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
250 |
s := s , component |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
251 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
252 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
253 |
s := s , '/' , component |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
254 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
255 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
256 |
^ self named:s |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
257 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
258 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
259 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
260 |
Filename fromComponents:#('foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
261 |
Filename fromComponents:#('/') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
262 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
263 |
Filename fromComponents: |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
264 |
(Filename components:('.' asFilename pathName)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
265 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
266 |
Filename fromComponents: |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
267 |
(Filename components:('.' asFilename name)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
268 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
269 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
270 |
"Modified: 29.2.1996 / 20:18:34 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
271 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
272 |
|
615 | 273 |
fromUser |
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
274 |
"show a box to enter a filename. |
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
275 |
Return a filename instance or nil (if cancel was pressed)." |
615 | 276 |
|
277 |
|name| |
|
278 |
||
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
279 |
name := Dialog requestFileName:'filename:' ifFail:nil. |
615 | 280 |
name notNil ifTrue:[^ self named:name]. |
281 |
^ nil |
|
282 |
||
283 |
" |
|
284 |
Filename fromUser |
|
285 |
" |
|
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
286 |
|
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
287 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
615 | 288 |
! |
289 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
290 |
homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
291 |
"return your homeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
292 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
293 |
(which is the currentDirectory) is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
294 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
295 |
|s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
296 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
297 |
s := OperatingSystem getHomeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
298 |
s isNil ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
299 |
^ self defaultDirectory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
300 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
301 |
^ s asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
302 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
303 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
304 |
Filename homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
305 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
306 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
307 |
"Modified: 29.2.1996 / 21:00:31 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
308 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
309 |
|
615 | 310 |
named:aString |
311 |
"return a filename for a directory named aString. |
|
312 |
This is the same as 'aString asFilename'." |
|
313 |
||
314 |
^ (self basicNew) setName:aString |
|
315 |
||
316 |
" |
|
317 |
Filename named:'/tmp/fooBar' |
|
318 |
" |
|
319 |
! |
|
320 |
||
276 | 321 |
newTemporary |
325 | 322 |
"return a new unique filename - use this for temporary files. |
323 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
324 |
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
|
325 |
call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
326 |
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
|
327 |
its value defines the temp directory." |
276 | 328 |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
329 |
^ self newTemporaryIn:self tempDirectory pathName |
276 | 330 |
|
331 |
" |
|
422 | 332 |
Filename newTemporary |
1080 | 333 |
Filename newTemporary |
276 | 334 |
" |
422 | 335 |
|
336 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
337 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
338 |
! |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
339 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
340 |
newTemporaryIn:aDirectoryPrefix |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
341 |
"return a new unique filename - use this for temporary files. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
342 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
343 |
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
|
344 |
with every call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
345 |
Notice: only a filename object is created and returned - no physical |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
346 |
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
|
347 |
whatever to it in order to really create something). |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
348 |
See also: #newTemporary which looks for a good temp directory." |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
349 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
350 |
|pid nm| |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
351 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
352 |
NextTempFilenameIndex isNil ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
353 |
NextTempFilenameIndex := 1. |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
354 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
355 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
356 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
357 |
the following has to be made OS independent ... |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
358 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
359 |
pid := OperatingSystem getProcessId printString. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
360 |
nm := 'stxtmp_' , pid , '_' , NextTempFilenameIndex printString. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
361 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
362 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
363 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
364 |
nm := aDirectoryPrefix asFilename construct:nm |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
365 |
] ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
366 |
nm := nm asFilename |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
367 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
368 |
^ nm |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
369 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
370 |
"temp files in '/tmp': |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
371 |
|
1080 | 372 |
Filename newTemporary |
373 |
" |
|
374 |
||
375 |
"temp files somewhere |
|
376 |
(not recommended - use above since it can be controlled via shell variables): |
|
377 |
||
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
378 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
379 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
380 |
Filename newTemporaryIn:'/usr/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
381 |
Filename newTemporaryIn:'/' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
382 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
383 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
384 |
"a local temp file: |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
385 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
386 |
Filename newTemporaryIn:'' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
387 |
Filename newTemporaryIn:nil |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
388 |
Filename newTemporaryIn:'.' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
389 |
Filename newTemporaryIn:('source' asFilename) |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
390 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
391 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
392 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
1080 | 393 |
"Modified: 7.3.1996 / 14:49:56 / cg" |
394 |
! |
|
395 |
||
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
396 |
tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
397 |
"return the temp directory as a filename. |
1968 | 398 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
399 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
400 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
401 |
|
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
402 |
Notice: do not hardcode '/tmp' into your programs - things may be |
1968 | 403 |
different on other OS's. Also, the user may want to set the |
404 |
TMPDIR environment variable to have her temp files somewhere else. |
|
405 |
(especially on SUNOS, the root partition is ALWAYS too small ..." |
|
1080 | 406 |
|
407 |
|tempDir| |
|
408 |
||
1969 | 409 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
1968 | 410 |
tempDir isNil ifTrue:[ |
411 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
412 |
]. |
|
413 |
]. |
|
1080 | 414 |
tempDir isNil ifTrue:[ |
1968 | 415 |
tempDir := '/tmp' |
1080 | 416 |
]. |
417 |
^ self named:tempDir |
|
418 |
||
419 |
" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
420 |
Filename tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
421 |
Filename tempDirectory pathName |
1080 | 422 |
" |
423 |
||
424 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
425 |
"Created: 7.3.1996 / 14:51:18 / cg" |
1969 | 426 |
"Modified: 12.11.1996 / 12:23:19 / cg" |
1 | 427 |
! ! |
428 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
429 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
430 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
431 |
concreteClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
432 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
433 |
in ST-80, different subclasses of Filename are used for different |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
434 |
OperatingSystems; concreteClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
435 |
Since in ST/X, there is (currently) only one Filename class, return it here." |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
436 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
437 |
^ self |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
438 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
439 |
"Created: 14.2.1997 / 16:36:13 / cg" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
440 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
441 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
442 |
defaultClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
443 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
444 |
in ST-80, different subclasses of Filename are used for different |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
445 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
446 |
Since in ST/X, there is (currently) only one Filename class, return it here." |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
447 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
448 |
^ self |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
449 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
450 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
451 |
isCaseSensitive |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
452 |
"return true, if filenames are case sensitive. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
453 |
We ask the OS about this, to be independent here." |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
454 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
455 |
^ OperatingSystem caseSensitiveFilenames |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
456 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
457 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
458 |
!Filename class methodsFor:'queries'! |
2 | 459 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
460 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
461 |
"separate the pathName given by aString into |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
462 |
a collection containing the directory components and the files name as |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
463 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
464 |
If the argument names an absolute path, the first component will be the |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
465 |
name of the root directory (i.e. '/')." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
466 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
467 |
|components| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
468 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
469 |
components := aString asCollectionOfSubstringsSeparatedBy:(self separator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
470 |
components first isEmpty ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
471 |
components at:1 put:(self separator asString) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
472 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
473 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
474 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
475 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
476 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
477 |
Filename components:'/foo/bar/baz' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
478 |
Filename components:'foo/bar/baz' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
479 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
480 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
481 |
"Modified: 29.2.1996 / 20:06:38 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
482 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
483 |
|
1523 | 484 |
errorReporter |
485 |
"who knows the signals to report errors?" |
|
486 |
||
487 |
^ FileStream |
|
488 |
||
489 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
490 |
! |
|
491 |
||
440 | 492 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
493 |
"perform filename completion on aString in some directory; |
|
494 |
return the longest matching filename prefix as a string. |
|
1318 | 495 |
The boolean directoriesOnly and filesOnly control respectively, |
496 |
if only directories or only regular files are to be considered for completion. |
|
497 |
If multiple files match, the exception block aBlock is evaluated with a |
|
498 |
filename representing the directory (where the match was done) as argument. |
|
440 | 499 |
(this may be different from the inDirectory argument, if aString is absolute |
500 |
or starts with ../)" |
|
501 |
||
502 |
|s f matchSet nMatch name words dir| |
|
503 |
||
504 |
s := aString. |
|
505 |
" |
|
506 |
find the last word ... |
|
507 |
" |
|
508 |
words := s asCollectionOfWords. |
|
509 |
words size == 0 ifTrue:[ |
|
1318 | 510 |
aBlock value:'.' asFilename. |
511 |
^ '' |
|
440 | 512 |
]. |
513 |
||
514 |
f := words last asFilename. |
|
515 |
||
516 |
matchSet := f filenameCompletionIn:inDirectory. |
|
517 |
||
518 |
dir := f directory. |
|
519 |
||
520 |
directoriesOnly ifTrue:[ |
|
1318 | 521 |
matchSet := matchSet select:[:aFilename | |
522 |
(dir construct:aFilename) isDirectory |
|
523 |
]. |
|
440 | 524 |
] ifFalse:[ |
1318 | 525 |
filesOnly ifTrue:[ |
526 |
matchSet := matchSet select:[:aFilename | |
|
527 |
(dir construct:aFilename) isDirectory not |
|
528 |
]. |
|
529 |
] |
|
440 | 530 |
]. |
531 |
||
532 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
1318 | 533 |
" |
534 |
more than one possible completion - |
|
535 |
" |
|
536 |
aBlock value:f |
|
440 | 537 |
]. |
538 |
" |
|
539 |
even with more than one possible completion, |
|
540 |
f's name is now the common prefix |
|
541 |
" |
|
542 |
name := f asString. |
|
543 |
nMatch == 1 ifTrue:[ |
|
1318 | 544 |
" |
545 |
exactly one possible completion - |
|
546 |
" |
|
547 |
f := dir construct:matchSet first. |
|
440 | 548 |
|
1318 | 549 |
directoriesOnly ifFalse:[ |
550 |
f isDirectory ifTrue:[ |
|
551 |
(name endsWith:(Filename separator)) ifFalse:[ |
|
552 |
name := name , '/' |
|
553 |
]. |
|
554 |
]. |
|
555 |
] |
|
440 | 556 |
]. |
557 |
||
558 |
" |
|
559 |
construct new contents, by taking |
|
560 |
last words completion |
|
561 |
" |
|
562 |
s := ''. |
|
563 |
1 to:(words size - 1) do:[:idx | |
|
1318 | 564 |
s := s , (words at:idx) , ' ' |
440 | 565 |
]. |
566 |
s := s , name. |
|
567 |
||
568 |
"/ special: if there was no change, and the string represented |
|
569 |
"/ is a directories name, add a directory separator |
|
570 |
s = aString ifTrue:[ |
|
1318 | 571 |
(s endsWith:Filename separator) ifFalse:[ |
572 |
s asFilename isDirectory ifTrue:[ |
|
573 |
^ s , Filename separator asString |
|
574 |
] |
|
575 |
] |
|
440 | 576 |
]. |
577 |
||
578 |
^ s |
|
1318 | 579 |
|
580 |
"Modified: 30.4.1996 / 12:13:20 / cg" |
|
615 | 581 |
! |
582 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
583 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
584 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
585 |
of files matching aPattern. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
586 |
If aPattern contains a diretory path, files are tried there; |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
587 |
otherwise, files from the currentDirectory are tried. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
588 |
The returned strings do not contain the pathName - only the |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
589 |
files basename" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
590 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
591 |
|dir| |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
592 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
593 |
dir := aPattern asFilename directoryName. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
594 |
^ dir asFilename filesMatching:aPattern asFilename baseName |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
595 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
596 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
597 |
Filename filesMatching:'*' |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
598 |
Filename filesMatching:'/*' |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
599 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
600 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
601 |
"Modified: 14.2.1997 / 16:34:25 / cg" |
615 | 602 |
! |
603 |
||
604 |
localNameStringFrom:aString |
|
605 |
"ST-80 compatibility. |
|
606 |
what does this do ? (used in FileNavigator-goody). |
|
607 |
GUESS: does it strip off the voulume-character on MSDOS systems ?" |
|
608 |
||
609 |
(aString startsWith:'/') ifTrue:[ |
|
610 |
^ aString copyFrom:2 |
|
611 |
]. |
|
612 |
^ aString |
|
613 |
||
614 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
615 |
! |
|
616 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
617 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
618 |
"return the maximum number of characters a filename may be in size. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
619 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
620 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
621 |
^ OperatingSystem maxFileNameLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
622 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
623 |
"Created: 29.2.1996 / 20:57:11 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
624 |
"Modified: 29.2.1996 / 20:57:46 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
625 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
626 |
|
615 | 627 |
parentDirectoryName |
628 |
"return the name used for the parent directory. |
|
629 |
This is '..' for unix and dos-like systems. |
|
630 |
(there may be more in the future." |
|
631 |
||
632 |
^ OperatingSystem parentDirectoryName |
|
633 |
||
634 |
" |
|
635 |
Filename parentDirectoryName |
|
636 |
" |
|
637 |
! |
|
638 |
||
639 |
separator |
|
640 |
"return the file/directory separator. |
|
641 |
Usually, this is $/ for unix-like systems |
|
642 |
and $\ for dos-like ones (there may be more in the future)." |
|
643 |
||
644 |
^ OperatingSystem fileSeparator |
|
645 |
||
646 |
" |
|
647 |
Filename separator |
|
648 |
" |
|
649 |
! |
|
650 |
||
651 |
suffixSeparator |
|
652 |
"return the filename suffix separator. |
|
653 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 654 |
(there is currently no known system, where this differs)" |
615 | 655 |
|
656 |
^ $. |
|
657 |
||
658 |
" |
|
659 |
Filename suffixSeparator |
|
660 |
" |
|
661 |
||
662 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 663 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 664 |
! |
665 |
||
666 |
volumes |
|
667 |
"ST-80 compatibility. |
|
668 |
what does this do ? (used in FileNavigator-goody). |
|
669 |
GUESS: does it return the available drives on MSDOS systems ?" |
|
670 |
||
671 |
^ #('/') |
|
672 |
||
673 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
674 |
! ! |
|
675 |
||
676 |
!Filename methodsFor:'comparing'! |
|
677 |
||
678 |
= aFilename |
|
679 |
"return true, if the argument represents the same filename" |
|
680 |
||
681 |
|str| |
|
682 |
||
683 |
self species == aFilename species ifTrue:[ |
|
684 |
str := aFilename asString. |
|
685 |
self class isCaseSensitive ifTrue:[ |
|
686 |
^ nameString = str |
|
687 |
]. |
|
688 |
^ nameString sameAs:str |
|
689 |
]. |
|
690 |
^ false |
|
691 |
! |
|
692 |
||
693 |
hash |
|
694 |
"return an integer useful as a hash-key" |
|
695 |
||
696 |
^ nameString hash |
|
697 |
! ! |
|
698 |
||
699 |
!Filename methodsFor:'converting'! |
|
700 |
||
701 |
asAbsoluteFilename |
|
702 |
"return the receiver converted to a filename with |
|
703 |
an absolute pathname." |
|
704 |
||
705 |
^ self pathName asFilename |
|
706 |
! |
|
707 |
||
708 |
asFilename |
|
1970 | 709 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 710 |
|
711 |
"Thats pretty easy here :-)" |
|
712 |
^ self |
|
1970 | 713 |
|
714 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 715 |
! |
716 |
||
717 |
asString |
|
718 |
"return the receiver converted to a string" |
|
719 |
||
720 |
^ nameString |
|
721 |
! |
|
722 |
||
723 |
makeLegalFilename |
|
1970 | 724 |
"convert the receivers name to be a legal filename. |
725 |
This removes/replaces invalid characters and/or compresses |
|
726 |
the name as required by the OS. |
|
615 | 727 |
The implementation may change in the future to be more |
728 |
OS specific." |
|
729 |
||
730 |
" |
|
731 |
actually, in Unix spaces are allowed - but it makes life |
|
732 |
so hard; therefore, replace them by underscores ... |
|
733 |
" |
|
734 |
nameString replaceAll:(Character space) by:$_. |
|
735 |
" |
|
736 |
need more - especially on SYS5.3 type systems, |
|
737 |
we may want to contract the fileName to 14 characters. |
|
738 |
" |
|
739 |
^ self |
|
740 |
||
741 |
" |
|
742 |
'hello world' asFilename makeLegalFilename |
|
743 |
" |
|
1970 | 744 |
|
745 |
"Modified: 12.11.1996 / 12:39:04 / cg" |
|
2 | 746 |
! ! |
747 |
||
542 | 748 |
!Filename methodsFor:'error handling'! |
749 |
||
615 | 750 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
751 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
752 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
753 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
754 |
|
615 | 755 |
^ OperatingSystem accessDeniedErrorSignal |
542 | 756 |
raiseRequestWith:filename |
615 | 757 |
errorString:('access denied: ' , filename asString) |
758 |
! |
|
759 |
||
760 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
761 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
762 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
763 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
764 |
|
615 | 765 |
^ OperatingSystem accessDeniedErrorSignal |
766 |
raiseRequestWith:filename |
|
767 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 768 |
! |
769 |
||
770 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
771 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
772 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
773 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
774 |
|
542 | 775 |
^ OperatingSystem fileNotFoundErrorSignal |
776 |
raiseRequestWith:filename |
|
777 |
errorString:('file not found: ' , filename asString) |
|
778 |
! |
|
779 |
||
780 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
781 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
782 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
783 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
784 |
|
542 | 785 |
^ OperatingSystem accessDeniedErrorSignal |
786 |
raiseRequestWith:filename |
|
787 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 788 |
! |
789 |
||
790 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
791 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
792 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
793 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
794 |
|
615 | 795 |
^ OperatingSystem errorSignal |
796 |
raiseRequestWith:filename |
|
797 |
errorString:string |
|
798 |
! ! |
|
799 |
||
800 |
!Filename methodsFor:'file access'! |
|
801 |
||
802 |
appendingWriteStream |
|
803 |
"return a stream for appending to the file represented by the receiver. |
|
804 |
If the file does not already exist, it is created." |
|
805 |
||
806 |
^ FileStream appendingOldFileNamed:nameString |
|
807 |
! |
|
808 |
||
809 |
newReadWriteStream |
|
810 |
"return a stream for read/write the file represented by the receiver. |
|
811 |
If the file does not already exist, it is created." |
|
812 |
||
813 |
^ FileStream newFileNamed:nameString |
|
814 |
! |
|
815 |
||
816 |
readStream |
|
817 |
"return a stream for reading from the file represented by the receiver. |
|
818 |
If the file does not already exist, nil is returned." |
|
819 |
||
820 |
^ FileStream readonlyFileNamed:nameString |
|
821 |
||
822 |
" |
|
823 |
'/tmp/foo' asFilename readStream |
|
824 |
" |
|
825 |
! |
|
826 |
||
827 |
readWriteStream |
|
828 |
"return a stream for read/write the file represented by the receiver. |
|
829 |
If the file does not already exist, nil is returned." |
|
830 |
||
831 |
^ FileStream oldFileNamed:nameString |
|
832 |
! |
|
833 |
||
834 |
writeStream |
|
835 |
"return a stream for writing to the file represented by the receiver. |
|
836 |
If the file does not already exist, it is created." |
|
837 |
||
838 |
^ FileStream newFileForWritingNamed:nameString |
|
839 |
||
840 |
" |
|
841 |
'/tmp/foo' asFilename writeStream |
|
842 |
" |
|
843 |
! ! |
|
844 |
||
845 |
!Filename methodsFor:'file operations'! |
|
846 |
||
847 |
addAccessRights:aCollection |
|
848 |
"add the access rights as specified in aCollection for the file represented |
|
849 |
by the receiver. The argument must be a collection of symbols, |
|
850 |
such as #readUser, #writeGroup etc." |
|
851 |
||
852 |
|access| |
|
853 |
||
854 |
access := OperatingSystem accessModeOf:nameString. |
|
855 |
aCollection do:[:accessSymbol | |
|
856 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
857 |
]. |
|
858 |
(OperatingSystem changeAccessModeOf:nameString to:access) ifFalse:[ |
|
859 |
^ self accessDeniedError:self |
|
860 |
] |
|
861 |
||
862 |
" |
|
863 |
'foo' asFilename writeStream close. |
|
864 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
865 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
866 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
867 |
" |
|
868 |
! |
|
869 |
||
870 |
copyTo:newName |
|
871 |
"copy the file - the argument must be convertable to a filename. |
|
671 | 872 |
Return true if successful, false if not." |
615 | 873 |
|
874 |
|inStream outStream buffer bufferSize count newFile| |
|
875 |
||
876 |
bufferSize := 8 * 1024. |
|
877 |
buffer := ByteArray new:bufferSize. |
|
878 |
inStream := self readStream. |
|
879 |
inStream isNil ifTrue:[ |
|
880 |
^ self fileNotFoundError:self |
|
881 |
]. |
|
882 |
||
883 |
outStream := (newFile := newName asFilename) writeStream. |
|
884 |
outStream isNil ifTrue:[ |
|
885 |
^ self fileCreationError:newFile |
|
886 |
]. |
|
887 |
||
888 |
[inStream atEnd] whileFalse:[ |
|
889 |
count := inStream nextBytes:bufferSize into:buffer. |
|
890 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
|
891 |
^ self fileCreationError:newFile |
|
892 |
] |
|
893 |
]. |
|
894 |
outStream close. |
|
895 |
inStream close. |
|
896 |
||
897 |
" |
|
898 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
899 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
900 |
" |
|
901 |
! |
|
902 |
||
903 |
delete |
|
904 |
"remove the file - same as remove, for ST-80 compatibility" |
|
905 |
||
906 |
self remove |
|
907 |
! |
|
908 |
||
909 |
makeDirectory |
|
910 |
"create a directory with the receivers name. |
|
671 | 911 |
Return true if successful, false if not." |
615 | 912 |
|
913 |
(OperatingSystem createDirectory:nameString) ifFalse:[ |
|
1970 | 914 |
(self exists and:[self isDirectory]) ifFalse:[ |
915 |
^ self fileCreationError:self |
|
916 |
] |
|
615 | 917 |
] |
1970 | 918 |
|
919 |
"Modified: 12.11.1996 / 12:25:22 / cg" |
|
615 | 920 |
! |
921 |
||
844 | 922 |
makeExecutable |
923 |
"make the file executable - you must have permission to do so. |
|
924 |
For directories, execution means: 'allow changing into it'" |
|
925 |
||
926 |
^ self addAccessRights:#(executeUser) |
|
927 |
||
928 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
929 |
! |
|
930 |
||
931 |
makeExecutableForAll |
|
932 |
"make the file executable for all - you must have permission to do so. |
|
933 |
For directories, execution means: 'allow changing into it'" |
|
934 |
||
935 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
936 |
||
937 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
938 |
! |
|
939 |
||
615 | 940 |
makeReadable |
941 |
"make the file readable for the owner - you must have permission to do so." |
|
942 |
||
943 |
^ self addAccessRights:#(readUser) |
|
944 |
! |
|
945 |
||
946 |
makeReadableForAll |
|
947 |
"make the file readable for all - you must have permission to do so." |
|
948 |
||
949 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
950 |
! |
|
951 |
||
952 |
makeUnwritable |
|
953 |
"make the file unwritable for all - you must have permission to do so." |
|
954 |
||
955 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
956 |
! |
|
957 |
||
958 |
makeWritable |
|
959 |
"make the file writableable for all - you must have permission to do so." |
|
960 |
||
961 |
^ self addAccessRights:#(writeUser) |
|
962 |
! |
|
963 |
||
964 |
makeWritableForAll |
|
965 |
"make the file writable for all - you must have permission to do so." |
|
966 |
||
967 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
968 |
! |
|
969 |
||
970 |
moveTo:newName |
|
971 |
"copy the file represented by the receiver, then delete it. |
|
972 |
This is different to renaming in case of cross device moves. |
|
671 | 973 |
Raise an error if not successful." |
615 | 974 |
|
975 |
self copyTo:newName. |
|
976 |
self remove |
|
977 |
! |
|
978 |
||
659 | 979 |
recursiveMakeDirectory |
980 |
"create a directory with the receivers name and all required intermediate |
|
981 |
directories. |
|
671 | 982 |
Raise an error if not successful." |
659 | 983 |
|
984 |
(OperatingSystem recursiveCreateDirectory:nameString) ifFalse:[ |
|
671 | 985 |
^ self fileCreationError:self |
659 | 986 |
] |
987 |
||
988 |
"Created: 27.11.1995 / 23:36:40 / cg" |
|
989 |
! |
|
990 |
||
615 | 991 |
recursiveRemove |
671 | 992 |
"remove the directory and all of its subfiles/subdirectories. |
993 |
Raise an error if not successful." |
|
615 | 994 |
|
995 |
|ok| |
|
996 |
||
997 |
ok := OperatingSystem recursiveRemoveDirectory:nameString. |
|
998 |
ok ifFalse:[ |
|
999 |
self removeError:self |
|
1000 |
]. |
|
1001 |
||
1002 |
" |
|
1003 |
'foo' asFilename makeDirectory. |
|
1004 |
'foo/bar' asFilename writeStream close. |
|
1005 |
('foo' asFilename remove) ifFalse:[ |
|
1422 | 1006 |
Transcript showCR:'could not remove foo' |
615 | 1007 |
] |
1008 |
" |
|
1009 |
" |
|
1010 |
'foo' asFilename makeDirectory. |
|
1011 |
'foo/bar' asFilename writeStream close. |
|
1012 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
1422 | 1013 |
Transcript showCR:'could not remove foo' |
615 | 1014 |
] |
1015 |
" |
|
1016 |
||
1017 |
"Created: 14.11.1995 / 11:19:29 / cg" |
|
1018 |
! |
|
1019 |
||
1020 |
remove |
|
845 | 1021 |
"remove the file/directory. |
672 | 1022 |
Raise an error if not successful. |
845 | 1023 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 1024 |
|
1025 |
|ok| |
|
1026 |
||
1027 |
self exists ifFalse:[ ^ self]. |
|
1028 |
self isDirectory ifTrue:[ |
|
883 | 1029 |
ok := OperatingSystem removeDirectory:nameString |
615 | 1030 |
] ifFalse:[ |
883 | 1031 |
ok := OperatingSystem removeFile:nameString |
615 | 1032 |
]. |
1033 |
ok ifFalse:[ |
|
883 | 1034 |
self removeError:self |
615 | 1035 |
]. |
1036 |
||
1037 |
" |
|
1038 |
(FileStream newFileNamed:'foo') close. |
|
1039 |
'foo' asFilename remove |
|
1040 |
" |
|
1041 |
||
1042 |
" |
|
1043 |
'foo' asFilename makeDirectory. |
|
1044 |
'foo/bar' asFilename writeStream close. |
|
1045 |
('foo' asFilename remove) ifFalse:[ |
|
1422 | 1046 |
Transcript showCR:'could not remove foo' |
615 | 1047 |
] |
1048 |
" |
|
1049 |
||
845 | 1050 |
"Modified: 10.1.1996 / 18:44:50 / cg" |
615 | 1051 |
! |
1052 |
||
1053 |
removeAccessRights:aCollection |
|
1054 |
"remove the access rights as specified in aCollection for the file represented |
|
1055 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 1056 |
such as #readUser, #writeGroup etc. |
1057 |
Raise an error if not successful." |
|
615 | 1058 |
|
1059 |
|access| |
|
1060 |
||
1061 |
access := OperatingSystem accessModeOf:nameString. |
|
1062 |
aCollection do:[:accessSymbol | |
|
1063 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
|
1064 |
]. |
|
1065 |
(OperatingSystem changeAccessModeOf:nameString to:access) ifFalse:[ |
|
1066 |
^ self accessDeniedError:self |
|
1067 |
]. |
|
1068 |
||
1069 |
" |
|
1070 |
'foo' asFilename writeStream close. |
|
1071 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
1072 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
1073 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
1074 |
" |
|
1075 |
! |
|
1076 |
||
1077 |
renameTo:newName |
|
671 | 1078 |
"rename the file - the argument must be convertable to a String. |
1079 |
Raise an error if not successful." |
|
615 | 1080 |
|
1081 |
|ok| |
|
1082 |
||
1083 |
ok := OperatingSystem renameFile:nameString to:(newName asString). |
|
1084 |
ok ifFalse:[ |
|
1085 |
self exists ifFalse:[ |
|
1086 |
^ self fileNotFoundError:self |
|
1087 |
]. |
|
1088 |
^ self accessDeniedError:newName asFilename. |
|
1089 |
]. |
|
1090 |
||
1091 |
" |
|
1092 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1093 |
" |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1094 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1095 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1096 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1097 |
"change the files size. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1098 |
This may not be supported on all operating systems" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1099 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1100 |
(OperatingSystem truncateFile:nameString to:newSize) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1101 |
^ self reportError:'unsupported operation' with:self |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1102 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1103 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1104 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1105 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1106 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1107 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1108 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1109 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1110 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1111 |
'test' asFilename truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1112 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1113 |
" |
615 | 1114 |
! ! |
1115 |
||
1116 |
!Filename methodsFor:'file queries'! |
|
1117 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1118 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1119 |
"return a timeStamp containing the files last access time." |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1120 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1121 |
^ self dates at:#accessed |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1122 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1123 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1124 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1125 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1126 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1127 |
"Created: 9.7.1996 / 10:19:15 / cg" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1128 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1129 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1130 |
|
615 | 1131 |
dates |
1132 |
"return the files modification and access times as an object (currently a dictionary) |
|
1133 |
that responds to the at: message with arguments |
|
1134 |
#modified, #accessed or #statusChanged." |
|
1135 |
||
1136 |
|info dates| |
|
1137 |
||
1138 |
info := OperatingSystem infoOf:nameString. |
|
1139 |
info isNil ifTrue:[ |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1140 |
info := OperatingSystem linkInfoOf:nameString. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1141 |
info isNil ifTrue:[ |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1142 |
^ nil |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1143 |
] |
615 | 1144 |
]. |
1145 |
dates := IdentityDictionary new. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1146 |
dates at:#modified put:(info modified). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1147 |
dates at:#accessed put:(info accessed). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1148 |
dates at:#statusChanged put:(info statusChanged). |
615 | 1149 |
^ dates |
1150 |
||
1151 |
" |
|
1152 |
Filename currentDirectory dates |
|
1153 |
'../regression' asFilename dates |
|
1154 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1155 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1156 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 1157 |
! |
1158 |
||
1159 |
fileSize |
|
1160 |
"return the size of the file in bytes" |
|
1161 |
||
1162 |
|info| |
|
1163 |
||
1164 |
info := self info. |
|
1165 |
info isNil ifTrue:[^ nil]. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1166 |
^ info size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1167 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1168 |
"Modified: 1.11.1996 / 20:24:43 / cg" |
615 | 1169 |
! |
1170 |
||
1171 |
fileType |
|
1172 |
"this returns a string describing the type of contents of |
|
1173 |
the file. This is done using the unix 'file' command, |
|
1174 |
(which usually is configurable by /etc/magic). |
|
1175 |
On non-unix systems, this may return an empty string, not knowning |
|
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1176 |
about the contents. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1177 |
Since the returned string differs among systems (and language settings), |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1178 |
it is only useful for user-information; NOT as a tag to be used by a program." |
615 | 1179 |
|
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1180 |
|stream buffer s n typeString suffix idx| |
615 | 1181 |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1182 |
"/ since executing 'file' takes some time, do the most obvious |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1183 |
"/ ones here. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1184 |
"/ (also useful for systems, which have no file command, such as NT) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1185 |
|
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1186 |
self isSymbolicLink ifTrue:[ |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1187 |
^ 'symbolic link to ' , (self linkInfo path) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1188 |
]. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1189 |
self isDirectory ifTrue:[^ 'directory']. |
1602 | 1190 |
self isReadable ifFalse:[^ 'unreadable']. |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1191 |
self fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 1192 |
|
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1193 |
buffer := String new:512. |
1602 | 1194 |
s := self readStream. |
1195 |
s notNil ifTrue:[ |
|
1196 |
n := s nextBytes:buffer size into:buffer. |
|
1197 |
s close. |
|
1198 |
n == buffer size ifTrue:[ |
|
1199 |
((suffix := self suffix) = 'st' |
|
1200 |
or:[suffix = 'ST']) ifTrue:[ |
|
1201 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
|
1202 |
^ 'smalltalk source' |
|
1203 |
]. |
|
1204 |
]. |
|
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1205 |
(suffix = 'htm' |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1206 |
or:[suffix = 'HTM' |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1207 |
or:[suffix = 'html' |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1208 |
or:[suffix = 'HTML']]]) ifTrue:[ |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1209 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1210 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1211 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1212 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1213 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1214 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1215 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1216 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1217 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1218 |
ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1219 |
^ 'HTML document text' |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1220 |
] |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1221 |
]. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1222 |
]. |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1223 |
|
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1224 |
(suffix = 'ps' |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1225 |
or:[suffix = 'PS']) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1226 |
ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1227 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1228 |
^ 'PostScript document' |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1229 |
]. |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1230 |
]. |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1231 |
|
1602 | 1232 |
self baseName = 'Makefile' ifTrue:[ |
1233 |
(buffer startsWith:'#') ifTrue:[ |
|
1234 |
^ 'make rules' |
|
1235 |
] |
|
1236 |
] |
|
1237 |
] |
|
1238 |
]. |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1239 |
|
615 | 1240 |
typeString := ''. |
1241 |
stream := PipeStream readingFrom:('file ' , self pathName). |
|
1242 |
stream notNil ifTrue:[ |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1243 |
typeString := stream contents asString. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1244 |
stream close. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1245 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1246 |
typeString := typeString withoutSeparators |
615 | 1247 |
] ifFalse:[ |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1248 |
" |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1249 |
could add some fallback code here, for systems, where no |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1250 |
file command is avaliable ... |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1251 |
... or at least analyze directory info. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1252 |
" |
615 | 1253 |
]. |
1254 |
^ typeString |
|
1255 |
||
1256 |
" |
|
1257 |
'Makefile' asFilename fileType |
|
1258 |
'.' asFilename fileType |
|
1259 |
'/dev/null' asFilename fileType |
|
1260 |
'smalltalk.rc' asFilename fileType |
|
1261 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
1262 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1263 |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1264 |
"Modified: 1.11.1996 / 20:48:54 / cg" |
615 | 1265 |
! |
1266 |
||
1267 |
info |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1268 |
"return some object filled with the files info; |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1269 |
the info (for which corresponding access methods are understood by |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1270 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1271 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1272 |
type - a symbol giving the files fileType |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1273 |
mode - numeric access mode |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1274 |
uid - owners user id |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1275 |
gid - owners group id |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1276 |
size - files size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1277 |
id - files number (i.e. inode number) |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1278 |
accessed - last access time (as osTime-stamp) |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1279 |
modified - last modification time (as osTime-stamp) |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1280 |
statusChanged - last staus change (as osTime-stamp) |
615 | 1281 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1282 |
Some of the fields may be returned as nil on systems which do not provide |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1283 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1284 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1285 |
modified |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1286 |
size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1287 |
type |
615 | 1288 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1289 |
Dont expect things like uid/gid/mode to be non-nil; write your application |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1290 |
to either handle nil values, |
615 | 1291 |
or (better) use one of isXXXX query methods. (Be prepared for DOS ...) |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1292 |
(i.e. instead of: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1293 |
someFilename type == #directory |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1294 |
use |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1295 |
someFIlename isDirectory |
615 | 1296 |
" |
1297 |
||
1298 |
^ OperatingSystem infoOf:nameString |
|
1299 |
||
1300 |
" |
|
1301 |
Filename currentDirectory info |
|
1302 |
'/dev/null' asFilename info |
|
1303 |
'Make.proto' asFilename info |
|
1304 |
'source/Point.st' asFilename info |
|
1305 |
'source/Point.st' asFilename linkInfo |
|
1306 |
'../../libbasic/Point.st' asFilename info |
|
1307 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1308 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1309 |
"Modified: 1.11.1996 / 20:22:40 / cg" |
615 | 1310 |
! |
1311 |
||
1312 |
linkInfo |
|
1313 |
"return the files info if its a symbolic link; nil otherwise. |
|
1314 |
On OS's which do not support symbolic links, nil is always returned. |
|
1315 |
The information is the same as returned by #info, except that if the |
|
1316 |
receiver represents a symbolic link, the links information |
|
1317 |
is returned |
|
1318 |
(while in this case, #info returns the info of the target file, |
|
1319 |
which is accessed via the symbolic link). |
|
1320 |
||
1321 |
In addition to the normal entries, Unix returns an additional entry: |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1322 |
path -> the target files pathname |
615 | 1323 |
|
1324 |
See the comment in #info for more details." |
|
1325 |
||
1326 |
^ OperatingSystem linkInfoOf:nameString |
|
1327 |
||
1328 |
" |
|
1329 |
Filename currentDirectory linkInfo |
|
1330 |
'/dev/null' asFilename linkInfo |
|
1331 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1332 |
'Make.proto' asFilename linkInfo path |
615 | 1333 |
'source/Point.st' asFilename linkInfo |
1334 |
'../../libbasic/Point.st' asFilename linkInfo |
|
1335 |
" |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1336 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1337 |
"Modified: 1.11.1996 / 20:49:09 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1338 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1339 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1340 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1341 |
"return a timeStamp containing the files modification time." |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1342 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1343 |
^ self dates at:#modified |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1344 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1345 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1346 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1347 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1348 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1349 |
"Created: 9.7.1996 / 10:18:59 / cg" |
615 | 1350 |
! ! |
1351 |
||
1352 |
!Filename methodsFor:'file utilities'! |
|
1353 |
||
1354 |
edit |
|
1355 |
"start an editView on the file represented by the receiver" |
|
1356 |
||
1357 |
EditTextView openOn:self asString |
|
1358 |
||
1359 |
" |
|
1360 |
'smalltalk.rc' asFilename edit |
|
1361 |
" |
|
1362 |
! |
|
1363 |
||
1364 |
fileIn |
|
1365 |
"load smalltalk code from the file" |
|
1366 |
||
1367 |
^ self readStream fileIn |
|
542 | 1368 |
! ! |
1369 |
||
2 | 1370 |
!Filename methodsFor:'instance creation'! |
1371 |
||
615 | 1372 |
construct:subname |
1373 |
"taking the receiver as a directory name, construct a new |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1374 |
filename for an entry within this directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1375 |
(i.e. for a file or a subdirectory in that directory). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1376 |
See also: #withSuffix: (which is different, but often needed)" |
615 | 1377 |
|
1378 |
^ (self constructString:subname) asFilename |
|
1379 |
||
1380 |
" |
|
1381 |
'/tmp' asFilename construct:'foo' |
|
1382 |
'/' asFilename construct:'foo' |
|
1383 |
'/usr/tmp' asFilename construct:'foo' |
|
1384 |
'/foo/bar' asFilename construct:'baz' |
|
1385 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1386 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1387 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
615 | 1388 |
! |
1389 |
||
249 | 1390 |
constructString:subname |
38 | 1391 |
"taking the receiver as a directory name, construct a new |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1392 |
filenames string for an entry within this directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1393 |
(i.e. for a file or a subdirectory in that directory)." |
38 | 1394 |
|
276 | 1395 |
|sepString| |
202 | 1396 |
|
1397 |
sepString := self class separator asString. |
|
1398 |
nameString = sepString ifTrue:[ |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1399 |
"I am the root" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1400 |
^ sepString , subname |
85 | 1401 |
]. |
422 | 1402 |
^ nameString , sepString , subname asString |
38 | 1403 |
|
85 | 1404 |
" |
249 | 1405 |
'/tmp' asFilename constructString:'foo' |
1406 |
'/' asFilename constructString:'foo' |
|
1407 |
'/usr/tmp' asFilename constructString:'foo' |
|
328 | 1408 |
'/foo/bar' asFilename constructString:'baz' |
249 | 1409 |
" |
422 | 1410 |
|
1411 |
"Modified: 7.9.1995 / 10:15:22 / claus" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1412 |
"Modified: 29.2.1996 / 20:55:18 / cg" |
2 | 1413 |
! ! |
1414 |
||
195 | 1415 |
!Filename methodsFor:'misc'! |
1416 |
||
1417 |
, aString |
|
1418 |
"this allows filenames to understand how names are concatenated. |
|
308 | 1419 |
Returns a string consisting of the receivers name, concatenated |
195 | 1420 |
by aString. Notice this is NOT the same as construct:, which inserts |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1421 |
a directory delimiter and returns a new fileName instance. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1422 |
See also: #withSuffix: which is new and better." |
195 | 1423 |
|
308 | 1424 |
^ (nameString , aString asString) |
195 | 1425 |
|
1426 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1427 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1428 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1429 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1430 |
'Makefile' asFilename construct:'.bak' |
195 | 1431 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1432 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1433 |
"Modified: 29.2.1996 / 20:54:12 / cg" |
195 | 1434 |
! ! |
1435 |
||
615 | 1436 |
!Filename methodsFor:'printing & storing'! |
174 | 1437 |
|
615 | 1438 |
printOn:aStream |
1439 |
"append a printed representation of the receiver to aStream." |
|
174 | 1440 |
|
615 | 1441 |
aStream nextPutAll:'FileName('''. |
1442 |
nameString printOn:aStream. |
|
1443 |
aStream nextPutAll:''')' |
|
1 | 1444 |
! |
1445 |
||
615 | 1446 |
storeOn:aStream |
1447 |
"append a printed representation of the receiver to aStream, |
|
1448 |
which allows reconstructing it via readFrom:" |
|
328 | 1449 |
|
615 | 1450 |
aStream nextPut:$(. |
1451 |
nameString storeOn:aStream. |
|
1452 |
aStream nextPutAll:' asFilename)' |
|
1 | 1453 |
! ! |
1454 |
||
202 | 1455 |
!Filename methodsFor:'private accessing'! |
1 | 1456 |
|
68 | 1457 |
setName:aString |
38 | 1458 |
"set the filename" |
1459 |
||
68 | 1460 |
nameString := aString |
1 | 1461 |
! ! |
1462 |
||
2 | 1463 |
!Filename methodsFor:'queries'! |
1464 |
||
615 | 1465 |
canBeWritten |
1466 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 1467 |
|
615 | 1468 |
^ self isWritable |
92 | 1469 |
|
328 | 1470 |
" |
615 | 1471 |
'/foo/bar' asFilename canBeWritten |
1472 |
'/tmp' asFilename canBeWritten |
|
1473 |
'Makefile' asFilename canBeWritten |
|
328 | 1474 |
" |
1475 |
! |
|
1476 |
||
68 | 1477 |
exists |
92 | 1478 |
"return true, if such a file exists." |
68 | 1479 |
|
1480 |
^ OperatingSystem isValidPath:nameString |
|
1481 |
||
85 | 1482 |
" |
92 | 1483 |
'/foo/bar' asFilename exists |
1484 |
'/tmp' asFilename exists |
|
1485 |
'Makefile' asFilename exists |
|
85 | 1486 |
" |
77 | 1487 |
! |
1488 |
||
615 | 1489 |
isAbsolute |
1490 |
"return true, if the receiver represents an absolute pathname |
|
1491 |
(in contrast to one relative to the current directory)." |
|
356 | 1492 |
|
615 | 1493 |
^ (nameString startsWith:self class separator) |
328 | 1494 |
|
1495 |
" |
|
615 | 1496 |
'/foo/bar' asFilename isAbsolute |
1497 |
'..' asFilename isAbsolute |
|
1498 |
'..' asAbsoluteFilename isAbsolute |
|
1499 |
'source/SBrowser.st' asFilename isAbsolute |
|
1500 |
" |
|
1501 |
! |
|
1502 |
||
1503 |
isDirectory |
|
1504 |
"return true, if the receiver represents an existing, |
|
1505 |
readable directories pathname." |
|
1506 |
||
1507 |
^ OperatingSystem isDirectory:nameString |
|
1508 |
||
1509 |
" |
|
1510 |
'/foo/bar' asFilename isDirectory |
|
1511 |
'/tmp' asFilename isDirectory |
|
1512 |
'Makefile' asFilename isDirectory |
|
1513 |
" |
|
1514 |
! |
|
1515 |
||
1516 |
isExecutable |
|
1517 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
1518 |
For directories, true is returned if the directory can be entered. |
|
1519 |
See isExecutableProgram for a related check." |
|
1520 |
||
1521 |
^ OperatingSystem isExecutable:nameString |
|
1522 |
||
1523 |
" |
|
1524 |
'/foo/bar' asFilename isExecutable |
|
1525 |
'/tmp' asFilename isExecutable |
|
1526 |
'Makefile' asFilename isExecutable |
|
1527 |
'/bin/ls' asFilename isExecutable |
|
356 | 1528 |
" |
1529 |
! |
|
1530 |
||
615 | 1531 |
isExecutableProgram |
1532 |
"return true, if such a file exists and is an executable program. |
|
1533 |
(i.e. for directories, false is returned.)" |
|
356 | 1534 |
|
615 | 1535 |
^ (OperatingSystem isExecutable:nameString) |
1536 |
and:[(OperatingSystem isDirectory:nameString) not] |
|
356 | 1537 |
|
1538 |
" |
|
615 | 1539 |
'/tmp' asFilename isExecutable |
1540 |
'/bin/ls' asFilename isExecutable |
|
1541 |
'/tmp' asFilename isExecutableProgram |
|
1542 |
'/bin/ls' asFilename isExecutableProgram |
|
1543 |
" |
|
1544 |
! |
|
1545 |
||
1546 |
isReadable |
|
1547 |
"return true, if such a file exists and is readable." |
|
1548 |
||
1549 |
^ OperatingSystem isReadable:nameString |
|
1550 |
||
1551 |
" |
|
1552 |
'/foo/bar' asFilename isReadable |
|
1553 |
'/tmp' asFilename isReadable |
|
1554 |
'Makefile' asFilename isReadable |
|
328 | 1555 |
" |
1556 |
! |
|
1557 |
||
615 | 1558 |
isRelative |
1559 |
"return true, if this name is interpreted relative to some |
|
1560 |
directory (opposite of absolute)" |
|
328 | 1561 |
|
615 | 1562 |
^ self isAbsolute not |
2175 | 1563 |
|
1564 |
" |
|
1565 |
'./foo/bar' asFilename isRelative |
|
1566 |
'../../foo/bar' asFilename isRelative |
|
1567 |
'/foo/bar' asFilename isRelative |
|
1568 |
'bar' asFilename isRelative |
|
1569 |
" |
|
1570 |
||
1571 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
615 | 1572 |
! |
328 | 1573 |
|
615 | 1574 |
isSymbolicLink |
1575 |
"return true, if the file represented by the receiver is a symbolic |
|
1576 |
link. Notice that not all OS's support symbolic links; those that do |
|
1577 |
not will always return false." |
|
1578 |
||
1579 |
^ OperatingSystem isSymbolicLink:nameString |
|
328 | 1580 |
|
1581 |
" |
|
615 | 1582 |
'Make.proto' asFilename isSymbolicLink |
1583 |
'Makefile' asFilename isSymbolicLink |
|
1584 |
" |
|
1585 |
! |
|
1586 |
||
1587 |
isWritable |
|
1588 |
"return true, if such a file exists and is writable." |
|
1589 |
||
1590 |
^ OperatingSystem isWritable:nameString |
|
1591 |
||
1592 |
" |
|
1593 |
'/foo/bar' asFilename isWritable |
|
1594 |
'/tmp' asFilename isWritable |
|
1595 |
'Makefile' asFilename isWritable |
|
328 | 1596 |
" |
174 | 1597 |
! |
1598 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1599 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1600 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1601 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1602 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1603 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1604 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1605 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1606 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1607 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1608 |
|
1540 | 1609 |
contents |
1610 |
"return the contents of the file as a collection of lines; |
|
1611 |
or nil, if the file is unreadable." |
|
1612 |
||
1613 |
|s contents| |
|
1614 |
||
1615 |
s := self readStream. |
|
1616 |
s isNil ifTrue:[^ nil]. |
|
1617 |
||
1618 |
[ |
|
1619 |
contents := s contents |
|
1620 |
] valueNowOrOnUnwindDo:[s close]. |
|
1621 |
^ contents |
|
1622 |
||
1623 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1624 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
|
1625 |
"Created: 11.7.1996 / 14:09:11 / cg" |
|
1626 |
! |
|
1627 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1628 |
contentsOfEntireFile |
1540 | 1629 |
"return the contents of the file as a string; |
1630 |
or nil, if the file is unreadable." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1631 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1632 |
|s contents| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1633 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1634 |
s := self readStream. |
1535 | 1635 |
s isNil ifTrue:[^ nil]. |
1636 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1637 |
[ |
1523 | 1638 |
contents := s contentsOfEntireFile |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1639 |
] valueNowOrOnUnwindDo:[s close]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1640 |
^ contents |
1523 | 1641 |
|
1642 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1540 | 1643 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1644 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1645 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1646 |
directoryContents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1647 |
"return the contents of the directory as a collection of strings" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1648 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1649 |
^ (FileDirectory directoryNamed:self asString) contents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1650 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1651 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1652 |
'.' asFilename directoryContents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1653 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1654 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1655 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1656 |
filesMatching:aPattern |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1657 |
"given the receiver, representing a directory; |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1658 |
return a collection of files matching a pattern." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1659 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1660 |
^ self directoryContents select:[:name | aPattern match:name] |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1661 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1662 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1663 |
Filename currentDirectory filesMatching:'M*' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1664 |
'/etc' asFilename filesMatching:'[a-z]*' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1665 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1666 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1667 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1668 |
"Modified: 29.2.1996 / 20:30:31 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1669 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1670 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1671 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1672 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1673 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1674 |
"return my baseName as a string. |
2012 | 1675 |
- thats the file/directory name without leading parent-dirs. |
1676 |
See also: #pathName, #directoryName and #directoryPathName" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1677 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1678 |
^ OperatingSystem baseNameOf:nameString "/ (self pathName) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1679 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1680 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1681 |
'/foo/bar' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1682 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1683 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1684 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1685 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1686 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1687 |
'../../libbasic/Object.st' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1688 |
" |
2012 | 1689 |
|
1690 |
"Modified: 21.12.1996 / 15:22:16 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1691 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1692 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1693 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1694 |
"return the directory name part of the file/directory as a new filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1695 |
- thats a filename for the directory where the file/dir represented by |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1696 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1697 |
(this is almost equivalent to #directoryName or #head, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1698 |
a Filename instance instead of a string )." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1699 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1700 |
^ self directoryName asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1701 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1702 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1703 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1704 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1705 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1706 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1707 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1708 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1709 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1710 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1711 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1712 |
"Modified: 29.2.1996 / 20:50:14 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1713 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1714 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1715 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1716 |
"return the directory name part of the file/directory as a string. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1717 |
- thats the name of the directory where the file/dir represented by |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1718 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1719 |
(this is almost equivalent to #directory, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1720 |
a string instead of a Filename instance). |
2012 | 1721 |
See also: #pathName, #directoryPathName and #baseName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1722 |
Compatibility note: use #head for ST-80 compatibility." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1723 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1724 |
^ OperatingSystem directoryNameOf:nameString "/ (self pathName) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1725 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1726 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1727 |
'/foo/bar/' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1728 |
'/foo/bar/' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1729 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1730 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1731 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1732 |
'bitmaps' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1733 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1734 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1735 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1736 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1737 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1738 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1739 |
"Modified: 7.9.1995 / 10:42:03 / claus" |
2012 | 1740 |
"Modified: 21.12.1996 / 15:21:48 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1741 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1742 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1743 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1744 |
"return the full directory pathname part of the file/directory as a string. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1745 |
- thats the full pathname of the directory where the file/dir represented by |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1746 |
the receiver is contained in. |
2012 | 1747 |
See also: #pathName, #directoryName, #directory and #baseName" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1748 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1749 |
^ OperatingSystem directoryNameOf:(self pathName) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1750 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1751 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1752 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1753 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1754 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1755 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1756 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1757 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1758 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1759 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1760 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1761 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1762 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1763 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1764 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1765 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1766 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 1767 |
"Modified: 21.12.1996 / 15:21:57 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1768 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1769 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1770 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1771 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1772 |
This method has both a return value and a side effect on the receiver: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1773 |
it returns a collection of matching filename objects, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1774 |
and leaves changes the receivers filename-string to the longest common |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1775 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1776 |
If none matches, the returned collection is empty and the recevier is unchanged. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1777 |
If there is only one match, the size of the returned collection is exactly 1, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1778 |
containing the fully expanded filename and the receivers name is changed to it." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1779 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1780 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1781 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1782 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1783 |
'mak' asFilename filenameCompletion |
1517 | 1784 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1785 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1786 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1787 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1788 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1789 |
|
1517 | 1790 |
"Modified: 3.7.1996 / 10:53:51 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1791 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1792 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1793 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1794 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1795 |
This method has both a return value and a side effect on the receiver: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1796 |
it returns a collection of matching filename objects, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1797 |
and leaves changes the receivers filename-string to the longest common |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1798 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1799 |
If none matches, the returned collection is empty and the recevier is unchanged. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1800 |
If there is only one match, the size of the returned collection is exactly 1, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1801 |
containing the fully expanded filename and the receivers name is changed to it." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1802 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1803 |
|dir baseName matching matchLen try allMatching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1804 |
sepString parentString prefix nMatch| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1805 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1806 |
sepString := self class separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1807 |
(nameString endsWith:sepString) ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1808 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1809 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1810 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1811 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1812 |
baseName := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1813 |
baseName ~= nameString ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1814 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1815 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1816 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1817 |
self isAbsolute ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1818 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1819 |
] ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1820 |
aDirectory isNil ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1821 |
dir := self directory |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1822 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1823 |
dir := (aDirectory construct:nameString) directory |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1824 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1825 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1826 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1827 |
matching := OrderedCollection new. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1828 |
dir directoryContents do:[:fileName | |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1829 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1830 |
(fileName startsWith:baseName) ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1831 |
matching add:fileName |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1832 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1833 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1834 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1835 |
(nMatch := matching size) > 1 ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1836 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1837 |
find the longest common prefix |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1838 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1839 |
matchLen := baseName size. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1840 |
matchLen > matching first size ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1841 |
try := baseName. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1842 |
allMatching := false |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1843 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1844 |
try := matching first copyTo:matchLen. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1845 |
allMatching := true. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1846 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1847 |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1848 |
[allMatching] whileTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1849 |
matching do:[:aName | |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1850 |
(aName startsWith:try) ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1851 |
allMatching := false |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1852 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1853 |
]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1854 |
allMatching ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1855 |
matchLen < matching first size ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1856 |
matchLen := matchLen + 1. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1857 |
try := matching first copyTo:matchLen. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1858 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1859 |
allMatching := false |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1860 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1861 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1862 |
try := matching first copyTo:matchLen - 1. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1863 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1864 |
]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1865 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1866 |
and set my name to the last full match |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1867 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1868 |
nameString := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1869 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1870 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1871 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1872 |
if I had a directory-prefix, change names in collection ... |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1873 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1874 |
prefix notNil ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1875 |
prefix = '/' ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1876 |
"/ avoid introducing double slashes |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1877 |
prefix := '' |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1878 |
]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1879 |
matching := matching collect:[:n | prefix , '/' , n]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1880 |
nMatch == 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1881 |
nameString := matching first |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1882 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1883 |
nMatch > 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1884 |
nameString := prefix , '/' , nameString |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1885 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1886 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1887 |
] ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1888 |
nMatch == 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1889 |
nameString := matching first |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1890 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1891 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1892 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1893 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1894 |
return the match-set, so caller can decide what to do |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1895 |
(i.e. show the matches, output a warning etc ...) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1896 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1897 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1898 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1899 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1900 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1901 |
'../' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1902 |
'/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1903 |
'/usr/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1904 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1905 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1906 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1907 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1908 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1909 |
'../../libpr' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1910 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1911 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1912 |
"Modified: 29.2.1996 / 20:28:45 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1913 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1914 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1915 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1916 |
"return the directory name as a string. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1917 |
An alias for directoryName, for ST-80 compatiblity. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1918 |
(this is almost equivalent to #directory, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1919 |
a string instead of a Filename instance)" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1920 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1921 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1922 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1923 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1924 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1925 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1926 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1927 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1928 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1929 |
"Modified: 29.2.1996 / 20:21:25 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1930 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1931 |
|
615 | 1932 |
name |
1933 |
"return the name of the file represented by the receiver as a string. |
|
883 | 1934 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 1935 |
See also: pathName" |
174 | 1936 |
|
615 | 1937 |
self isAbsolute ifTrue:[^ self pathName]. |
1938 |
^ nameString |
|
174 | 1939 |
|
1940 |
" |
|
615 | 1941 |
'/foo/bar' asFilename name |
1942 |
'/foo/bar' asFilename pathName |
|
1943 |
'.' asFilename name |
|
1944 |
'.' asFilename pathName |
|
1945 |
'../..' asFilename name |
|
883 | 1946 |
'../..' asFilename pathName |
615 | 1947 |
'bitmaps' asFilename name |
1948 |
'bitmaps' asFilename pathName |
|
1949 |
'/tmp/../usr' asFilename name |
|
883 | 1950 |
'/tmp/../usr' asFilename pathName |
1951 |
'source/..' asFilename name |
|
1952 |
'source/..' asFilename pathName |
|
1953 |
'/tmp/..' asFilename name |
|
1954 |
'/tmp/..' asFilename pathName |
|
92 | 1955 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1956 |
|
883 | 1957 |
"Modified: 18.1.1996 / 21:36:27 / cg" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1958 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1959 |
|
615 | 1960 |
pathName |
1961 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 1962 |
as a string. This will not include ..'s. |
1963 |
If the path represented by the receiver does NOT represent a valid path, |
|
1964 |
no compression will be done (for now; this may change). |
|
1965 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1966 |
|
1317 | 1967 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1968 |
|
1317 | 1969 |
"/ sep := self class separator. |
1970 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
1971 |
"/ parentName := self class parentDirectoryName. |
|
1972 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
1973 |
"/ ^ nameString |
|
1974 |
"/ ] |
|
1975 |
"/ ]. |
|
1976 |
p := OperatingSystem pathNameOf:nameString. |
|
1977 |
^ p |
|
2 | 1978 |
|
92 | 1979 |
" |
1317 | 1980 |
'/foo/bar' asFilename pathName |
1981 |
'.' asFilename pathName |
|
1982 |
'../..' asFilename pathName |
|
1983 |
'../..' asFilename name |
|
1984 |
'/tmp/../usr' asFilename pathName |
|
1985 |
'/././usr' asFilename pathName |
|
92 | 1986 |
" |
159 | 1987 |
|
1317 | 1988 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 1989 |
! |
1990 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1991 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1992 |
"return the full pathname of the physical file represented by the receiver, |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1993 |
If the receiver represents a symbolic link, thats the fileName of the |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1994 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1995 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1996 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1997 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1998 |
|t target path| |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
1999 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2000 |
self isSymbolicLink ifFalse:[ |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2001 |
self exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2002 |
^ self pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2003 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2004 |
t := self. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2005 |
[t isSymbolicLink] whileTrue:[ |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2006 |
path := t linkInfo path. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2007 |
path isNil ifTrue:[ |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2008 |
"/ cannot happen |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2009 |
^ nil |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2010 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2011 |
target := t directoryName asFilename construct:path. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2012 |
target exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2013 |
t := target asFilename |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2014 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2015 |
t exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2016 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2017 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2018 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2019 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2020 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2021 |
'../..' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2022 |
'include/abbrev.stc' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2023 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2024 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2025 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2026 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2027 |
|
615 | 2028 |
suffix |
2029 |
"return my suffix. |
|
2030 |
The suffix is the namepart after the final period character, |
|
2031 |
or the empty string, if the name does not contain a period." |
|
2032 |
||
2033 |
^ self prefixAndSuffix at:2 |
|
174 | 2034 |
|
615 | 2035 |
" |
2036 |
'abc.st' asFilename suffix |
|
2037 |
'abc' asFilename suffix |
|
2038 |
'a.b.c' asFilename suffix |
|
2039 |
" |
|
174 | 2040 |
|
615 | 2041 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
174 | 2042 |
! |
2043 |
||
615 | 2044 |
tail |
2045 |
"the files name without directory prefix as a string. |
|
2046 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 2047 |
|
615 | 2048 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2049 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2050 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2051 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2052 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2053 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2054 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2055 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2056 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2057 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2058 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2059 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2060 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2061 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2062 |
"return an array consisting of my prefix and suffix. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2063 |
The suffix is the namepart after the final period character, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2064 |
the prefix everything before, except for the period. |
1517 | 2065 |
The directory name part is stripped off (i.e. the returned prefix |
2066 |
will consist of the files basename only.) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2067 |
(on some systems, the suffix-character may be different from a period). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2068 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
1517 | 2069 |
See also: #withoutSuffix and #withSuffix |
2070 |
Notice: |
|
2071 |
there is currently no known system which uses other than |
|
2072 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2073 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2074 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2075 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2076 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2077 |
idx := nm lastIndexOf:(self class suffixSeparator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2078 |
idx == 0 ifTrue:[ |
1517 | 2079 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2080 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2081 |
^ Array |
1517 | 2082 |
with:(nm copyTo:idx-1) |
2083 |
with:(nm copyFrom:idx+1) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2084 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2085 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2086 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2087 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2088 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 2089 |
'/foo/bar.c/baz.c' asFilename prefixAndSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2090 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2091 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2092 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 2093 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2094 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2095 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2096 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 2097 |
"Modified: 3.7.1996 / 10:53:10 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2098 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2099 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2100 |
withSuffix:aSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2101 |
"return a new filename for the receivers name with a suffix. |
1993 | 2102 |
If the name already has a suffix, the new suffix replacaes it; |
2103 |
otherwise, the new suffix is simply appended to the name." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2104 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2105 |
^ self class named: |
1517 | 2106 |
(self withoutSuffix name |
2107 |
, self class suffixSeparator asString |
|
2108 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2109 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2110 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2111 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2112 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2113 |
'a.b.c' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2114 |
'/foo/bar/baz.st' asFilename withSuffix:'c' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2115 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 2116 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 2117 |
'/foo/bar.c/baz' asFilename withSuffix:'st' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2118 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2119 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2120 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1993 | 2121 |
"Modified: 11.12.1996 / 16:01:02 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2122 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2123 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2124 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2125 |
"return a new filename for the receivers name without the suffix. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2126 |
If the name has no suffix, the receiver is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2127 |
|
1516 | 2128 |
|lastComponentsIndex idx| |
2129 |
||
2130 |
lastComponentsIndex := nameString lastIndexOf:(self class separator). |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2131 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2132 |
idx := nameString lastIndexOf:(self class suffixSeparator). |
1516 | 2133 |
(idx == 0 or:[idx <= lastComponentsIndex]) ifTrue:[^ self]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2134 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2135 |
^ self class named:(nameString copyTo:(idx - 1)) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2136 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2137 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2138 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2139 |
'abc' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2140 |
'a.b.c' asFilename withoutSuffix |
1516 | 2141 |
'/foo/bar/baz.c' asFilename withoutSuffix |
2142 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
|
2143 |
'/foo/bar/baz/foo.c/bar.c' asFilename withoutSuffix |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2144 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2145 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2146 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1516 | 2147 |
"Modified: 3.7.1996 / 10:49:58 / cg" |
174 | 2148 |
! ! |
2149 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2150 |
!Filename class methodsFor:'documentation'! |
630 | 2151 |
|
2152 |
version |
|
2175 | 2153 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.79 1997-01-16 00:19:44 cg Exp $' |
630 | 2154 |
! ! |