author | Stefan Vogel <sv@exept.de> |
Thu, 18 Sep 1997 19:28:12 +0200 | |
changeset 2944 | e1f1111afa12 |
parent 2939 | b7cebf237308 |
child 2946 | c61e7226a7eb |
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' |
2906 | 15 |
classVariableNames:'NextTempFilenameIndex ConcreteClass' |
844 | 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 |
||
2911 | 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 |
||
2911 | 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. |
|
2911 | 64 |
Especially the path-construction methods (i.e. #construct:) are highly |
1318 | 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:] |
2911 | 69 |
Claus Gittinger |
276 | 70 |
|
1286 | 71 |
[see also:] |
2911 | 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 |
||
2911 | 83 |
|f| |
84 |
||
85 |
f := 'foobar' asFilename. |
|
86 |
^ f exists |
|
360 | 87 |
|
88 |
||
89 |
is it a directory ?: |
|
90 |
||
2911 | 91 |
|f| |
92 |
||
93 |
f := '/tmp' asFilename. |
|
94 |
^ f isDirectory. |
|
360 | 95 |
|
96 |
||
97 |
get the working directory: |
|
98 |
||
2911 | 99 |
^ Filename defaultDirectory |
360 | 100 |
|
101 |
||
102 |
get a files full pathname |
|
103 |
(caring for relative names or symbolic links): |
|
104 |
||
2911 | 105 |
|f| |
106 |
||
107 |
f := '..' asFilename. |
|
108 |
^ f pathName |
|
360 | 109 |
|
110 |
||
111 |
get a directories directory: |
|
112 |
||
2911 | 113 |
|f| |
114 |
||
115 |
f := Filename defaultDirectory. |
|
116 |
^ f directory |
|
360 | 117 |
|
118 |
||
119 |
get a files directory: |
|
120 |
||
2911 | 121 |
|f| |
122 |
||
123 |
f := './smalltalk' asFilename. |
|
124 |
^ f directory |
|
360 | 125 |
|
126 |
||
127 |
getting access & modification times: |
|
128 |
||
129 |
||
2911 | 130 |
|f| |
131 |
||
132 |
f := '/tmp' asFilename. |
|
133 |
^ f dates |
|
360 | 134 |
|
135 |
access time only: |
|
136 |
||
2911 | 137 |
|f| |
138 |
||
139 |
f := '/tmp' asFilename. |
|
140 |
^ f dates at:#accessed |
|
360 | 141 |
|
142 |
||
143 |
getting all information on a file/directory: |
|
144 |
||
145 |
||
2911 | 146 |
|f| |
147 |
||
148 |
f := '/tmp' asFilename. |
|
149 |
^ f info |
|
360 | 150 |
|
151 |
||
152 |
getting a temporary file (unique name): |
|
153 |
||
2911 | 154 |
|f| |
155 |
||
156 |
f := Filename newTemporary. |
|
157 |
^ f |
|
360 | 158 |
|
159 |
||
160 |
creating, writing, reading and removing a temporary file: |
|
2911 | 161 |
[exBegin] |
162 |
|f writeStream readStream| |
|
163 |
||
164 |
f := Filename newTemporary. |
|
165 |
writeStream := f writeStream. |
|
166 |
writeStream nextPutAll:'hello world'. |
|
167 |
writeStream cr. |
|
168 |
writeStream close. |
|
169 |
||
170 |
'contents (as seen by unix''s cat command:' printNL. |
|
171 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
172 |
||
173 |
readStream := f readStream. |
|
174 |
Transcript showCR:'contents as seen by smalltalk:'. |
|
175 |
Transcript showCR:(readStream upToEnd). |
|
176 |
readStream close. |
|
177 |
||
178 |
f delete. |
|
179 |
[exEnd] |
|
360 | 180 |
|
181 |
||
182 |
getting a directories contents: |
|
2911 | 183 |
[exBegin] |
184 |
|f files| |
|
185 |
||
186 |
f := Filename currentDirectory. |
|
187 |
files := f directoryContents. |
|
188 |
Transcript showCR:'the files are:'. |
|
189 |
Transcript showCR:(files printString). |
|
190 |
[exEnd] |
|
360 | 191 |
|
192 |
||
193 |
editing a file: |
|
2911 | 194 |
[exBegin] |
195 |
|f| |
|
196 |
||
197 |
f := Filename newTemporary. |
|
198 |
(f writeStream) nextPutAll:'hello world'; close. |
|
199 |
||
200 |
f edit |
|
201 |
[exEnd] |
|
360 | 202 |
" |
88 | 203 |
! ! |
1 | 204 |
|
2906 | 205 |
!Filename class methodsFor:'initialization'! |
206 |
||
207 |
initialize |
|
208 |
"initialize for the OS we are running on" |
|
209 |
||
210 |
self initializeConcreteClass |
|
211 |
||
212 |
" |
|
213 |
self initialize |
|
214 |
" |
|
215 |
||
216 |
"Created: 7.9.1997 / 23:32:55 / cg" |
|
217 |
! |
|
218 |
||
219 |
initializeConcreteClass |
|
220 |
"initialize for the OS we are running on" |
|
221 |
||
222 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
223 |
ConcreteClass := PCFilename |
|
224 |
] ifFalse:[ |
|
225 |
OperatingSystem isVMSlike ifTrue:[ |
|
226 |
ConcreteClass := OpenVMSFilename |
|
227 |
] ifFalse:[ |
|
228 |
OperatingSystem isUNIXlike ifTrue:[ |
|
229 |
ConcreteClass := UnixFilename |
|
230 |
] ifFalse:[ |
|
231 |
ConcreteClass := nil |
|
232 |
] |
|
233 |
] |
|
234 |
] |
|
235 |
||
236 |
" |
|
237 |
self initialize |
|
238 |
" |
|
239 |
||
240 |
"Modified: 7.9.1997 / 23:32:37 / cg" |
|
241 |
! |
|
242 |
||
243 |
reinitialize |
|
244 |
"initialize for the OS we are running on" |
|
245 |
||
246 |
self initializeConcreteClass |
|
247 |
||
248 |
" |
|
249 |
self initialize |
|
250 |
" |
|
251 |
||
252 |
"Created: 7.9.1997 / 23:33:02 / cg" |
|
253 |
! ! |
|
254 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
255 |
!Filename class methodsFor:'instance creation'! |
1 | 256 |
|
276 | 257 |
currentDirectory |
258 |
"return a filename for the current directory" |
|
259 |
||
2906 | 260 |
(self ~~ ConcreteClass) ifTrue:[ |
261 |
^ ConcreteClass currentDirectory |
|
262 |
]. |
|
263 |
||
264 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
265 |
||
2922 | 266 |
^ self named:'.' |
267 |
"/ ^ self named:('.' asFilename pathName) |
|
276 | 268 |
|
269 |
" |
|
270 |
Filename currentDirectory |
|
271 |
" |
|
2550 | 272 |
|
2906 | 273 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
276 | 274 |
! |
275 |
||
328 | 276 |
defaultDirectory |
277 |
"ST80 compatibility: same as currentDirectory" |
|
278 |
||
279 |
^ self currentDirectory |
|
280 |
||
281 |
" |
|
282 |
Filename defaultDirectory |
|
283 |
" |
|
284 |
! |
|
285 |
||
542 | 286 |
defaultDirectoryName |
287 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
|
288 |
||
289 |
^ self defaultDirectory name |
|
290 |
||
291 |
" |
|
292 |
Filename defaultDirectoryName |
|
293 |
" |
|
294 |
! |
|
295 |
||
2906 | 296 |
defaultTempDirectoryName |
297 |
"return the default temp directory as a filename. |
|
298 |
This is used, if no special preferences were defined in |
|
299 |
any of the TEMP-environment variables (see tempDirectory)." |
|
300 |
||
301 |
(self ~~ ConcreteClass) ifTrue:[ |
|
302 |
^ ConcreteClass defaultTempDirectoryName |
|
303 |
]. |
|
304 |
||
305 |
^ '/tmp' |
|
306 |
||
307 |
" |
|
308 |
Filename defaultTempDirectoryName |
|
309 |
" |
|
310 |
||
311 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
312 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
313 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
314 |
! |
|
315 |
||
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
316 |
findDefaultDirectory |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
317 |
"same as #defaultDirectory for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
318 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
319 |
^ self defaultDirectory |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
320 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
321 |
"Created: 20.6.1997 / 17:00:29 / cg" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
322 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
323 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
324 |
fromComponents:aCollectionOfDirectoryNames |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
325 |
"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
|
326 |
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
|
327 |
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
|
328 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
329 |
|sep s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
330 |
|
2906 | 331 |
(self ~~ ConcreteClass) ifTrue:[ |
332 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
|
333 |
]. |
|
334 |
||
335 |
"/ fallBack - works on Unix & MSDOS |
|
336 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
337 |
sep := self separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
338 |
s := ''. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
339 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
2906 | 340 |
index == 1 ifTrue:[ |
341 |
(component ~= sep |
|
342 |
or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ |
|
343 |
s := s , component |
|
344 |
] |
|
345 |
] ifFalse:[ |
|
346 |
s := s , sep , component |
|
347 |
]. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
348 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
349 |
^ self named:s |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
350 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
351 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
352 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
353 |
Filename fromComponents:#('foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
354 |
Filename fromComponents:#('/') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
355 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
356 |
Filename fromComponents: |
2906 | 357 |
(Filename components:('.' asFilename pathName)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
358 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
359 |
Filename fromComponents: |
2906 | 360 |
(Filename components:('.' asFilename name)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
361 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
362 |
|
2906 | 363 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
364 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
365 |
|
615 | 366 |
fromUser |
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
367 |
"show a box to enter a filename. |
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
368 |
Return a filename instance or nil (if cancel was pressed)." |
615 | 369 |
|
370 |
|name| |
|
371 |
||
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
372 |
name := Dialog requestFileName:'filename:' ifFail:nil. |
615 | 373 |
name notNil ifTrue:[^ self named:name]. |
374 |
^ nil |
|
375 |
||
376 |
" |
|
377 |
Filename fromUser |
|
378 |
" |
|
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
379 |
|
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
380 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
615 | 381 |
! |
382 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
383 |
homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
384 |
"return your homeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
385 |
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
|
386 |
(which is the currentDirectory) is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
387 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
388 |
|s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
389 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
390 |
s := OperatingSystem getHomeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
391 |
s isNil ifTrue:[ |
2906 | 392 |
^ self defaultDirectory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
393 |
]. |
2906 | 394 |
^ self named:s |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
395 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
396 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
397 |
Filename homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
398 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
399 |
|
2906 | 400 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
401 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
402 |
|
615 | 403 |
named:aString |
404 |
"return a filename for a directory named aString. |
|
405 |
This is the same as 'aString asFilename'." |
|
406 |
||
2908 | 407 |
|cls| |
408 |
||
409 |
cls := self. |
|
410 |
cls == Filename ifTrue:[ |
|
411 |
cls := self concreteClass |
|
412 |
]. |
|
413 |
^ (cls basicNew) setName:aString |
|
615 | 414 |
|
415 |
" |
|
416 |
Filename named:'/tmp/fooBar' |
|
417 |
" |
|
2906 | 418 |
|
419 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
615 | 420 |
! |
421 |
||
276 | 422 |
newTemporary |
325 | 423 |
"return a new unique filename - use this for temporary files. |
424 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
425 |
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
|
426 |
call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
427 |
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
|
428 |
its value defines the temp directory." |
276 | 429 |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
430 |
^ self newTemporaryIn:self tempDirectory pathName |
276 | 431 |
|
432 |
" |
|
422 | 433 |
Filename newTemporary |
1080 | 434 |
Filename newTemporary |
276 | 435 |
" |
422 | 436 |
|
437 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
438 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
439 |
! |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
440 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
441 |
newTemporaryIn:aDirectoryPrefix |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
442 |
"return a new unique filename - use this for temporary files. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
443 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
444 |
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
|
445 |
with every call to this method. |
2906 | 446 |
Notice: only a unique filename object is created and returned - no physical |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
447 |
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
|
448 |
whatever to it in order to really create something). |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
449 |
See also: #newTemporary which looks for a good temp directory." |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
450 |
|
2906 | 451 |
|pid nameString| |
452 |
||
453 |
(self ~~ ConcreteClass) ifTrue:[ |
|
454 |
^ ConcreteClass newTemporaryIn:aDirectoryPrefix |
|
455 |
]. |
|
456 |
||
457 |
"/ although the above allows things to be redefined in concrete classes, |
|
458 |
"/ the following should work on all systems ... |
|
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
459 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
460 |
NextTempFilenameIndex isNil ifTrue:[ |
2906 | 461 |
NextTempFilenameIndex := 1. |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
462 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
463 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
464 |
pid := OperatingSystem getProcessId printString. |
2906 | 465 |
nameString := (self tempFileNameTemplate) bindWith:pid with:(NextTempFilenameIndex printString). |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
466 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
467 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
468 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
2906 | 469 |
^ aDirectoryPrefix asFilename construct:nameString |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
470 |
]. |
2906 | 471 |
^ self named:nameString |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
472 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
473 |
"temp files in '/tmp': |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
474 |
|
1080 | 475 |
Filename newTemporary |
476 |
" |
|
477 |
||
478 |
"temp files somewhere |
|
479 |
(not recommended - use above since it can be controlled via shell variables): |
|
480 |
||
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
481 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
482 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
483 |
Filename newTemporaryIn:'/usr/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
484 |
Filename newTemporaryIn:'/' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
485 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
486 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
487 |
"a local temp file: |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
488 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
489 |
Filename newTemporaryIn:'' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
490 |
Filename newTemporaryIn:nil |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
491 |
Filename newTemporaryIn:'.' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
492 |
Filename newTemporaryIn:('source' asFilename) |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
493 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
494 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
495 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
2906 | 496 |
"Modified: 8.9.1997 / 00:28:33 / cg" |
1080 | 497 |
! |
498 |
||
2922 | 499 |
rootDirectory |
500 |
"return a filename for the root directory" |
|
501 |
||
502 |
(self ~~ ConcreteClass) ifTrue:[ |
|
503 |
^ ConcreteClass rootDirectory |
|
504 |
]. |
|
505 |
||
506 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
507 |
||
508 |
^ self named:(self separator asString) |
|
509 |
||
510 |
" |
|
511 |
Filename rootDirectory |
|
512 |
" |
|
513 |
||
514 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
515 |
! |
|
516 |
||
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
517 |
tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
518 |
"return the temp directory as a filename. |
1968 | 519 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
520 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
521 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
522 |
|
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
523 |
Notice: do not hardcode '/tmp' into your programs - things may be |
2906 | 524 |
different on other OS's. Also, the user may want to set the |
525 |
TMPDIR environment variable to have her temp files somewhere else. |
|
526 |
(especially on SUNOS, the root partition is ALWAYS too small ..." |
|
1080 | 527 |
|
528 |
|tempDir| |
|
529 |
||
1969 | 530 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
2906 | 531 |
tempDir isNil ifTrue:[ |
532 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
533 |
]. |
|
1968 | 534 |
]. |
1080 | 535 |
tempDir isNil ifTrue:[ |
2906 | 536 |
tempDir := self defaultTempDirectoryName |
1080 | 537 |
]. |
538 |
^ self named:tempDir |
|
539 |
||
540 |
" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
541 |
Filename tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
542 |
Filename tempDirectory pathName |
1080 | 543 |
" |
544 |
||
545 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
546 |
"Created: 7.3.1996 / 14:51:18 / cg" |
2906 | 547 |
"Modified: 8.9.1997 / 00:08:11 / cg" |
1 | 548 |
! ! |
549 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
550 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
551 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
552 |
concreteClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
553 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
554 |
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
|
555 |
OperatingSystems; concreteClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
556 |
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
|
557 |
|
2906 | 558 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
559 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
560 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 561 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
562 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
563 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
564 |
defaultClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
565 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
566 |
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
|
567 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
568 |
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
|
569 |
|
2906 | 570 |
^ ConcreteClass |
571 |
||
572 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
573 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
574 |
|
2922 | 575 |
!Filename class methodsFor:'misc'! |
576 |
||
577 |
canonicalize:aPathString |
|
578 |
^ aPathString |
|
579 |
||
580 |
"Created: 13.9.1997 / 10:50:01 / cg" |
|
581 |
! ! |
|
582 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
583 |
!Filename class methodsFor:'queries'! |
2 | 584 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
585 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
586 |
"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
|
587 |
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
|
588 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
589 |
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
|
590 |
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
|
591 |
|
2503 | 592 |
|sep components| |
593 |
||
2906 | 594 |
(self ~~ ConcreteClass) ifTrue:[ |
595 |
^ ConcreteClass components:aString |
|
596 |
]. |
|
597 |
||
598 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
599 |
||
2503 | 600 |
sep := self separator. |
601 |
components := aString asCollectionOfSubstringsSeparatedBy:sep. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
602 |
components first isEmpty ifTrue:[ |
2906 | 603 |
components at:1 put:(sep asString) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
604 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
605 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
606 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
607 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
608 |
Filename components:'/foo/bar/baz' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
609 |
Filename components:'foo/bar/baz' |
2503 | 610 |
Filename components:'foo/bar' |
611 |
Filename components:'foo' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
612 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
613 |
|
2906 | 614 |
"Modified: 8.9.1997 / 00:30:57 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
615 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
616 |
|
1523 | 617 |
errorReporter |
618 |
"who knows the signals to report errors?" |
|
619 |
||
620 |
^ FileStream |
|
621 |
||
622 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
623 |
! |
|
624 |
||
440 | 625 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
626 |
"perform filename completion on aString in some directory; |
|
627 |
return the longest matching filename prefix as a string. |
|
1318 | 628 |
The boolean directoriesOnly and filesOnly control respectively, |
629 |
if only directories or only regular files are to be considered for completion. |
|
630 |
If multiple files match, the exception block aBlock is evaluated with a |
|
631 |
filename representing the directory (where the match was done) as argument. |
|
440 | 632 |
(this may be different from the inDirectory argument, if aString is absolute |
633 |
or starts with ../)" |
|
634 |
||
635 |
|s f matchSet nMatch name words dir| |
|
636 |
||
2906 | 637 |
(self ~~ ConcreteClass) ifTrue:[ |
638 |
^ ConcreteClass |
|
639 |
filenameCompletionFor:aString |
|
640 |
directory:inDirectory |
|
641 |
directoriesOnly:directoriesOnly |
|
642 |
filesOnly:filesOnly |
|
643 |
ifMultiple:aBlock |
|
644 |
]. |
|
645 |
||
646 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
647 |
||
440 | 648 |
s := aString. |
649 |
" |
|
650 |
find the last word ... |
|
651 |
" |
|
652 |
words := s asCollectionOfWords. |
|
653 |
words size == 0 ifTrue:[ |
|
2906 | 654 |
aBlock value:'.' asFilename. |
655 |
^ '' |
|
440 | 656 |
]. |
657 |
||
658 |
f := words last asFilename. |
|
659 |
||
660 |
matchSet := f filenameCompletionIn:inDirectory. |
|
661 |
||
662 |
dir := f directory. |
|
663 |
||
664 |
directoriesOnly ifTrue:[ |
|
2906 | 665 |
matchSet := matchSet select:[:aFilename | |
666 |
(dir construct:aFilename) isDirectory |
|
667 |
]. |
|
440 | 668 |
] ifFalse:[ |
2906 | 669 |
filesOnly ifTrue:[ |
670 |
matchSet := matchSet select:[:aFilename | |
|
671 |
(dir construct:aFilename) isDirectory not |
|
672 |
]. |
|
673 |
] |
|
440 | 674 |
]. |
675 |
||
676 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
2906 | 677 |
" |
678 |
more than one possible completion - |
|
679 |
" |
|
680 |
aBlock value:f |
|
440 | 681 |
]. |
682 |
" |
|
683 |
even with more than one possible completion, |
|
684 |
f's name is now the common prefix |
|
685 |
" |
|
686 |
name := f asString. |
|
687 |
nMatch == 1 ifTrue:[ |
|
2906 | 688 |
" |
689 |
exactly one possible completion - |
|
690 |
" |
|
691 |
f := dir construct:matchSet first. |
|
692 |
||
693 |
directoriesOnly ifFalse:[ |
|
694 |
f isDirectory ifTrue:[ |
|
695 |
(name endsWith:(Filename separator)) ifFalse:[ |
|
696 |
name := name , '/' |
|
697 |
]. |
|
698 |
]. |
|
699 |
] |
|
440 | 700 |
]. |
701 |
||
702 |
" |
|
703 |
construct new contents, by taking |
|
704 |
last words completion |
|
705 |
" |
|
706 |
s := ''. |
|
707 |
1 to:(words size - 1) do:[:idx | |
|
2906 | 708 |
s := s , (words at:idx) , ' ' |
440 | 709 |
]. |
710 |
s := s , name. |
|
711 |
||
712 |
"/ special: if there was no change, and the string represented |
|
713 |
"/ is a directories name, add a directory separator |
|
714 |
s = aString ifTrue:[ |
|
2906 | 715 |
(s endsWith:Filename separator) ifFalse:[ |
716 |
s asFilename isDirectory ifTrue:[ |
|
717 |
^ s , Filename separator asString |
|
718 |
] |
|
719 |
] |
|
440 | 720 |
]. |
721 |
||
722 |
^ s |
|
1318 | 723 |
|
2906 | 724 |
"Modified: 8.9.1997 / 00:31:51 / cg" |
615 | 725 |
! |
726 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
727 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
728 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
729 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
730 |
If aPattern contains a directory path, files are tried there; |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
731 |
otherwise, files from the currentDirectory are tried. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
732 |
The returned strings are the expanded names, in the same form |
2550 | 733 |
as given in pattern. |
734 |
The pattern should be a simple pattern." |
|
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
735 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
736 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
737 |
|
2906 | 738 |
(self ~~ ConcreteClass) ifTrue:[ |
739 |
^ ConcreteClass filesMatching:aPattern |
|
740 |
]. |
|
741 |
||
742 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
743 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
744 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
745 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
746 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
747 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
748 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
749 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
750 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
751 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
752 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
753 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
754 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
755 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
756 |
|
2906 | 757 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 758 |
! |
759 |
||
2903 | 760 |
isBadCharacter:aCharacter |
761 |
"return true, if aCharacter is unallowed in a filename." |
|
762 |
||
763 |
|ascii| |
|
764 |
||
2906 | 765 |
(self ~~ ConcreteClass) ifTrue:[ |
766 |
^ ConcreteClass isBadCharacter:aCharacter |
|
767 |
]. |
|
768 |
||
2903 | 769 |
ascii := aCharacter asciiValue. |
770 |
ascii < 32 ifTrue:[ |
|
2906 | 771 |
^ true "/ a control character |
2903 | 772 |
]. |
773 |
ascii == 16rFF ifTrue:[ |
|
2906 | 774 |
^ true "/ delete character |
2903 | 775 |
]. |
776 |
^ false |
|
2906 | 777 |
|
778 |
"Modified: 8.9.1997 / 00:32:59 / cg" |
|
2903 | 779 |
! |
780 |
||
781 |
isCaseSensitive |
|
782 |
"return true, if filenames are case sensitive. |
|
783 |
We ask the OS about this, to be independent here." |
|
784 |
||
2906 | 785 |
(self ~~ ConcreteClass) ifTrue:[ |
786 |
^ ConcreteClass isCaseSensitive |
|
787 |
]. |
|
788 |
||
2903 | 789 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 790 |
|
791 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 792 |
! |
793 |
||
615 | 794 |
localNameStringFrom:aString |
795 |
"ST-80 compatibility. |
|
796 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 797 |
GUESS: |
798 |
does it strip off any volume characters and make a path relative ?" |
|
799 |
||
800 |
|sep| |
|
615 | 801 |
|
2906 | 802 |
(self ~~ ConcreteClass) ifTrue:[ |
803 |
^ ConcreteClass localNameStringFrom:aString |
|
804 |
]. |
|
805 |
||
2922 | 806 |
sep := self separator asString. |
807 |
(aString startsWith:sep) ifTrue:[ |
|
808 |
^ aString copyFrom:sep size + 1 |
|
615 | 809 |
]. |
810 |
^ aString |
|
811 |
||
812 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 813 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 814 |
! |
815 |
||
2908 | 816 |
maxComponentLength |
817 |
"return the maximum number of characters a filename component may |
|
818 |
be in size. This depends on the OperatingSystem." |
|
819 |
||
820 |
(self ~~ ConcreteClass) ifTrue:[ |
|
821 |
^ ConcreteClass maxComponentLength |
|
822 |
]. |
|
823 |
^ OperatingSystem maxFileNameLength |
|
824 |
! |
|
825 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
826 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
827 |
"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
|
828 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
829 |
|
2908 | 830 |
(self ~~ ConcreteClass) ifTrue:[ |
831 |
^ ConcreteClass maxLength |
|
832 |
]. |
|
833 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
834 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
835 |
"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
|
836 |
"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
|
837 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
838 |
|
615 | 839 |
parentDirectoryName |
840 |
"return the name used for the parent directory. |
|
841 |
This is '..' for unix and dos-like systems. |
|
842 |
(there may be more in the future." |
|
843 |
||
2906 | 844 |
(self ~~ ConcreteClass) ifTrue:[ |
845 |
^ ConcreteClass parentDirectoryName |
|
846 |
]. |
|
847 |
||
848 |
^ OperatingSystem parentDirectoryName |
|
849 |
||
850 |
" |
|
851 |
Filename parentDirectoryName |
|
852 |
" |
|
853 |
||
854 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 855 |
! |
856 |
||
857 |
separator |
|
858 |
"return the file/directory separator. |
|
2906 | 859 |
This is to be redefined in concrete classes; |
860 |
the following default usually leads to a flat view of |
|
861 |
the fileSystem (huh - BS2000 ?)" |
|
862 |
||
863 |
(self ~~ ConcreteClass) ifTrue:[ |
|
864 |
^ ConcreteClass separator |
|
865 |
]. |
|
866 |
^ $_ |
|
615 | 867 |
|
868 |
" |
|
869 |
Filename separator |
|
870 |
" |
|
2906 | 871 |
|
872 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 873 |
! |
874 |
||
875 |
suffixSeparator |
|
876 |
"return the filename suffix separator. |
|
877 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 878 |
(there is currently no known system, where this differs)" |
615 | 879 |
|
880 |
^ $. |
|
881 |
||
882 |
" |
|
883 |
Filename suffixSeparator |
|
884 |
" |
|
885 |
||
886 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 887 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 888 |
! |
889 |
||
2906 | 890 |
tempFileNameTemplate |
891 |
"return a template for temporary files. |
|
892 |
This is expanded with the current processID and a sequenceNumber |
|
893 |
to generate a unique filename." |
|
894 |
||
895 |
(self ~~ ConcreteClass) ifTrue:[ |
|
896 |
^ ConcreteClass tempFileNameTemplate |
|
897 |
]. |
|
898 |
||
899 |
^ 'stxtmp_%1_%2' |
|
900 |
||
901 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
902 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
903 |
! |
|
904 |
||
615 | 905 |
volumes |
906 |
"ST-80 compatibility. |
|
2896 | 907 |
GUESS: does it return the available drives on MSDOS systems ? |
908 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
909 |
||
2906 | 910 |
(self ~~ ConcreteClass) ifTrue:[ |
911 |
^ ConcreteClass volumes |
|
912 |
]. |
|
913 |
||
2896 | 914 |
^ OperatingSystem getDriveList |
615 | 915 |
|
916 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
2906 | 917 |
"Modified: 8.9.1997 / 00:35:19 / cg" |
615 | 918 |
! ! |
919 |
||
920 |
!Filename methodsFor:'comparing'! |
|
921 |
||
922 |
= aFilename |
|
923 |
"return true, if the argument represents the same filename" |
|
924 |
||
925 |
|str| |
|
926 |
||
927 |
self species == aFilename species ifTrue:[ |
|
928 |
str := aFilename asString. |
|
929 |
self class isCaseSensitive ifTrue:[ |
|
930 |
^ nameString = str |
|
931 |
]. |
|
932 |
^ nameString sameAs:str |
|
933 |
]. |
|
934 |
^ false |
|
935 |
! |
|
936 |
||
937 |
hash |
|
938 |
"return an integer useful as a hash-key" |
|
939 |
||
940 |
^ nameString hash |
|
941 |
! ! |
|
942 |
||
943 |
!Filename methodsFor:'converting'! |
|
944 |
||
945 |
asAbsoluteFilename |
|
946 |
"return the receiver converted to a filename with |
|
947 |
an absolute pathname." |
|
948 |
||
949 |
^ self pathName asFilename |
|
950 |
! |
|
951 |
||
952 |
asFilename |
|
1970 | 953 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 954 |
|
955 |
"Thats pretty easy here :-)" |
|
956 |
^ self |
|
1970 | 957 |
|
958 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 959 |
! |
960 |
||
961 |
asString |
|
962 |
"return the receiver converted to a string" |
|
963 |
||
964 |
^ nameString |
|
965 |
! |
|
966 |
||
967 |
makeLegalFilename |
|
1970 | 968 |
"convert the receivers name to be a legal filename. |
969 |
This removes/replaces invalid characters and/or compresses |
|
970 |
the name as required by the OS. |
|
615 | 971 |
The implementation may change in the future to be more |
972 |
OS specific." |
|
973 |
||
974 |
" |
|
975 |
actually, in Unix spaces are allowed - but it makes life |
|
976 |
so hard; therefore, replace them by underscores ... |
|
977 |
" |
|
2922 | 978 |
nameString replaceAll:(Character space) with:$_. |
615 | 979 |
" |
980 |
need more - especially on SYS5.3 type systems, |
|
981 |
we may want to contract the fileName to 14 characters. |
|
982 |
" |
|
983 |
^ self |
|
984 |
||
985 |
" |
|
986 |
'hello world' asFilename makeLegalFilename |
|
987 |
" |
|
1970 | 988 |
|
989 |
"Modified: 12.11.1996 / 12:39:04 / cg" |
|
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
990 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
991 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
992 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
993 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
994 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
995 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
996 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
997 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 998 |
! ! |
999 |
||
542 | 1000 |
!Filename methodsFor:'error handling'! |
1001 |
||
615 | 1002 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1003 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1004 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1005 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1006 |
|
615 | 1007 |
^ OperatingSystem accessDeniedErrorSignal |
542 | 1008 |
raiseRequestWith:filename |
615 | 1009 |
errorString:('access denied: ' , filename asString) |
1010 |
! |
|
1011 |
||
1012 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1013 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1014 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1015 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1016 |
|
615 | 1017 |
^ OperatingSystem accessDeniedErrorSignal |
1018 |
raiseRequestWith:filename |
|
1019 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 1020 |
! |
1021 |
||
1022 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1023 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1024 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1025 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1026 |
|
542 | 1027 |
^ OperatingSystem fileNotFoundErrorSignal |
1028 |
raiseRequestWith:filename |
|
1029 |
errorString:('file not found: ' , filename asString) |
|
1030 |
! |
|
1031 |
||
1032 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1033 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1034 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1035 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1036 |
|
542 | 1037 |
^ OperatingSystem accessDeniedErrorSignal |
1038 |
raiseRequestWith:filename |
|
1039 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 1040 |
! |
1041 |
||
1042 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1043 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1044 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1045 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1046 |
|
615 | 1047 |
^ OperatingSystem errorSignal |
1048 |
raiseRequestWith:filename |
|
1049 |
errorString:string |
|
1050 |
! ! |
|
1051 |
||
1052 |
!Filename methodsFor:'file access'! |
|
1053 |
||
1054 |
appendingWriteStream |
|
1055 |
"return a stream for appending to the file represented by the receiver. |
|
1056 |
If the file does not already exist, it is created." |
|
1057 |
||
2922 | 1058 |
^ FileStream appendingOldFileNamed:(self osNameForFile) |
615 | 1059 |
! |
1060 |
||
1061 |
newReadWriteStream |
|
1062 |
"return a stream for read/write the file represented by the receiver. |
|
1063 |
If the file does not already exist, it is created." |
|
1064 |
||
2922 | 1065 |
^ FileStream newFileNamed:(self osNameForFile) |
615 | 1066 |
! |
1067 |
||
1068 |
readStream |
|
1069 |
"return a stream for reading from the file represented by the receiver. |
|
1070 |
If the file does not already exist, nil is returned." |
|
1071 |
||
2922 | 1072 |
^ FileStream readonlyFileNamed:(self osNameForFile) |
615 | 1073 |
|
1074 |
" |
|
1075 |
'/tmp/foo' asFilename readStream |
|
1076 |
" |
|
1077 |
! |
|
1078 |
||
1079 |
readWriteStream |
|
1080 |
"return a stream for read/write the file represented by the receiver. |
|
1081 |
If the file does not already exist, nil is returned." |
|
1082 |
||
1083 |
^ FileStream oldFileNamed:nameString |
|
1084 |
! |
|
1085 |
||
1086 |
writeStream |
|
1087 |
"return a stream for writing to the file represented by the receiver. |
|
1088 |
If the file does not already exist, it is created." |
|
1089 |
||
1090 |
^ FileStream newFileForWritingNamed:nameString |
|
1091 |
||
1092 |
" |
|
1093 |
'/tmp/foo' asFilename writeStream |
|
1094 |
" |
|
1095 |
! ! |
|
1096 |
||
1097 |
!Filename methodsFor:'file operations'! |
|
1098 |
||
1099 |
addAccessRights:aCollection |
|
1100 |
"add the access rights as specified in aCollection for the file represented |
|
1101 |
by the receiver. The argument must be a collection of symbols, |
|
1102 |
such as #readUser, #writeGroup etc." |
|
1103 |
||
2922 | 1104 |
|access osName| |
1105 |
||
2939 | 1106 |
osName := self osNameForStat. |
2922 | 1107 |
access := OperatingSystem accessModeOf:osName. |
615 | 1108 |
aCollection do:[:accessSymbol | |
1109 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
1110 |
]. |
|
2922 | 1111 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1112 |
^ self accessDeniedError:self |
1113 |
] |
|
1114 |
||
1115 |
" |
|
1116 |
'foo' asFilename writeStream close. |
|
1117 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
1118 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
1119 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
1120 |
" |
|
1121 |
! |
|
1122 |
||
1123 |
copyTo:newName |
|
1124 |
"copy the file - the argument must be convertable to a filename. |
|
671 | 1125 |
Return true if successful, false if not." |
615 | 1126 |
|
1127 |
|inStream outStream buffer bufferSize count newFile| |
|
1128 |
||
1129 |
bufferSize := 8 * 1024. |
|
1130 |
buffer := ByteArray new:bufferSize. |
|
1131 |
inStream := self readStream. |
|
1132 |
inStream isNil ifTrue:[ |
|
1133 |
^ self fileNotFoundError:self |
|
1134 |
]. |
|
1135 |
||
1136 |
outStream := (newFile := newName asFilename) writeStream. |
|
1137 |
outStream isNil ifTrue:[ |
|
1138 |
^ self fileCreationError:newFile |
|
1139 |
]. |
|
1140 |
||
1141 |
[inStream atEnd] whileFalse:[ |
|
1142 |
count := inStream nextBytes:bufferSize into:buffer. |
|
1143 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
|
1144 |
^ self fileCreationError:newFile |
|
1145 |
] |
|
1146 |
]. |
|
1147 |
outStream close. |
|
1148 |
inStream close. |
|
1149 |
||
1150 |
" |
|
1151 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
1152 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
1153 |
" |
|
1154 |
! |
|
1155 |
||
1156 |
delete |
|
1157 |
"remove the file - same as remove, for ST-80 compatibility" |
|
1158 |
||
1159 |
self remove |
|
1160 |
! |
|
1161 |
||
1162 |
makeDirectory |
|
1163 |
"create a directory with the receivers name. |
|
671 | 1164 |
Return true if successful, false if not." |
615 | 1165 |
|
2922 | 1166 |
(OperatingSystem createDirectory:(self osNameForDirectory)) ifFalse:[ |
2629 | 1167 |
(self exists and:[self isDirectory]) ifFalse:[ |
1168 |
^ self fileCreationError:self |
|
1169 |
] |
|
615 | 1170 |
] |
1970 | 1171 |
|
1172 |
"Modified: 12.11.1996 / 12:25:22 / cg" |
|
615 | 1173 |
! |
1174 |
||
844 | 1175 |
makeExecutable |
1176 |
"make the file executable - you must have permission to do so. |
|
1177 |
For directories, execution means: 'allow changing into it'" |
|
1178 |
||
1179 |
^ self addAccessRights:#(executeUser) |
|
1180 |
||
1181 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
1182 |
! |
|
1183 |
||
1184 |
makeExecutableForAll |
|
1185 |
"make the file executable for all - you must have permission to do so. |
|
1186 |
For directories, execution means: 'allow changing into it'" |
|
1187 |
||
1188 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
1189 |
||
1190 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
1191 |
! |
|
1192 |
||
615 | 1193 |
makeReadable |
1194 |
"make the file readable for the owner - you must have permission to do so." |
|
1195 |
||
1196 |
^ self addAccessRights:#(readUser) |
|
1197 |
! |
|
1198 |
||
1199 |
makeReadableForAll |
|
1200 |
"make the file readable for all - you must have permission to do so." |
|
1201 |
||
1202 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
1203 |
! |
|
1204 |
||
1205 |
makeUnwritable |
|
1206 |
"make the file unwritable for all - you must have permission to do so." |
|
1207 |
||
1208 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
1209 |
! |
|
1210 |
||
1211 |
makeWritable |
|
1212 |
"make the file writableable for all - you must have permission to do so." |
|
1213 |
||
1214 |
^ self addAccessRights:#(writeUser) |
|
1215 |
! |
|
1216 |
||
1217 |
makeWritableForAll |
|
1218 |
"make the file writable for all - you must have permission to do so." |
|
1219 |
||
1220 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
1221 |
! |
|
1222 |
||
1223 |
moveTo:newName |
|
1224 |
"copy the file represented by the receiver, then delete it. |
|
1225 |
This is different to renaming in case of cross device moves. |
|
671 | 1226 |
Raise an error if not successful." |
615 | 1227 |
|
1228 |
self copyTo:newName. |
|
1229 |
self remove |
|
1230 |
! |
|
1231 |
||
659 | 1232 |
recursiveMakeDirectory |
1233 |
"create a directory with the receivers name and all required intermediate |
|
1234 |
directories. |
|
671 | 1235 |
Raise an error if not successful." |
659 | 1236 |
|
2922 | 1237 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
671 | 1238 |
^ self fileCreationError:self |
659 | 1239 |
] |
1240 |
||
1241 |
"Created: 27.11.1995 / 23:36:40 / cg" |
|
1242 |
! |
|
1243 |
||
615 | 1244 |
recursiveRemove |
671 | 1245 |
"remove the directory and all of its subfiles/subdirectories. |
1246 |
Raise an error if not successful." |
|
615 | 1247 |
|
1248 |
|ok| |
|
1249 |
||
2922 | 1250 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
615 | 1251 |
ok ifFalse:[ |
1252 |
self removeError:self |
|
1253 |
]. |
|
1254 |
||
1255 |
" |
|
1256 |
'foo' asFilename makeDirectory. |
|
1257 |
'foo/bar' asFilename writeStream close. |
|
1258 |
('foo' asFilename remove) ifFalse:[ |
|
1422 | 1259 |
Transcript showCR:'could not remove foo' |
615 | 1260 |
] |
1261 |
" |
|
1262 |
" |
|
1263 |
'foo' asFilename makeDirectory. |
|
1264 |
'foo/bar' asFilename writeStream close. |
|
1265 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
1422 | 1266 |
Transcript showCR:'could not remove foo' |
615 | 1267 |
] |
1268 |
" |
|
1269 |
||
1270 |
"Created: 14.11.1995 / 11:19:29 / cg" |
|
1271 |
! |
|
1272 |
||
1273 |
remove |
|
845 | 1274 |
"remove the file/directory. |
672 | 1275 |
Raise an error if not successful. |
845 | 1276 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 1277 |
|
1278 |
|ok| |
|
1279 |
||
1280 |
self exists ifFalse:[ ^ self]. |
|
1281 |
self isDirectory ifTrue:[ |
|
2922 | 1282 |
ok := OperatingSystem removeDirectory:(self osNameForFile) |
615 | 1283 |
] ifFalse:[ |
2922 | 1284 |
ok := OperatingSystem removeFile:(self osNameForFile) |
615 | 1285 |
]. |
1286 |
ok ifFalse:[ |
|
883 | 1287 |
self removeError:self |
615 | 1288 |
]. |
1289 |
||
1290 |
" |
|
1291 |
(FileStream newFileNamed:'foo') close. |
|
1292 |
'foo' asFilename remove |
|
1293 |
" |
|
1294 |
||
1295 |
" |
|
1296 |
'foo' asFilename makeDirectory. |
|
1297 |
'foo/bar' asFilename writeStream close. |
|
1298 |
('foo' asFilename remove) ifFalse:[ |
|
1422 | 1299 |
Transcript showCR:'could not remove foo' |
615 | 1300 |
] |
1301 |
" |
|
1302 |
||
845 | 1303 |
"Modified: 10.1.1996 / 18:44:50 / cg" |
615 | 1304 |
! |
1305 |
||
1306 |
removeAccessRights:aCollection |
|
1307 |
"remove the access rights as specified in aCollection for the file represented |
|
1308 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 1309 |
such as #readUser, #writeGroup etc. |
1310 |
Raise an error if not successful." |
|
615 | 1311 |
|
2922 | 1312 |
|access osName| |
1313 |
||
2939 | 1314 |
osName := self osNameForStat. |
2922 | 1315 |
access := OperatingSystem accessModeOf:osName. |
615 | 1316 |
aCollection do:[:accessSymbol | |
1317 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
|
1318 |
]. |
|
2922 | 1319 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1320 |
^ self accessDeniedError:self |
1321 |
]. |
|
1322 |
||
1323 |
" |
|
1324 |
'foo' asFilename writeStream close. |
|
1325 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
1326 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
1327 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
1328 |
" |
|
1329 |
! |
|
1330 |
||
1331 |
renameTo:newName |
|
671 | 1332 |
"rename the file - the argument must be convertable to a String. |
1333 |
Raise an error if not successful." |
|
615 | 1334 |
|
2922 | 1335 |
(OperatingSystem |
1336 |
renameFile:(self osNameForFile) |
|
1337 |
to:(newName asFilename osNameForFile) |
|
1338 |
) ifFalse:[ |
|
615 | 1339 |
self exists ifFalse:[ |
1340 |
^ self fileNotFoundError:self |
|
1341 |
]. |
|
1342 |
^ self accessDeniedError:newName asFilename. |
|
1343 |
]. |
|
1344 |
||
1345 |
" |
|
1346 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1347 |
" |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1348 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1349 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1350 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1351 |
"change the files size. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1352 |
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
|
1353 |
|
2922 | 1354 |
(OperatingSystem truncateFile:(self osNameForFile) to:newSize) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1355 |
^ 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
|
1356 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1357 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1358 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1359 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1360 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1361 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1362 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1363 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1364 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1365 |
'test' asFilename truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1366 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1367 |
" |
615 | 1368 |
! ! |
1369 |
||
1370 |
!Filename methodsFor:'file queries'! |
|
1371 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1372 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1373 |
"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
|
1374 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1375 |
^ self dates at:#accessed |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1376 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1377 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1378 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1379 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1380 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1381 |
"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
|
1382 |
"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
|
1383 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1384 |
|
615 | 1385 |
dates |
1386 |
"return the files modification and access times as an object (currently a dictionary) |
|
1387 |
that responds to the at: message with arguments |
|
1388 |
#modified, #accessed or #statusChanged." |
|
1389 |
||
2922 | 1390 |
|info dates osName| |
1391 |
||
2939 | 1392 |
osName := self osNameForStat. |
2922 | 1393 |
info := OperatingSystem infoOf:osName. |
615 | 1394 |
info isNil ifTrue:[ |
2922 | 1395 |
info := OperatingSystem linkInfoOf:osName. |
2629 | 1396 |
info isNil ifTrue:[ |
1397 |
^ nil |
|
1398 |
] |
|
615 | 1399 |
]. |
1400 |
dates := IdentityDictionary new. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1401 |
dates at:#modified put:(info modified). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1402 |
dates at:#accessed put:(info accessed). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1403 |
dates at:#statusChanged put:(info statusChanged). |
615 | 1404 |
^ dates |
1405 |
||
1406 |
" |
|
1407 |
Filename currentDirectory dates |
|
1408 |
'../regression' asFilename dates |
|
1409 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1410 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1411 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 1412 |
! |
1413 |
||
1414 |
fileSize |
|
1415 |
"return the size of the file in bytes" |
|
1416 |
||
1417 |
|info| |
|
1418 |
||
1419 |
info := self info. |
|
1420 |
info isNil ifTrue:[^ nil]. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1421 |
^ info size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1422 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1423 |
"Modified: 1.11.1996 / 20:24:43 / cg" |
615 | 1424 |
! |
1425 |
||
1426 |
fileType |
|
1427 |
"this returns a string describing the type of contents of |
|
1428 |
the file. This is done using the unix 'file' command, |
|
1429 |
(which usually is configurable by /etc/magic). |
|
2922 | 1430 |
On non-unix systems, this may return simply 'file', |
1431 |
not knowning about the contents. |
|
1432 |
Warning: |
|
1433 |
Since the returned string differs among systems (and language settings), |
|
1434 |
it is only useful for user-information; NOT as a tag to be used by a program." |
|
1435 |
||
1436 |
|buffer s n suffix idx baseNm| |
|
615 | 1437 |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1438 |
"/ 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
|
1439 |
"/ ones here. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1440 |
"/ (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
|
1441 |
|
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1442 |
self isSymbolicLink ifTrue:[ |
2906 | 1443 |
^ 'symbolic link to ' , (self linkInfo path) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1444 |
]. |
2573 | 1445 |
self isDirectory ifTrue:[ |
2906 | 1446 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
1447 |
self isExecutable ifFalse:[^ 'directory, locked']. |
|
1448 |
^ 'directory' |
|
2573 | 1449 |
]. |
1602 | 1450 |
self isReadable ifFalse:[^ 'unreadable']. |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1451 |
self fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 1452 |
|
2922 | 1453 |
suffix := self suffix asLowercase. |
1454 |
baseNm := self withoutSuffix baseName asLowercase. |
|
1455 |
||
1456 |
((#('st' 'rc' 'chg' 'htm' 'html' 'ps') includes:suffix) |
|
1457 |
or:[#('makefile') includes:baseNm]) ifTrue:[ |
|
1458 |
||
1459 |
buffer := String new:2024. |
|
1460 |
s := self readStream. |
|
1461 |
s notNil ifTrue:[ |
|
1462 |
n := s nextBytes:buffer size into:buffer. |
|
1463 |
s close. |
|
1464 |
||
1465 |
(suffix = 'st') ifTrue:[ |
|
2906 | 1466 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
1467 |
^ 'smalltalk source' |
|
1468 |
]. |
|
1469 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1470 |
^ 'smalltalk source' |
|
1471 |
]. |
|
1472 |
]. |
|
1473 |
||
1474 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1475 |
^ 'smalltalk changes / method source' |
|
1476 |
]. |
|
1477 |
||
1478 |
(suffix = 'rc') ifTrue:[ |
|
1479 |
(buffer findString:'ST/X startup') ~~ 0 ifTrue:[ |
|
1480 |
^ 'smalltalk startup script' |
|
1481 |
]. |
|
1482 |
]. |
|
2922 | 1483 |
|
2906 | 1484 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
1485 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
|
1486 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
|
1487 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
|
1488 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
|
1489 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
|
1490 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
|
1491 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
|
1492 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
|
1493 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
|
1494 |
ifTrue:[ |
|
1495 |
^ 'HTML document text' |
|
1496 |
] |
|
1497 |
]. |
|
1498 |
]. |
|
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1499 |
|
2906 | 1500 |
(suffix = 'ps') ifTrue:[ |
1501 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
|
1502 |
^ 'PostScript document' |
|
1503 |
]. |
|
1504 |
]. |
|
1505 |
||
1506 |
(baseNm = 'makefile') ifTrue:[ |
|
1507 |
(buffer startsWith:'#') ifTrue:[ |
|
1508 |
^ 'make rules' |
|
1509 |
] |
|
2922 | 1510 |
] |
2906 | 1511 |
] |
1602 | 1512 |
]. |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1513 |
|
2906 | 1514 |
^ 'file' |
615 | 1515 |
|
1516 |
" |
|
1517 |
'Makefile' asFilename fileType |
|
1518 |
'.' asFilename fileType |
|
1519 |
'/dev/null' asFilename fileType |
|
1520 |
'smalltalk.rc' asFilename fileType |
|
1521 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
1522 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1523 |
|
2906 | 1524 |
"Modified: 7.9.1997 / 23:43:48 / cg" |
615 | 1525 |
! |
1526 |
||
2836 | 1527 |
id |
1528 |
"return the files/directories file-id (inode number)" |
|
1529 |
||
2939 | 1530 |
^ OperatingSystem idOf:(self osNameForStat) |
2836 | 1531 |
|
1532 |
" |
|
1533 |
Filename currentDirectory id |
|
1534 |
" |
|
1535 |
||
1536 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
1537 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
1538 |
! |
|
1539 |
||
615 | 1540 |
info |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1541 |
"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
|
1542 |
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
|
1543 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1544 |
|
2629 | 1545 |
type - a symbol giving the files fileType |
1546 |
mode - numeric access mode |
|
1547 |
uid - owners user id |
|
1548 |
gid - owners group id |
|
1549 |
size - files size |
|
1550 |
id - files number (i.e. inode number) |
|
1551 |
accessed - last access time (as osTime-stamp) |
|
1552 |
modified - last modification time (as osTime-stamp) |
|
1553 |
statusChanged - last staus change (as osTime-stamp) |
|
615 | 1554 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1555 |
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
|
1556 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1557 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
2629 | 1558 |
modified |
1559 |
size |
|
1560 |
type |
|
615 | 1561 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1562 |
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
|
1563 |
to either handle nil values, |
615 | 1564 |
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
|
1565 |
(i.e. instead of: |
2629 | 1566 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1567 |
use |
2922 | 1568 |
someFilename isDirectory |
615 | 1569 |
" |
1570 |
||
2939 | 1571 |
^ OperatingSystem infoOf:(self osNameForStat) |
615 | 1572 |
|
1573 |
" |
|
1574 |
Filename currentDirectory info |
|
1575 |
'/dev/null' asFilename info |
|
1576 |
'Make.proto' asFilename info |
|
1577 |
'source/Point.st' asFilename info |
|
1578 |
'source/Point.st' asFilename linkInfo |
|
1579 |
'../../libbasic/Point.st' asFilename info |
|
1580 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1581 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1582 |
"Modified: 1.11.1996 / 20:22:40 / cg" |
615 | 1583 |
! |
1584 |
||
1585 |
linkInfo |
|
1586 |
"return the files info if its a symbolic link; nil otherwise. |
|
1587 |
On OS's which do not support symbolic links, nil is always returned. |
|
1588 |
The information is the same as returned by #info, except that if the |
|
1589 |
receiver represents a symbolic link, the links information |
|
1590 |
is returned |
|
1591 |
(while in this case, #info returns the info of the target file, |
|
1592 |
which is accessed via the symbolic link). |
|
1593 |
||
1594 |
In addition to the normal entries, Unix returns an additional entry: |
|
2629 | 1595 |
path -> the target files pathname |
615 | 1596 |
|
1597 |
See the comment in #info for more details." |
|
1598 |
||
2939 | 1599 |
^ OperatingSystem linkInfoOf:(self osNameForStat) |
615 | 1600 |
|
1601 |
" |
|
1602 |
Filename currentDirectory linkInfo |
|
1603 |
'/dev/null' asFilename linkInfo |
|
1604 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1605 |
'Make.proto' asFilename linkInfo path |
615 | 1606 |
'source/Point.st' asFilename linkInfo |
1607 |
'../../libbasic/Point.st' asFilename linkInfo |
|
1608 |
" |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1609 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1610 |
"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
|
1611 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1612 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1613 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1614 |
"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
|
1615 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1616 |
^ self dates at:#modified |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1617 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1618 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1619 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1620 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1621 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1622 |
"Created: 9.7.1996 / 10:18:59 / cg" |
2836 | 1623 |
! |
1624 |
||
1625 |
type |
|
1626 |
"return the symbolic type of the file" |
|
1627 |
||
2939 | 1628 |
^ OperatingSystem typeOf:(self osNameForStat) |
2836 | 1629 |
|
1630 |
" |
|
1631 |
Filename currentDirectory type |
|
1632 |
" |
|
1633 |
||
1634 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
1635 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 1636 |
! ! |
1637 |
||
1638 |
!Filename methodsFor:'file utilities'! |
|
1639 |
||
1640 |
edit |
|
1641 |
"start an editView on the file represented by the receiver" |
|
1642 |
||
1643 |
EditTextView openOn:self asString |
|
1644 |
||
1645 |
" |
|
1646 |
'smalltalk.rc' asFilename edit |
|
1647 |
" |
|
1648 |
! |
|
1649 |
||
1650 |
fileIn |
|
1651 |
"load smalltalk code from the file" |
|
1652 |
||
1653 |
^ self readStream fileIn |
|
542 | 1654 |
! ! |
1655 |
||
2 | 1656 |
!Filename methodsFor:'instance creation'! |
1657 |
||
615 | 1658 |
construct:subname |
1659 |
"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
|
1660 |
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
|
1661 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 1662 |
The argument may not specify an absolute path name. |
1663 |
Please do not use this to create filenames with suffixes, |
|
1664 |
since some systems require special naming conventions. |
|
1665 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 1666 |
|
2903 | 1667 |
^ self class named:(self constructString:subname) |
615 | 1668 |
|
1669 |
" |
|
1670 |
'/tmp' asFilename construct:'foo' |
|
1671 |
'/' asFilename construct:'foo' |
|
1672 |
'/usr/tmp' asFilename construct:'foo' |
|
1673 |
'/foo/bar' asFilename construct:'baz' |
|
2922 | 1674 |
|
1675 |
Bad example; works on UNIX, but may not on others: |
|
1676 |
'foo/bar.baz' construct:'.suff' |
|
615 | 1677 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1678 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1679 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 1680 |
! |
1681 |
||
2922 | 1682 |
constructDirectory:subname |
1683 |
"same as #construct: on most systems. |
|
1684 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
1685 |
||
1686 |
^ self class named:(self constructDirectoryString:subname) |
|
1687 |
! |
|
1688 |
||
1689 |
constructDirectoryString:subName |
|
1690 |
"same as #constructString: on most systems. |
|
1691 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
1692 |
||
1693 |
^ self constructString:subName |
|
1694 |
! |
|
1695 |
||
1696 |
constructString:subName |
|
2911 | 1697 |
"taking the receiver as a directory name, construct a new |
1698 |
filename-string for an entry within this directory |
|
2922 | 1699 |
(i.e. for a file or a subdirectory in that directory). |
1700 |
The argument may not specify an absolute path name." |
|
2911 | 1701 |
|
1702 |
|sepString| |
|
1703 |
||
1704 |
sepString := self class separator asString. |
|
1705 |
nameString = sepString ifTrue:[ |
|
1706 |
"I am the root" |
|
2922 | 1707 |
^ sepString , subName asString |
2911 | 1708 |
]. |
2922 | 1709 |
^ nameString , sepString , subName asString |
2911 | 1710 |
|
1711 |
" |
|
1712 |
'/tmp' asFilename constructString:'foo' |
|
1713 |
'/' asFilename constructString:'foo' |
|
1714 |
'/usr/tmp' asFilename constructString:'foo' |
|
1715 |
'/foo/bar' asFilename constructString:'baz' |
|
1716 |
" |
|
1717 |
||
1718 |
"Modified: 7.9.1995 / 10:15:22 / claus" |
|
1719 |
"Modified: 29.2.1996 / 20:55:18 / cg" |
|
1720 |
"Created: 9.9.1997 / 08:57:08 / cg" |
|
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1721 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1722 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1723 |
filenameFor:fileName |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1724 |
"taking the receiver as a directory name, construct a new |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1725 |
filename for an entry within this directory |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1726 |
(i.e. for a file or a subdirectory in that directory). |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1727 |
If the argument specifies an absolute path name, the argument is returned." |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1728 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1729 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1730 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1731 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1732 |
f isAbsolute ifTrue:[^ f]. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1733 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1734 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1735 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1736 |
'/tmp' asFilename filenameFor:'foo' |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1737 |
'/tmp' asFilename filenameFor:'/foo' |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1738 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1739 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1740 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
2 | 1741 |
! ! |
1742 |
||
195 | 1743 |
!Filename methodsFor:'misc'! |
1744 |
||
1745 |
, aString |
|
1746 |
"this allows filenames to understand how names are concatenated. |
|
308 | 1747 |
Returns a string consisting of the receivers name, concatenated |
195 | 1748 |
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
|
1749 |
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
|
1750 |
See also: #withSuffix: which is new and better." |
195 | 1751 |
|
2906 | 1752 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 1753 |
^ (nameString , aString asString) |
195 | 1754 |
|
1755 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1756 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1757 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1758 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1759 |
'Makefile' asFilename construct:'.bak' |
195 | 1760 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1761 |
|
2906 | 1762 |
"Modified: 7.9.1997 / 23:45:36 / cg" |
195 | 1763 |
! ! |
1764 |
||
615 | 1765 |
!Filename methodsFor:'printing & storing'! |
174 | 1766 |
|
615 | 1767 |
printOn:aStream |
1768 |
"append a printed representation of the receiver to aStream." |
|
174 | 1769 |
|
2906 | 1770 |
aStream nextPutAll:(self class name). |
1771 |
aStream nextPutAll:'('''. |
|
615 | 1772 |
nameString printOn:aStream. |
1773 |
aStream nextPutAll:''')' |
|
2906 | 1774 |
|
1775 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 1776 |
! |
1777 |
||
615 | 1778 |
storeOn:aStream |
1779 |
"append a printed representation of the receiver to aStream, |
|
1780 |
which allows reconstructing it via readFrom:" |
|
328 | 1781 |
|
615 | 1782 |
aStream nextPut:$(. |
1783 |
nameString storeOn:aStream. |
|
1784 |
aStream nextPutAll:' asFilename)' |
|
1 | 1785 |
! ! |
1786 |
||
202 | 1787 |
!Filename methodsFor:'private accessing'! |
1 | 1788 |
|
68 | 1789 |
setName:aString |
38 | 1790 |
"set the filename" |
1791 |
||
68 | 1792 |
nameString := aString |
1 | 1793 |
! ! |
1794 |
||
2 | 1795 |
!Filename methodsFor:'queries'! |
1796 |
||
615 | 1797 |
canBeWritten |
1798 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 1799 |
|
615 | 1800 |
^ self isWritable |
92 | 1801 |
|
328 | 1802 |
" |
615 | 1803 |
'/foo/bar' asFilename canBeWritten |
1804 |
'/tmp' asFilename canBeWritten |
|
1805 |
'Makefile' asFilename canBeWritten |
|
328 | 1806 |
" |
1807 |
! |
|
1808 |
||
68 | 1809 |
exists |
92 | 1810 |
"return true, if such a file exists." |
68 | 1811 |
|
2939 | 1812 |
^ OperatingSystem isValidPath:(self osNameForStat) |
68 | 1813 |
|
85 | 1814 |
" |
92 | 1815 |
'/foo/bar' asFilename exists |
1816 |
'/tmp' asFilename exists |
|
1817 |
'Makefile' asFilename exists |
|
85 | 1818 |
" |
77 | 1819 |
! |
1820 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1821 |
filesMatching:aPattern |
2550 | 1822 |
"given the receiver, representing a directory; |
1823 |
return a collection of files matching a pattern. |
|
1824 |
The pattern may be a simple matchPattern, or a set of |
|
1825 |
multiple patterns separated by semicolons." |
|
1826 |
||
1827 |
|matchers| |
|
1828 |
||
1829 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
1830 |
^ self directoryContents |
|
2629 | 1831 |
select:[:name | |
1832 |
(matchers detect:[:p | p match:name] ifNone:0) ~~ 0 |
|
1833 |
] |
|
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1834 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1835 |
" |
2550 | 1836 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1837 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1838 |
|
2550 | 1839 |
"Created: 15.4.1997 / 15:40:02 / cg" |
1840 |
"Modified: 15.4.1997 / 15:41:33 / cg" |
|
1841 |
! |
|
1842 |
||
1843 |
filesMatchingWithoutDotDirs:aPattern |
|
1844 |
"given the receiver, representing a directory; |
|
1845 |
return a collection of files matching a pattern. |
|
1846 |
Exclude '.' and '..' from the returned list. |
|
1847 |
The pattern may be a simple matchPattern, or a set of |
|
1848 |
multiple patterns separated by semicolons." |
|
1849 |
||
1850 |
|matchers| |
|
1851 |
||
1852 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
1853 |
^ self directoryContents |
|
2629 | 1854 |
select:[:name | |
1855 |
name ~= '.' |
|
1856 |
and:[name ~= '..' |
|
1857 |
and:[(matchers detect:[:p | p match:name] ifNone:0) ~~ 0]] |
|
2550 | 1858 |
] |
1859 |
||
1860 |
" |
|
1861 |
Filename currentDirectory filesMatching:'M*' |
|
1862 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
1863 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
1864 |
" |
|
1865 |
||
1866 |
"Created: 15.4.1997 / 12:52:10 / cg" |
|
1867 |
"Modified: 15.4.1997 / 15:41:40 / cg" |
|
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1868 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1869 |
|
615 | 1870 |
isAbsolute |
1871 |
"return true, if the receiver represents an absolute pathname |
|
1872 |
(in contrast to one relative to the current directory)." |
|
356 | 1873 |
|
2629 | 1874 |
(nameString startsWith:self class separator) ifTrue:[^ true]. |
1875 |
^ self isVolumeAbsolute |
|
328 | 1876 |
|
1877 |
" |
|
615 | 1878 |
'/foo/bar' asFilename isAbsolute |
1879 |
'..' asFilename isAbsolute |
|
1880 |
'..' asAbsoluteFilename isAbsolute |
|
1881 |
'source/SBrowser.st' asFilename isAbsolute |
|
1882 |
" |
|
1883 |
! |
|
1884 |
||
1885 |
isDirectory |
|
1886 |
"return true, if the receiver represents an existing, |
|
1887 |
readable directories pathname." |
|
1888 |
||
2939 | 1889 |
^ OperatingSystem isDirectory:(self osNameForStat) |
615 | 1890 |
|
1891 |
" |
|
1892 |
'/foo/bar' asFilename isDirectory |
|
1893 |
'/tmp' asFilename isDirectory |
|
1894 |
'Makefile' asFilename isDirectory |
|
1895 |
" |
|
1896 |
! |
|
1897 |
||
1898 |
isExecutable |
|
1899 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
1900 |
For directories, true is returned if the directory can be entered. |
|
1901 |
See isExecutableProgram for a related check." |
|
1902 |
||
2939 | 1903 |
^ OperatingSystem isExecutable:(self osNameForStat) |
615 | 1904 |
|
1905 |
" |
|
1906 |
'/foo/bar' asFilename isExecutable |
|
1907 |
'/tmp' asFilename isExecutable |
|
1908 |
'Makefile' asFilename isExecutable |
|
1909 |
'/bin/ls' asFilename isExecutable |
|
356 | 1910 |
" |
1911 |
! |
|
1912 |
||
615 | 1913 |
isExecutableProgram |
1914 |
"return true, if such a file exists and is an executable program. |
|
1915 |
(i.e. for directories, false is returned.)" |
|
356 | 1916 |
|
2922 | 1917 |
|osName| |
1918 |
||
2939 | 1919 |
osName := self osNameForStat. |
2922 | 1920 |
^ (OperatingSystem isExecutable:osName) |
1921 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 1922 |
|
1923 |
" |
|
615 | 1924 |
'/tmp' asFilename isExecutable |
1925 |
'/bin/ls' asFilename isExecutable |
|
1926 |
'/tmp' asFilename isExecutableProgram |
|
1927 |
'/bin/ls' asFilename isExecutableProgram |
|
1928 |
" |
|
1929 |
! |
|
1930 |
||
2922 | 1931 |
isExplicitRelative |
1932 |
"return true, if this name is an explicit relative name |
|
1933 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
1934 |
||
1935 |
^ false |
|
1936 |
! |
|
1937 |
||
1938 |
isHidden |
|
1939 |
"return true, if the receiver represents a hidden file. |
|
1940 |
The definitions of hidden files depends on the OS used; |
|
1941 |
on UNIX, a name starting with a period is considered hidden; |
|
1942 |
on MSDOS, the files hidden attribute is used. |
|
1943 |
VMS has no concept of hidden files." |
|
1944 |
||
1945 |
^ false |
|
1946 |
! |
|
1947 |
||
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1948 |
isImplicit |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1949 |
"return true, if the receiver represents a builtin file. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1950 |
The definitions of builtin files depends on the OS used; |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1951 |
on UNIX, '.' and '..' are builtin names." |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1952 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1953 |
^ false |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1954 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1955 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1956 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1957 |
|
615 | 1958 |
isReadable |
1959 |
"return true, if such a file exists and is readable." |
|
1960 |
||
2939 | 1961 |
^ OperatingSystem isReadable:(self osNameForStat) |
615 | 1962 |
|
1963 |
" |
|
1964 |
'/foo/bar' asFilename isReadable |
|
1965 |
'/tmp' asFilename isReadable |
|
1966 |
'Makefile' asFilename isReadable |
|
328 | 1967 |
" |
1968 |
! |
|
1969 |
||
615 | 1970 |
isRelative |
1971 |
"return true, if this name is interpreted relative to some |
|
1972 |
directory (opposite of absolute)" |
|
328 | 1973 |
|
615 | 1974 |
^ self isAbsolute not |
2175 | 1975 |
|
1976 |
" |
|
1977 |
'./foo/bar' asFilename isRelative |
|
1978 |
'../../foo/bar' asFilename isRelative |
|
1979 |
'/foo/bar' asFilename isRelative |
|
1980 |
'bar' asFilename isRelative |
|
1981 |
" |
|
1982 |
||
1983 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
615 | 1984 |
! |
328 | 1985 |
|
615 | 1986 |
isSymbolicLink |
1987 |
"return true, if the file represented by the receiver is a symbolic |
|
1988 |
link. Notice that not all OS's support symbolic links; those that do |
|
1989 |
not will always return false." |
|
1990 |
||
2939 | 1991 |
^ OperatingSystem isSymbolicLink:(self osNameForStat) |
328 | 1992 |
|
1993 |
" |
|
615 | 1994 |
'Make.proto' asFilename isSymbolicLink |
1995 |
'Makefile' asFilename isSymbolicLink |
|
1996 |
" |
|
1997 |
! |
|
1998 |
||
2629 | 1999 |
isVolumeAbsolute |
2000 |
"return true, if the receiver represents an absolute pathname |
|
2001 |
on some disk volume (MSDOS only)" |
|
2002 |
||
2003 |
^ false |
|
2906 | 2004 |
|
2005 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
2629 | 2006 |
! |
2007 |
||
615 | 2008 |
isWritable |
2009 |
"return true, if such a file exists and is writable." |
|
2010 |
||
2939 | 2011 |
^ OperatingSystem isWritable:(self osNameForStat) |
615 | 2012 |
|
2013 |
" |
|
2014 |
'/foo/bar' asFilename isWritable |
|
2015 |
'/tmp' asFilename isWritable |
|
2016 |
'Makefile' asFilename isWritable |
|
328 | 2017 |
" |
174 | 2018 |
! |
2019 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2020 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2021 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2022 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2023 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2024 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2025 |
"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
|
2026 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2027 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2028 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2029 |
|
1540 | 2030 |
contents |
2031 |
"return the contents of the file as a collection of lines; |
|
2032 |
or nil, if the file is unreadable." |
|
2033 |
||
2034 |
|s contents| |
|
2035 |
||
2036 |
s := self readStream. |
|
2037 |
s isNil ifTrue:[^ nil]. |
|
2038 |
||
2039 |
[ |
|
2629 | 2040 |
contents := s contents |
1540 | 2041 |
] valueNowOrOnUnwindDo:[s close]. |
2042 |
^ contents |
|
2043 |
||
2044 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
2045 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
|
2046 |
"Created: 11.7.1996 / 14:09:11 / cg" |
|
2047 |
! |
|
2048 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2049 |
contentsOfEntireFile |
1540 | 2050 |
"return the contents of the file as a string; |
2051 |
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
|
2052 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2053 |
|s contents| |
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 |
s := self readStream. |
1535 | 2056 |
s isNil ifTrue:[^ nil]. |
2057 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2058 |
[ |
2629 | 2059 |
contents := s contentsOfEntireFile |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2060 |
] valueNowOrOnUnwindDo:[s close]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2061 |
^ contents |
1523 | 2062 |
|
2063 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1540 | 2064 |
"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
|
2065 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2066 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2067 |
directoryContents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2068 |
"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
|
2069 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2070 |
^ (FileDirectory directoryNamed:self asString) contents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2071 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2072 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2073 |
'.' asFilename directoryContents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2074 |
" |
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 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2077 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2078 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2079 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2080 |
"return my baseName as a string. |
2012 | 2081 |
- thats the file/directory name without leading parent-dirs. |
2922 | 2082 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
2083 |
and '/usr/lib' asFilename baseName -> lib). |
|
2084 |
This method does not check if the path is valid |
|
2085 |
||
2911 | 2086 |
See also: #pathName, #directoryName and #directoryPathName. |
2087 |
Compatibility note: use #tail for ST-80 compatibility." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2088 |
|
2922 | 2089 |
|len index sep endIdx| |
2090 |
||
2091 |
sep := self separator. |
|
2092 |
len := nameString size. |
|
2093 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
2094 |
^ nameString |
|
2095 |
]. |
|
2096 |
||
2097 |
endIdx := len. |
|
2098 |
len > 1 ifTrue:[ |
|
2099 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
|
2100 |
]. |
|
2101 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
2102 |
index == 0 ifTrue:[ |
|
2103 |
^ nameString copyTo:endIdx |
|
2104 |
]. |
|
2105 |
^ nameString copyFrom:(index+1) to:endIdx |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2106 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2107 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2108 |
'/foo/bar' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2109 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2110 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2111 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2112 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2113 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2114 |
'../../libbasic/Object.st' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2115 |
" |
2012 | 2116 |
|
2922 | 2117 |
"Modified: 13.9.1997 / 09:32:49 / cg" |
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 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2121 |
"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
|
2122 |
- 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
|
2123 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2124 |
(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
|
2125 |
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
|
2126 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2127 |
^ self directoryName asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2128 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2129 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2130 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2131 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2132 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2133 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2134 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2135 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2136 |
'../..' asFilename directory |
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 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2139 |
"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
|
2140 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2141 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2142 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2143 |
"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
|
2144 |
- 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
|
2145 |
the receiver is contained in. |
2922 | 2146 |
This method does not check if the path is valid. |
2147 |
||
2148 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
2149 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
2150 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2151 |
(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
|
2152 |
a string instead of a Filename instance). |
2922 | 2153 |
|
2012 | 2154 |
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
|
2155 |
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
|
2156 |
|
2922 | 2157 |
|last index sep sepString p| |
2158 |
||
2159 |
sep := self separator. |
|
2160 |
sepString := sep asString. |
|
2161 |
(nameString = sepString) ifTrue:[ |
|
2162 |
"/ |
|
2163 |
"/ the trivial '/' case |
|
2164 |
"/ |
|
2165 |
^ nameString |
|
2166 |
]. |
|
2167 |
||
2168 |
"/ |
|
2169 |
"/ strip off multiple leading slashes |
|
2170 |
"/ |
|
2171 |
p := nameString. |
|
2172 |
[p endsWith:sepString] whileTrue:[ |
|
2173 |
(p = sepString) ifTrue:[ |
|
2174 |
^ p |
|
2175 |
]. |
|
2176 |
p := p copyWithoutLast:1 |
|
2177 |
]. |
|
2178 |
||
2179 |
last := 1. |
|
2180 |
[true] whileTrue:[ |
|
2181 |
index := p indexOf:sep startingAt:(last + 1). |
|
2182 |
index == 0 ifTrue:[ |
|
2183 |
(last == 1) ifTrue:[ |
|
2184 |
(p startsWith:sepString) ifTrue:[ |
|
2185 |
^ sepString |
|
2186 |
]. |
|
2187 |
^ '.' |
|
2188 |
]. |
|
2189 |
^ p copyTo:(last - 1) |
|
2190 |
]. |
|
2191 |
last := index. |
|
2192 |
]. |
|
2193 |
||
2194 |
"/ notreached |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2195 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2196 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2197 |
'/foo/bar/' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2198 |
'/foo/bar/' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2199 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2200 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2201 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2202 |
'bitmaps' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2203 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2204 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2205 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2206 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2207 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2208 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2209 |
"Modified: 7.9.1995 / 10:42:03 / claus" |
2012 | 2210 |
"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
|
2211 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2212 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2213 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2214 |
"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
|
2215 |
- 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
|
2216 |
the receiver is contained in. |
2012 | 2217 |
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
|
2218 |
|
2922 | 2219 |
^ self pathName asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2220 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2221 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2222 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2223 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2224 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2225 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2226 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2227 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2228 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2229 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2230 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2231 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2232 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2233 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2234 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2235 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2236 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 2237 |
"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
|
2238 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2239 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2240 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2241 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2242 |
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
|
2243 |
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
|
2244 |
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
|
2245 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2246 |
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
|
2247 |
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
|
2248 |
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
|
2249 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2250 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2251 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2252 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2253 |
'mak' asFilename filenameCompletion |
1517 | 2254 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2255 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2256 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2257 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2258 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2259 |
|
1517 | 2260 |
"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
|
2261 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2262 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2263 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2264 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2265 |
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
|
2266 |
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
|
2267 |
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
|
2268 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2269 |
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
|
2270 |
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
|
2271 |
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
|
2272 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2273 |
|dir baseName matching matchLen try allMatching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2274 |
sepString parentString prefix nMatch| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2275 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2276 |
sepString := self class separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2277 |
(nameString endsWith:sepString) ifTrue:[ |
2906 | 2278 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2279 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2280 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2281 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2282 |
baseName := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2283 |
baseName ~= nameString ifTrue:[ |
2906 | 2284 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2285 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2286 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2287 |
self isAbsolute ifTrue:[ |
2906 | 2288 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2289 |
] ifFalse:[ |
2906 | 2290 |
aDirectory isNil ifTrue:[ |
2291 |
dir := self directory |
|
2292 |
] ifFalse:[ |
|
2293 |
dir := (aDirectory construct:nameString) directory |
|
2294 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2295 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2296 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2297 |
matching := OrderedCollection new. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2298 |
dir directoryContents do:[:fileName | |
2906 | 2299 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
2300 |
(fileName startsWith:baseName) ifTrue:[ |
|
2301 |
matching add:fileName |
|
2302 |
] |
|
2303 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2304 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2305 |
(nMatch := matching size) > 1 ifTrue:[ |
2906 | 2306 |
" |
2307 |
find the longest common prefix |
|
2308 |
" |
|
2309 |
matchLen := baseName size. |
|
2310 |
matchLen > matching first size ifTrue:[ |
|
2311 |
try := baseName. |
|
2312 |
allMatching := false |
|
2313 |
] ifFalse:[ |
|
2314 |
try := matching first copyTo:matchLen. |
|
2315 |
allMatching := true. |
|
2316 |
]. |
|
2317 |
||
2318 |
[allMatching] whileTrue:[ |
|
2319 |
matching do:[:aName | |
|
2320 |
(aName startsWith:try) ifFalse:[ |
|
2321 |
allMatching := false |
|
2322 |
] |
|
2323 |
]. |
|
2324 |
allMatching ifTrue:[ |
|
2325 |
matchLen < matching first size ifTrue:[ |
|
2326 |
matchLen := matchLen + 1. |
|
2327 |
try := matching first copyTo:matchLen. |
|
2328 |
] ifFalse:[ |
|
2329 |
allMatching := false |
|
2330 |
] |
|
2331 |
] ifFalse:[ |
|
2332 |
try := matching first copyTo:matchLen - 1. |
|
2333 |
] |
|
2334 |
]. |
|
2335 |
" |
|
2336 |
and set my name to the last full match |
|
2337 |
" |
|
2338 |
nameString := try |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2339 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2340 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2341 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2342 |
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
|
2343 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2344 |
prefix notNil ifTrue:[ |
2906 | 2345 |
prefix = sepString ifTrue:[ |
2346 |
"/ avoid introducing double slashes |
|
2347 |
prefix := '' |
|
2348 |
]. |
|
2349 |
matching := matching collect:[:n | prefix , sepString , n]. |
|
2350 |
nMatch == 1 ifTrue:[ |
|
2351 |
nameString := matching first |
|
2352 |
] ifFalse:[ |
|
2353 |
nMatch > 1 ifTrue:[ |
|
2354 |
nameString := prefix , sepString , nameString |
|
2355 |
] |
|
2356 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2357 |
] ifFalse:[ |
2906 | 2358 |
nMatch == 1 ifTrue:[ |
2359 |
nameString := matching first |
|
2360 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2361 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2362 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2363 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2364 |
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
|
2365 |
(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
|
2366 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2367 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2368 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2369 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2370 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2371 |
'../' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2372 |
'/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2373 |
'/usr/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2374 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2375 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2376 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2377 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2378 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2379 |
'../../libpr' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2380 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2381 |
|
2906 | 2382 |
"Modified: 7.9.1997 / 23:56:53 / cg" |
2903 | 2383 |
! |
2384 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2385 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2386 |
"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
|
2387 |
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
|
2388 |
(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
|
2389 |
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
|
2390 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2391 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2392 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2393 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2394 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2395 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2396 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2397 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2398 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2399 |
"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
|
2400 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2401 |
|
615 | 2402 |
name |
2403 |
"return the name of the file represented by the receiver as a string. |
|
883 | 2404 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 2405 |
See also: pathName" |
174 | 2406 |
|
615 | 2407 |
self isAbsolute ifTrue:[^ self pathName]. |
2408 |
^ nameString |
|
174 | 2409 |
|
2410 |
" |
|
615 | 2411 |
'/foo/bar' asFilename name |
2412 |
'/foo/bar' asFilename pathName |
|
2413 |
'.' asFilename name |
|
2414 |
'.' asFilename pathName |
|
2415 |
'../..' asFilename name |
|
883 | 2416 |
'../..' asFilename pathName |
615 | 2417 |
'bitmaps' asFilename name |
2418 |
'bitmaps' asFilename pathName |
|
2419 |
'/tmp/../usr' asFilename name |
|
883 | 2420 |
'/tmp/../usr' asFilename pathName |
2421 |
'source/..' asFilename name |
|
2422 |
'source/..' asFilename pathName |
|
2423 |
'/tmp/..' asFilename name |
|
2424 |
'/tmp/..' asFilename pathName |
|
92 | 2425 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2426 |
|
883 | 2427 |
"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
|
2428 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2429 |
|
615 | 2430 |
pathName |
2431 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 2432 |
as a string. This will not include ..'s. |
2433 |
If the path represented by the receiver does NOT represent a valid path, |
|
2434 |
no compression will be done (for now; this may change). |
|
2435 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2436 |
|
1317 | 2437 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2438 |
|
1317 | 2439 |
"/ sep := self class separator. |
2440 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
2441 |
"/ parentName := self class parentDirectoryName. |
|
2442 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
2443 |
"/ ^ nameString |
|
2444 |
"/ ] |
|
2445 |
"/ ]. |
|
2446 |
p := OperatingSystem pathNameOf:nameString. |
|
2447 |
^ p |
|
2 | 2448 |
|
92 | 2449 |
" |
1317 | 2450 |
'/foo/bar' asFilename pathName |
2451 |
'.' asFilename pathName |
|
2452 |
'../..' asFilename pathName |
|
2453 |
'../..' asFilename name |
|
2454 |
'/tmp/../usr' asFilename pathName |
|
2455 |
'/././usr' asFilename pathName |
|
92 | 2456 |
" |
159 | 2457 |
|
1317 | 2458 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 2459 |
! |
2460 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2461 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2462 |
"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
|
2463 |
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
|
2464 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2465 |
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
|
2466 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2467 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2468 |
|t target path| |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2469 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2470 |
self isSymbolicLink ifFalse:[ |
2629 | 2471 |
self exists ifFalse:[^ nil]. |
2472 |
^ self pathName |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2473 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2474 |
t := self. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2475 |
[t isSymbolicLink] whileTrue:[ |
2629 | 2476 |
path := t linkInfo path. |
2477 |
path isNil ifTrue:[ |
|
2478 |
"/ cannot happen |
|
2479 |
^ nil |
|
2480 |
]. |
|
2481 |
target := t directoryName asFilename construct:path. |
|
2482 |
target exists ifFalse:[^ nil]. |
|
2483 |
t := target asFilename |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2484 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2485 |
t exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2486 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2487 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2488 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2489 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2490 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2491 |
'../..' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2492 |
'include/abbrev.stc' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2493 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2494 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2495 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2496 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2497 |
|
615 | 2498 |
tail |
2499 |
"the files name without directory prefix as a string. |
|
2500 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 2501 |
|
615 | 2502 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2503 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2504 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2505 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2506 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2507 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2508 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2509 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2510 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 2511 |
! |
2512 |
||
2513 |
volume |
|
2514 |
"return the disc volume part of the name or an empty string. |
|
2906 | 2515 |
This is only used with MSDOS and VMS filenames |
2516 |
- by default (and on unix), an empty string is returned" |
|
2517 |
||
2629 | 2518 |
^ '' |
2906 | 2519 |
|
2520 |
"Modified: 8.9.1997 / 00:37:33 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2521 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2522 |
|
2922 | 2523 |
!Filename methodsFor:'special accessing'! |
2524 |
||
2525 |
osName |
|
2526 |
"special - return the OS's name for the receiver." |
|
2527 |
||
2528 |
self isDirectory ifTrue:[ |
|
2529 |
^ self osNameForDirectory |
|
2530 |
]. |
|
2531 |
^ self osNameForFile |
|
2532 |
! |
|
2533 |
||
2534 |
osNameForDirectory |
|
2535 |
"special - return the OS's name for the receiver to |
|
2536 |
access it as a directory." |
|
2537 |
||
2538 |
^ nameString |
|
2539 |
! |
|
2540 |
||
2541 |
osNameForFile |
|
2542 |
"internal - return the OS's name for the receiver to |
|
2543 |
access it as a file." |
|
2544 |
||
2545 |
^ nameString |
|
2939 | 2546 |
! |
2547 |
||
2548 |
osNameForStat |
|
2549 |
^ nameString |
|
2922 | 2550 |
! ! |
2551 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2552 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2553 |
|
2906 | 2554 |
hasSuffix:aSuffixString |
2555 |
"return true if my suffix is the same as aString. |
|
2556 |
This cares for systems, where case is ignored in filenames" |
|
2557 |
||
2558 |
|mySuffix| |
|
2559 |
||
2560 |
mySuffix := self suffix. |
|
2561 |
self class isCaseSensitive ifTrue:[ |
|
2562 |
^ mySuffix = aSuffixString |
|
2563 |
]. |
|
2564 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
2565 |
||
2566 |
" |
|
2567 |
'abc.st' asFilename hasSuffix:'st' |
|
2568 |
'abc.ST' asFilename hasSuffix:'st' |
|
2569 |
" |
|
2570 |
||
2571 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
2572 |
! |
|
2573 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2574 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2575 |
"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
|
2576 |
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
|
2577 |
the prefix everything before, except for the period. |
1517 | 2578 |
The directory name part is stripped off (i.e. the returned prefix |
2579 |
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
|
2580 |
(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
|
2581 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
1517 | 2582 |
See also: #withoutSuffix and #withSuffix |
2583 |
Notice: |
|
2629 | 2584 |
there is currently no known system which uses other than |
2585 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2586 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2587 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2588 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2589 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2590 |
idx := nm lastIndexOf:(self class suffixSeparator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2591 |
idx == 0 ifTrue:[ |
2629 | 2592 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2593 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2594 |
^ Array |
2629 | 2595 |
with:(nm copyTo:idx-1) |
2596 |
with:(nm copyFrom:idx+1) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2597 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2598 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2599 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2600 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2601 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 2602 |
'/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
|
2603 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2604 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2605 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 2606 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2607 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2608 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2609 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 2610 |
"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
|
2611 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2612 |
|
2906 | 2613 |
suffix |
2614 |
"return my suffix. |
|
2615 |
The suffix is the namepart after the final period character, |
|
2616 |
or the empty string, if the name does not contain a period." |
|
2617 |
||
2618 |
^ self prefixAndSuffix at:2 |
|
2619 |
||
2620 |
" |
|
2621 |
'abc.st' asFilename suffix |
|
2622 |
'abc' asFilename suffix |
|
2623 |
'a.b.c' asFilename suffix |
|
2624 |
" |
|
2625 |
||
2626 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
2627 |
! |
|
2628 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2629 |
withSuffix:aSuffix |
2922 | 2630 |
"return a new filename for the receivers name with a different suffix. |
1993 | 2631 |
If the name already has a suffix, the new suffix replacaes it; |
2632 |
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
|
2633 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2634 |
^ self class named: |
2629 | 2635 |
(self withoutSuffix name |
2636 |
, self class suffixSeparator asString |
|
2637 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2638 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2639 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2640 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2641 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2642 |
'a.b.c' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2643 |
'/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
|
2644 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 2645 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 2646 |
'/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
|
2647 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2648 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2649 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1993 | 2650 |
"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
|
2651 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2652 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2653 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2654 |
"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
|
2655 |
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
|
2656 |
|
2922 | 2657 |
|nm idx| |
2658 |
||
2659 |
nm := self baseName. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2660 |
idx := nameString lastIndexOf:(self class suffixSeparator). |
2922 | 2661 |
(idx == 0) ifTrue:[^ self]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2662 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2663 |
^ 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
|
2664 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2665 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2666 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2667 |
'abc' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2668 |
'a.b.c' asFilename withoutSuffix |
1516 | 2669 |
'/foo/bar/baz.c' asFilename withoutSuffix |
2670 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
|
2671 |
'/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
|
2672 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2673 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2674 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1516 | 2675 |
"Modified: 3.7.1996 / 10:49:58 / cg" |
174 | 2676 |
! ! |
2677 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2678 |
!Filename class methodsFor:'documentation'! |
630 | 2679 |
|
2680 |
version |
|
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2681 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.100 1997-09-18 17:28:12 stefan Exp $' |
630 | 2682 |
! ! |
2906 | 2683 |
Filename initialize! |