author | Claus Gittinger <cg@exept.de> |
Tue, 21 Mar 2000 12:07:58 +0100 | |
changeset 5303 | fd21c677d273 |
parent 5226 | 49955e61788f |
child 5507 | e8c61b1741c6 |
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 |
||
3959 | 255 |
!Filename class methodsFor:'instance creation'! |
256 |
||
257 |
currentDirectory |
|
258 |
"return a filename for the current directory" |
|
259 |
||
260 |
(self ~~ ConcreteClass) ifTrue:[ |
|
261 |
^ ConcreteClass currentDirectory |
|
262 |
]. |
|
263 |
||
264 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
265 |
||
266 |
^ self named:'.' |
|
267 |
"/ ^ self named:('.' asFilename pathName) |
|
268 |
||
269 |
" |
|
270 |
Filename currentDirectory |
|
271 |
" |
|
272 |
||
273 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
274 |
! |
|
275 |
||
276 |
currentDirectoryName |
|
277 |
"return a filename for the current directory" |
|
278 |
||
279 |
(self ~~ ConcreteClass) ifTrue:[ |
|
280 |
^ ConcreteClass currentDirectoryName |
|
281 |
]. |
|
282 |
||
283 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
284 |
||
285 |
^ '.' |
|
286 |
||
287 |
" |
|
288 |
Filename currentDirectoryName |
|
289 |
" |
|
290 |
||
291 |
"Modified: / 8.9.1997 / 00:24:15 / cg" |
|
292 |
"Created: / 21.10.1998 / 17:49:57 / cg" |
|
293 |
! |
|
294 |
||
295 |
defaultDirectory |
|
296 |
"ST80 compatibility: same as currentDirectory" |
|
297 |
||
298 |
^ self currentDirectory |
|
299 |
||
300 |
" |
|
301 |
Filename defaultDirectory |
|
302 |
" |
|
303 |
! |
|
304 |
||
305 |
defaultDirectoryName |
|
306 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
|
307 |
||
308 |
^ self defaultDirectory name |
|
309 |
||
310 |
" |
|
311 |
Filename defaultDirectoryName |
|
312 |
" |
|
313 |
! |
|
314 |
||
315 |
defaultTempDirectoryName |
|
316 |
"return the default temp directory as a filename. |
|
317 |
This is used, if no special preferences were defined in |
|
318 |
any of the TEMP-environment variables (see tempDirectory)." |
|
319 |
||
320 |
(self ~~ ConcreteClass) ifTrue:[ |
|
321 |
^ ConcreteClass defaultTempDirectoryName |
|
322 |
]. |
|
323 |
||
324 |
^ '/tmp' |
|
325 |
||
326 |
" |
|
327 |
Filename defaultTempDirectoryName |
|
328 |
" |
|
329 |
||
330 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
331 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
332 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
333 |
! |
|
334 |
||
335 |
findDefaultDirectory |
|
336 |
"same as #defaultDirectory for ST80 compatibility" |
|
337 |
||
338 |
^ self defaultDirectory |
|
339 |
||
340 |
"Created: 20.6.1997 / 17:00:29 / cg" |
|
341 |
! |
|
342 |
||
343 |
fromComponents:aCollectionOfDirectoryNames |
|
344 |
"create & return a new filename from components given in |
|
345 |
aCollectionOfDirectoryNames. If the first component is the name of the |
|
346 |
root directory (i.e. '/') an absolute path-filename is returned." |
|
347 |
||
348 |
|sep s| |
|
349 |
||
350 |
(self ~~ ConcreteClass) ifTrue:[ |
|
351 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
|
352 |
]. |
|
353 |
||
354 |
"/ fallBack - works on Unix & MSDOS |
|
355 |
||
356 |
sep := self separator asString. |
|
357 |
s := ''. |
|
358 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
|
359 |
index == 1 ifTrue:[ |
|
360 |
(component ~= sep |
|
361 |
or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ |
|
362 |
s := s , component |
|
363 |
] |
|
364 |
] ifFalse:[ |
|
365 |
s := s , sep , component |
|
366 |
]. |
|
367 |
]. |
|
368 |
^ self named:s |
|
369 |
||
370 |
" |
|
371 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
|
372 |
Filename fromComponents:#('foo' 'bar' 'baz') |
|
373 |
Filename fromComponents:#('/') |
|
374 |
||
375 |
Filename fromComponents: |
|
376 |
(Filename components:('.' asFilename pathName)) |
|
377 |
||
378 |
Filename fromComponents: |
|
379 |
(Filename components:('.' asFilename name)) |
|
380 |
" |
|
381 |
||
382 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
383 |
! |
|
384 |
||
385 |
fromUser |
|
386 |
"show a box to enter a filename. |
|
387 |
Return a filename instance or nil (if cancel was pressed)." |
|
388 |
||
389 |
|name| |
|
390 |
||
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
391 |
name := Dialog |
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
392 |
requestFileName:'filename:' |
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
393 |
default:nil |
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
394 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory). |
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
395 |
|
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
396 |
name size > 0 ifTrue:[ |
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
397 |
^ self named:name |
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
398 |
]. |
3959 | 399 |
^ nil |
400 |
||
401 |
" |
|
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
402 |
Filename fromUser |
3959 | 403 |
" |
404 |
||
405 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
|
406 |
! |
|
407 |
||
408 |
homeDirectory |
|
409 |
"return your homeDirectory. |
|
410 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
|
411 |
(which is the currentDirectory) is returned." |
|
412 |
||
413 |
|s| |
|
414 |
||
415 |
s := OperatingSystem getHomeDirectory. |
|
416 |
s isNil ifTrue:[ |
|
417 |
^ self defaultDirectory |
|
418 |
]. |
|
419 |
^ self named:s |
|
420 |
||
421 |
" |
|
422 |
Filename homeDirectory |
|
423 |
" |
|
424 |
||
425 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
|
426 |
! |
|
427 |
||
428 |
named:aString |
|
429 |
"return a filename for a directory named aString. |
|
430 |
This is the same as 'aString asFilename'." |
|
431 |
||
432 |
|cls| |
|
433 |
||
434 |
cls := self. |
|
435 |
cls == Filename ifTrue:[ |
|
436 |
cls := self concreteClass |
|
437 |
]. |
|
438 |
^ (cls basicNew) setName:aString |
|
439 |
||
440 |
" |
|
441 |
Filename named:'/tmp/fooBar' |
|
442 |
" |
|
443 |
||
444 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
445 |
! |
|
446 |
||
447 |
newTemporary |
|
448 |
"return a new unique filename - use this for temporary files. |
|
449 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
450 |
unix process id, and nn is a unique number, incremented with every |
|
451 |
call to this method. |
|
452 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
4757 | 453 |
its value defines the temp directory. |
454 |
Notice, that no file is created by this - only a unique name |
|
455 |
is generated." |
|
3959 | 456 |
|
457 |
^ self newTemporaryIn:(self tempDirectory) pathName |
|
458 |
||
459 |
" |
|
460 |
Filename newTemporary |
|
461 |
Filename newTemporary |
|
462 |
" |
|
463 |
||
464 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
465 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
|
466 |
! |
|
467 |
||
468 |
newTemporaryIn:aDirectoryPrefix |
|
469 |
"return a new unique filename - use this for temporary files. |
|
470 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
|
471 |
where xx is our unix process id, and nn is a unique number, incremented |
|
472 |
with every call to this method. |
|
473 |
Notice: only a unique filename object is created and returned - no physical |
|
474 |
file is created by this method (i.e. you have to send #writeStream or |
|
475 |
whatever to it in order to really create something). |
|
476 |
See also: #newTemporary which looks for a good temp directory." |
|
477 |
||
478 |
|pid nameString fn| |
|
479 |
||
480 |
(self ~~ ConcreteClass) ifTrue:[ |
|
481 |
^ ConcreteClass newTemporaryIn:aDirectoryPrefix |
|
482 |
]. |
|
483 |
||
484 |
"/ care for existing leftOver tempFiles |
|
485 |
"/ from a previous boot of the OS |
|
486 |
"/ (i.e. my pid could be the same as when executed |
|
487 |
"/ the last time before system reboot ...) |
|
488 |
||
489 |
[fn isNil or:[fn exists]] whileTrue:[ |
|
490 |
"/ although the above allows things to be redefined in concrete classes, |
|
491 |
"/ the following should work on all systems ... |
|
492 |
||
493 |
NextTempFilenameIndex isNil ifTrue:[ |
|
494 |
NextTempFilenameIndex := 1. |
|
495 |
]. |
|
496 |
||
497 |
pid := OperatingSystem getProcessId printString. |
|
498 |
nameString := (self tempFileNameTemplate) bindWith:pid with:(NextTempFilenameIndex printString). |
|
499 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
|
500 |
||
501 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
|
502 |
fn := aDirectoryPrefix asFilename construct:nameString |
|
503 |
] ifTrue:[ |
|
504 |
fn := self named:nameString |
|
505 |
] |
|
506 |
]. |
|
507 |
^ fn |
|
508 |
||
509 |
"temp files in '/tmp': |
|
510 |
||
511 |
Filename newTemporary |
|
512 |
" |
|
513 |
||
514 |
"temp files somewhere |
|
515 |
(not recommended - use above since it can be controlled via shell variables): |
|
516 |
||
517 |
UnixFilename newTemporaryIn:'/tmp' |
|
518 |
UnixFilename newTemporaryIn:'/tmp' |
|
519 |
UnixFilename newTemporaryIn:'/usr/tmp' |
|
520 |
UnixFilename newTemporaryIn:'/' |
|
521 |
" |
|
522 |
||
523 |
"a local temp file: |
|
524 |
||
525 |
Filename newTemporaryIn:'' |
|
526 |
Filename newTemporaryIn:nil |
|
527 |
Filename newTemporaryIn:'.' |
|
528 |
Filename newTemporaryIn:('source' asFilename) |
|
529 |
" |
|
530 |
||
531 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
|
532 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
|
533 |
! |
|
534 |
||
4199 | 535 |
nullDevice |
536 |
"return the filename of the nullDevice (if available). |
|
537 |
returns nil, if the OperatingSystem does not support this." |
|
538 |
||
539 |
|s| |
|
540 |
||
541 |
s := OperatingSystem getNullDevice. |
|
542 |
s isNil ifTrue:[ |
|
543 |
^ nil |
|
544 |
]. |
|
545 |
^ self named:s |
|
546 |
||
547 |
" |
|
548 |
Filename nullDevice |
|
549 |
" |
|
550 |
||
551 |
"Created: / 19.5.1999 / 12:24:26 / cg" |
|
552 |
! |
|
553 |
||
3959 | 554 |
rootDirectory |
555 |
"return a filename for the root directory" |
|
556 |
||
557 |
(self ~~ ConcreteClass) ifTrue:[ |
|
558 |
^ ConcreteClass rootDirectory |
|
559 |
]. |
|
560 |
||
561 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
562 |
||
563 |
^ self named:(self separator asString) |
|
564 |
||
565 |
" |
|
566 |
Filename rootDirectory |
|
567 |
" |
|
568 |
||
569 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
570 |
! |
|
571 |
||
572 |
rootDirectoryOnVolume:aVolumeName |
|
573 |
"return a filename for the root directory on some volume" |
|
574 |
||
575 |
(self ~~ ConcreteClass) ifTrue:[ |
|
576 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
|
577 |
]. |
|
578 |
||
579 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
|
580 |
||
581 |
^ self rootDirectory |
|
582 |
||
583 |
" |
|
584 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
|
585 |
Filename rootDirectoryOnVolume:'d:' |
|
586 |
" |
|
587 |
||
588 |
"Modified: / 5.10.1998 / 12:45:39 / cg" |
|
589 |
! |
|
590 |
||
591 |
tempDirectory |
|
592 |
"return the temp directory as a filename. |
|
593 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
|
594 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
595 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
596 |
||
597 |
Notice: do not hardcode '/tmp' into your programs - things may be |
|
598 |
different on other OS's. Also, the user may want to set the |
|
599 |
TMPDIR environment variable to have her temp files somewhere else. |
|
600 |
(especially on SUNOS, the root partition is ALWAYS too small ..." |
|
601 |
||
602 |
|tempDir| |
|
603 |
||
604 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
|
605 |
tempDir isNil ifTrue:[ |
|
606 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
607 |
]. |
|
608 |
]. |
|
609 |
tempDir isNil ifTrue:[ |
|
610 |
tempDir := self defaultTempDirectoryName |
|
611 |
]. |
|
612 |
^ self named:tempDir |
|
613 |
||
614 |
" |
|
615 |
Filename tempDirectory |
|
616 |
Filename tempDirectory pathName |
|
617 |
" |
|
618 |
||
619 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
620 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
621 |
"Modified: 8.9.1997 / 00:08:11 / cg" |
|
622 |
! ! |
|
623 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
624 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
625 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
626 |
concreteClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
627 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
628 |
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
|
629 |
OperatingSystems; concreteClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
630 |
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
|
631 |
|
2906 | 632 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
633 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
634 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 635 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
636 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
637 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
638 |
defaultClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
639 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
640 |
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
|
641 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
642 |
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
|
643 |
|
2906 | 644 |
^ ConcreteClass |
645 |
||
646 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
647 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
648 |
|
2922 | 649 |
!Filename class methodsFor:'misc'! |
650 |
||
651 |
canonicalize:aPathString |
|
3077 | 652 |
"convert the argument, aPathString to a good format. |
653 |
This should eliminate useless directory components (i.e. '././') |
|
654 |
and useless tree walks (i.e. '../foo/..')." |
|
655 |
||
2922 | 656 |
^ aPathString |
657 |
||
3077 | 658 |
"Created: / 13.9.1997 / 10:50:01 / cg" |
659 |
"Modified: / 1.11.1997 / 12:44:57 / cg" |
|
660 |
! |
|
661 |
||
662 |
filterSeps:aFilenameString |
|
663 |
"ST80 compatibility: |
|
664 |
filter out (invalid) separators in aFilenameString. |
|
665 |
We recommend using #makeLegalFilename" |
|
666 |
||
3658 | 667 |
^ aFilenameString copyReplaceAll:(Character space) with:$_. |
3077 | 668 |
|
669 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 670 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 671 |
! |
672 |
||
673 |
suggest:aFilenameString |
|
674 |
"return a fileNamestring based on the argument, |
|
675 |
which is legal on the current platform." |
|
676 |
||
677 |
^ self canonicalize:aFilenameString |
|
678 |
||
679 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 680 |
! ! |
681 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
682 |
!Filename class methodsFor:'queries'! |
2 | 683 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
684 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
685 |
"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
|
686 |
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
|
687 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
688 |
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
|
689 |
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
|
690 |
|
3852 | 691 |
|sep f vol rest components| |
2503 | 692 |
|
2906 | 693 |
(self ~~ ConcreteClass) ifTrue:[ |
694 |
^ ConcreteClass components:aString |
|
695 |
]. |
|
696 |
||
697 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
3852 | 698 |
"/ However, MSDOS drive-letters and network drives are |
699 |
"/ not correctly handled here. |
|
2906 | 700 |
|
2503 | 701 |
sep := self separator. |
3852 | 702 |
f := aString asFilename. |
703 |
vol := f volume. |
|
704 |
vol size ~~ 0 ifTrue:[ |
|
705 |
rest := f localPathName. |
|
706 |
] ifFalse:[ |
|
707 |
rest := aString |
|
708 |
]. |
|
709 |
||
710 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
711 |
components first isEmpty ifTrue:[ |
2906 | 712 |
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
|
713 |
]. |
3852 | 714 |
|
715 |
"/ prepend volume to first component (the root directory) |
|
716 |
vol size ~~ 0 ifTrue:[ |
|
717 |
components at:1 put:(vol , (components at:1)). |
|
718 |
]. |
|
3373 | 719 |
components last isEmpty ifTrue:[ |
720 |
^ components copyWithoutLast:1 |
|
721 |
]. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
722 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
723 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
724 |
" |
3373 | 725 |
Filename components:'/foo/bar/baz' |
3852 | 726 |
Filename components:'/' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
727 |
Filename components:'foo/bar/baz' |
2503 | 728 |
Filename components:'foo/bar' |
729 |
Filename components:'foo' |
|
3852 | 730 |
Filename components:'/foo' |
731 |
||
732 |
Filename components:'\' |
|
733 |
Filename components:'\foo' |
|
734 |
Filename components:'\foo\' |
|
735 |
Filename components:'\foo\bar' |
|
736 |
Filename components:'\foo\bar\' |
|
737 |
Filename components:'c:' |
|
738 |
Filename components:'c:\' |
|
739 |
Filename components:'c:\foo' |
|
740 |
Filename components:'c:\foo\' |
|
741 |
Filename components:'c:\foo\bar' |
|
742 |
Filename components:'c:\foo\bar\' |
|
743 |
Filename components:'\\idefix' |
|
744 |
Filename components:'\\idefix\home' |
|
745 |
Filename components:'\\idefix\home\bar' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
746 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
747 |
|
3852 | 748 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
749 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
750 |
|
2963 | 751 |
directorySuffix |
752 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
753 |
The default is nil here, redefined for VMS" |
|
754 |
||
755 |
(self ~~ ConcreteClass) ifTrue:[ |
|
756 |
^ ConcreteClass directorySuffix |
|
757 |
]. |
|
758 |
||
759 |
^ nil |
|
760 |
! |
|
761 |
||
1523 | 762 |
errorReporter |
763 |
"who knows the signals to report errors?" |
|
764 |
||
765 |
^ FileStream |
|
766 |
||
767 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
768 |
! |
|
769 |
||
440 | 770 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
771 |
"perform filename completion on aString in some directory; |
|
772 |
return the longest matching filename prefix as a string. |
|
1318 | 773 |
The boolean directoriesOnly and filesOnly control respectively, |
774 |
if only directories or only regular files are to be considered for completion. |
|
775 |
If multiple files match, the exception block aBlock is evaluated with a |
|
776 |
filename representing the directory (where the match was done) as argument. |
|
440 | 777 |
(this may be different from the inDirectory argument, if aString is absolute |
778 |
or starts with ../)" |
|
779 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
780 |
|s f matchSet nMatch name words dir isAbsolute sep| |
440 | 781 |
|
2906 | 782 |
(self ~~ ConcreteClass) ifTrue:[ |
783 |
^ ConcreteClass |
|
784 |
filenameCompletionFor:aString |
|
785 |
directory:inDirectory |
|
786 |
directoriesOnly:directoriesOnly |
|
787 |
filesOnly:filesOnly |
|
788 |
ifMultiple:aBlock |
|
789 |
]. |
|
790 |
||
791 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
792 |
||
440 | 793 |
s := aString. |
794 |
" |
|
795 |
find the last word ... |
|
796 |
" |
|
797 |
words := s asCollectionOfWords. |
|
798 |
words size == 0 ifTrue:[ |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
799 |
aBlock value:(self named:'.'). |
2906 | 800 |
^ '' |
440 | 801 |
]. |
802 |
||
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
803 |
f := self named:(words last). |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
804 |
isAbsolute := f isAbsolute. |
440 | 805 |
|
806 |
matchSet := f filenameCompletionIn:inDirectory. |
|
807 |
dir := f directory. |
|
808 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
809 |
matchSet := matchSet select:[:aFilename | |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
810 |
|f isDir| |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
811 |
|
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
812 |
isAbsolute ifTrue:[ |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
813 |
f := aFilename asFilename |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
814 |
] ifFalse:[ |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
815 |
f := (dir construct:aFilename). |
2906 | 816 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
817 |
isDir := f isDirectory. |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
818 |
directoriesOnly ifTrue:[ |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
819 |
isDir |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
820 |
] ifFalse:[ |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
821 |
isDir not |
2906 | 822 |
] |
440 | 823 |
]. |
824 |
||
825 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
2906 | 826 |
" |
827 |
more than one possible completion - |
|
828 |
" |
|
829 |
aBlock value:f |
|
440 | 830 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
831 |
|
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
832 |
sep := self separator. |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
833 |
|
440 | 834 |
" |
835 |
even with more than one possible completion, |
|
836 |
f's name is now the common prefix |
|
837 |
" |
|
838 |
name := f asString. |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
839 |
|
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
840 |
nMatch <= 1 ifTrue:[ |
2906 | 841 |
" |
842 |
exactly one possible completion - |
|
843 |
" |
|
3752 | 844 |
"/ f := dir construct:matchSet first. |
845 |
false "directoriesOnly" ifFalse:[ |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
846 |
(f exists and:[f isDirectory]) ifTrue:[ |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
847 |
(name endsWith:sep) ifFalse:[ |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
848 |
name := name , sep asString |
2906 | 849 |
]. |
850 |
]. |
|
851 |
] |
|
440 | 852 |
]. |
853 |
||
854 |
" |
|
855 |
construct new contents, by taking |
|
856 |
last words completion |
|
857 |
" |
|
858 |
s := ''. |
|
859 |
1 to:(words size - 1) do:[:idx | |
|
2906 | 860 |
s := s , (words at:idx) , ' ' |
440 | 861 |
]. |
862 |
s := s , name. |
|
863 |
||
864 |
"/ special: if there was no change, and the string represented |
|
865 |
"/ is a directories name, add a directory separator |
|
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
866 |
((nMatch == 1) or:[s = aString]) ifTrue:[ |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
867 |
(s endsWith:sep) ifFalse:[ |
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
868 |
(self named:s) isDirectory ifTrue:[ |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
869 |
^ s , sep asString |
2906 | 870 |
] |
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
871 |
]. |
440 | 872 |
]. |
873 |
||
874 |
^ s |
|
1318 | 875 |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
876 |
"Modified: / 30.4.1999 / 09:40:13 / cg" |
615 | 877 |
! |
878 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
879 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
880 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
881 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
882 |
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
|
883 |
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
|
884 |
The returned strings are the expanded names, in the same form |
2550 | 885 |
as given in pattern. |
886 |
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
|
887 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
888 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
889 |
|
2906 | 890 |
(self ~~ ConcreteClass) ifTrue:[ |
891 |
^ ConcreteClass filesMatching:aPattern |
|
892 |
]. |
|
893 |
||
894 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
895 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
896 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
897 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
898 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
899 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
900 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
901 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
902 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
903 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
904 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
905 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
906 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
907 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
908 |
|
2906 | 909 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 910 |
! |
911 |
||
2903 | 912 |
isBadCharacter:aCharacter |
913 |
"return true, if aCharacter is unallowed in a filename." |
|
914 |
||
915 |
|ascii| |
|
916 |
||
2906 | 917 |
(self ~~ ConcreteClass) ifTrue:[ |
918 |
^ ConcreteClass isBadCharacter:aCharacter |
|
919 |
]. |
|
920 |
||
2903 | 921 |
ascii := aCharacter asciiValue. |
922 |
ascii < 32 ifTrue:[ |
|
2906 | 923 |
^ true "/ a control character |
2903 | 924 |
]. |
925 |
ascii == 16rFF ifTrue:[ |
|
2906 | 926 |
^ true "/ delete character |
2903 | 927 |
]. |
928 |
^ false |
|
2906 | 929 |
|
930 |
"Modified: 8.9.1997 / 00:32:59 / cg" |
|
2903 | 931 |
! |
932 |
||
933 |
isCaseSensitive |
|
934 |
"return true, if filenames are case sensitive. |
|
935 |
We ask the OS about this, to be independent here." |
|
936 |
||
2906 | 937 |
(self ~~ ConcreteClass) ifTrue:[ |
938 |
^ ConcreteClass isCaseSensitive |
|
939 |
]. |
|
940 |
||
2903 | 941 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 942 |
|
943 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 944 |
! |
945 |
||
615 | 946 |
localNameStringFrom:aString |
947 |
"ST-80 compatibility. |
|
948 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 949 |
GUESS: |
950 |
does it strip off any volume characters and make a path relative ?" |
|
951 |
||
952 |
|sep| |
|
615 | 953 |
|
2906 | 954 |
(self ~~ ConcreteClass) ifTrue:[ |
955 |
^ ConcreteClass localNameStringFrom:aString |
|
956 |
]. |
|
957 |
||
2922 | 958 |
sep := self separator asString. |
959 |
(aString startsWith:sep) ifTrue:[ |
|
960 |
^ aString copyFrom:sep size + 1 |
|
615 | 961 |
]. |
962 |
^ aString |
|
963 |
||
964 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 965 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 966 |
! |
967 |
||
2908 | 968 |
maxComponentLength |
969 |
"return the maximum number of characters a filename component may |
|
970 |
be in size. This depends on the OperatingSystem." |
|
971 |
||
972 |
(self ~~ ConcreteClass) ifTrue:[ |
|
973 |
^ ConcreteClass maxComponentLength |
|
974 |
]. |
|
975 |
^ OperatingSystem maxFileNameLength |
|
976 |
! |
|
977 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
978 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
979 |
"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
|
980 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
981 |
|
2908 | 982 |
(self ~~ ConcreteClass) ifTrue:[ |
983 |
^ ConcreteClass maxLength |
|
984 |
]. |
|
985 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
986 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
987 |
"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
|
988 |
"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
|
989 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
990 |
|
3171 | 991 |
nullFilename |
992 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
993 |
The default is nil here" |
|
994 |
||
995 |
(self ~~ ConcreteClass) ifTrue:[ |
|
996 |
^ ConcreteClass nullFilename |
|
997 |
]. |
|
998 |
||
999 |
^ nil |
|
1000 |
||
1001 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1002 |
! |
|
1003 |
||
615 | 1004 |
parentDirectoryName |
1005 |
"return the name used for the parent directory. |
|
1006 |
This is '..' for unix and dos-like systems. |
|
1007 |
(there may be more in the future." |
|
1008 |
||
2906 | 1009 |
(self ~~ ConcreteClass) ifTrue:[ |
1010 |
^ ConcreteClass parentDirectoryName |
|
1011 |
]. |
|
1012 |
||
1013 |
^ OperatingSystem parentDirectoryName |
|
1014 |
||
1015 |
" |
|
1016 |
Filename parentDirectoryName |
|
1017 |
" |
|
1018 |
||
1019 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1020 |
! |
1021 |
||
1022 |
separator |
|
1023 |
"return the file/directory separator. |
|
2906 | 1024 |
This is to be redefined in concrete classes; |
1025 |
the following default usually leads to a flat view of |
|
1026 |
the fileSystem (huh - BS2000 ?)" |
|
1027 |
||
1028 |
(self ~~ ConcreteClass) ifTrue:[ |
|
1029 |
^ ConcreteClass separator |
|
1030 |
]. |
|
1031 |
^ $_ |
|
615 | 1032 |
|
1033 |
" |
|
1034 |
Filename separator |
|
1035 |
" |
|
2906 | 1036 |
|
1037 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1038 |
! |
1039 |
||
1040 |
suffixSeparator |
|
1041 |
"return the filename suffix separator. |
|
1042 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 1043 |
(there is currently no known system, where this differs)" |
615 | 1044 |
|
1045 |
^ $. |
|
1046 |
||
1047 |
" |
|
1048 |
Filename suffixSeparator |
|
1049 |
" |
|
1050 |
||
1051 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1052 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1053 |
! |
1054 |
||
2906 | 1055 |
tempFileNameTemplate |
1056 |
"return a template for temporary files. |
|
1057 |
This is expanded with the current processID and a sequenceNumber |
|
1058 |
to generate a unique filename." |
|
1059 |
||
1060 |
(self ~~ ConcreteClass) ifTrue:[ |
|
1061 |
^ ConcreteClass tempFileNameTemplate |
|
1062 |
]. |
|
1063 |
||
1064 |
^ 'stxtmp_%1_%2' |
|
1065 |
||
1066 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1067 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1068 |
! |
|
1069 |
||
615 | 1070 |
volumes |
1071 |
"ST-80 compatibility. |
|
2896 | 1072 |
GUESS: does it return the available drives on MSDOS systems ? |
1073 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1074 |
||
2906 | 1075 |
(self ~~ ConcreteClass) ifTrue:[ |
1076 |
^ ConcreteClass volumes |
|
1077 |
]. |
|
1078 |
||
2896 | 1079 |
^ OperatingSystem getDriveList |
615 | 1080 |
|
1081 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
2906 | 1082 |
"Modified: 8.9.1997 / 00:35:19 / cg" |
615 | 1083 |
! ! |
1084 |
||
1085 |
!Filename methodsFor:'comparing'! |
|
1086 |
||
1087 |
= aFilename |
|
1088 |
"return true, if the argument represents the same filename" |
|
1089 |
||
1090 |
|str| |
|
1091 |
||
1092 |
self species == aFilename species ifTrue:[ |
|
1093 |
str := aFilename asString. |
|
1094 |
self class isCaseSensitive ifTrue:[ |
|
1095 |
^ nameString = str |
|
1096 |
]. |
|
1097 |
^ nameString sameAs:str |
|
1098 |
]. |
|
1099 |
^ false |
|
1100 |
! |
|
1101 |
||
1102 |
hash |
|
1103 |
"return an integer useful as a hash-key" |
|
1104 |
||
1105 |
^ nameString hash |
|
3868 | 1106 |
! |
1107 |
||
1108 |
sameContentsAs:aFilename |
|
1109 |
"return true if the file represented by the receiver has the |
|
1110 |
same contents as the file represented by the argument, aFilename. |
|
1111 |
This compares the files actual contents; not the filenames." |
|
1112 |
||
4979 | 1113 |
|f2 s1 s2 buffer1 buffer2 rslt n| |
1114 |
||
1115 |
f2 := aFilename asFilename. |
|
1116 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
|
3868 | 1117 |
|
1118 |
buffer1 := ByteArray new:8192. |
|
1119 |
buffer2 := ByteArray new:8192. |
|
1120 |
||
1121 |
s1 := self readStream. |
|
1122 |
s1 isNil ifTrue:[ |
|
1123 |
^ self error:('cannot open %1 for reading' bindWith:nameString) |
|
1124 |
]. |
|
4979 | 1125 |
s2 := f2 readStream. |
3868 | 1126 |
s2 isNil ifTrue:[ |
1127 |
^ self error:('cannot open %1 for reading' bindWith:aFilename asFilename name) |
|
1128 |
]. |
|
3869
6d7dca488a41
read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents:
3868
diff
changeset
|
1129 |
s1 binary. |
6d7dca488a41
read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents:
3868
diff
changeset
|
1130 |
s2 binary. |
3868 | 1131 |
|
1132 |
[s1 atEnd] whileFalse:[ |
|
1133 |
n := s1 nextBytes:8192 into:buffer1 startingAt:1. |
|
1134 |
n == 0 ifTrue:[ |
|
1135 |
rslt := s2 atEnd. |
|
1136 |
s1 close. s2 close. |
|
1137 |
^ rslt |
|
1138 |
]. |
|
1139 |
(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[ |
|
1140 |
"/ aFilename shorter |
|
1141 |
s1 close. s2 close. |
|
1142 |
^ false |
|
1143 |
]. |
|
1144 |
buffer1 ~= buffer2 ifTrue:[ |
|
1145 |
s1 close. s2 close. |
|
1146 |
^ false |
|
1147 |
] |
|
1148 |
]. |
|
1149 |
rslt := s2 atEnd. |
|
1150 |
s1 close. s2 close. |
|
1151 |
^ rslt |
|
1152 |
||
1153 |
" |
|
1154 |
'Make.proto' asFilename sameContentsAs:'Makefile' |
|
1155 |
" |
|
615 | 1156 |
! ! |
1157 |
||
1158 |
!Filename methodsFor:'converting'! |
|
1159 |
||
1160 |
asAbsoluteFilename |
|
1161 |
"return the receiver converted to a filename with |
|
1162 |
an absolute pathname." |
|
1163 |
||
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
1164 |
^ self class named:self pathName |
615 | 1165 |
! |
1166 |
||
1167 |
asFilename |
|
1970 | 1168 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 1169 |
|
1170 |
"Thats pretty easy here :-)" |
|
1171 |
^ self |
|
1970 | 1172 |
|
1173 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 1174 |
! |
1175 |
||
1176 |
asString |
|
1177 |
"return the receiver converted to a string" |
|
1178 |
||
1179 |
^ nameString |
|
1180 |
! |
|
1181 |
||
1182 |
makeLegalFilename |
|
1970 | 1183 |
"convert the receivers name to be a legal filename. |
1184 |
This removes/replaces invalid characters and/or compresses |
|
1185 |
the name as required by the OS. |
|
615 | 1186 |
The implementation may change in the future to be more |
1187 |
OS specific." |
|
1188 |
||
1189 |
" |
|
1190 |
actually, in Unix spaces are allowed - but it makes life |
|
1191 |
so hard; therefore, replace them by underscores ... |
|
1192 |
" |
|
3658 | 1193 |
(nameString includes:Character space) ifTrue:[ |
1194 |
nameString := nameString copyReplaceAll:(Character space) with:$_. |
|
1195 |
]. |
|
615 | 1196 |
" |
1197 |
need more - especially on SYS5.3 type systems, |
|
1198 |
we may want to contract the fileName to 14 characters. |
|
1199 |
" |
|
1200 |
^ self |
|
1201 |
||
1202 |
" |
|
1203 |
'hello world' asFilename makeLegalFilename |
|
1204 |
" |
|
1970 | 1205 |
|
3658 | 1206 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1207 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1208 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1209 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1210 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1211 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1212 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1213 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1214 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 1215 |
! ! |
1216 |
||
542 | 1217 |
!Filename methodsFor:'error handling'! |
1218 |
||
615 | 1219 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1220 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1221 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1222 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1223 |
|
4820 | 1224 |
|errNo errString| |
1225 |
||
1226 |
errNo := OperatingSystem lastErrorNumber. |
|
1227 |
errString := OperatingSystem lastErrorString. |
|
1228 |
errString size == 0 ifTrue:[ |
|
1229 |
errString := ''. |
|
1230 |
] ifFalse:[ |
|
1231 |
errString := ' (' , errString , ')' |
|
1232 |
]. |
|
1233 |
||
615 | 1234 |
^ OperatingSystem accessDeniedErrorSignal |
4820 | 1235 |
raiseRequestWith:filename |
1236 |
errorString:('access denied: ' , filename asString , errString) |
|
1237 |
||
1238 |
"Modified: / 26.9.1999 / 16:11:44 / cg" |
|
615 | 1239 |
! |
1240 |
||
1241 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1242 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1243 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1244 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1245 |
|
615 | 1246 |
^ OperatingSystem accessDeniedErrorSignal |
1247 |
raiseRequestWith:filename |
|
1248 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 1249 |
! |
1250 |
||
1251 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1252 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1253 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1254 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1255 |
|
542 | 1256 |
^ OperatingSystem fileNotFoundErrorSignal |
1257 |
raiseRequestWith:filename |
|
1258 |
errorString:('file not found: ' , filename asString) |
|
1259 |
! |
|
1260 |
||
1261 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1262 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1263 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1264 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1265 |
|
542 | 1266 |
^ OperatingSystem accessDeniedErrorSignal |
1267 |
raiseRequestWith:filename |
|
1268 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 1269 |
! |
1270 |
||
1271 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1272 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1273 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1274 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1275 |
|
615 | 1276 |
^ OperatingSystem errorSignal |
1277 |
raiseRequestWith:filename |
|
1278 |
errorString:string |
|
1279 |
! ! |
|
1280 |
||
1281 |
!Filename methodsFor:'file access'! |
|
1282 |
||
3015 | 1283 |
appendStream |
1284 |
"return a stream for appending to the file represented by the receiver. |
|
1285 |
If the file does not already exist, it is created. |
|
1286 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
1287 |
||
1288 |
^ self appendingWriteStream |
|
1289 |
! |
|
1290 |
||
615 | 1291 |
appendingWriteStream |
1292 |
"return a stream for appending to the file represented by the receiver. |
|
1293 |
If the file does not already exist, it is created." |
|
1294 |
||
2947 | 1295 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
615 | 1296 |
! |
1297 |
||
1298 |
newReadWriteStream |
|
1299 |
"return a stream for read/write the file represented by the receiver. |
|
1300 |
If the file does not already exist, it is created." |
|
1301 |
||
2947 | 1302 |
^ FileStream newFileNamed:(self osNameForAccess) |
615 | 1303 |
! |
1304 |
||
1305 |
readStream |
|
1306 |
"return a stream for reading from the file represented by the receiver. |
|
1307 |
If the file does not already exist, nil is returned." |
|
1308 |
||
2947 | 1309 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 1310 |
|
1311 |
" |
|
1312 |
'/tmp/foo' asFilename readStream |
|
1313 |
" |
|
1314 |
! |
|
1315 |
||
1316 |
readWriteStream |
|
1317 |
"return a stream for read/write the file represented by the receiver. |
|
1318 |
If the file does not already exist, nil is returned." |
|
1319 |
||
5208
7cdbf4e22374
oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents:
5200
diff
changeset
|
1320 |
self exists ifTrue:[ |
7cdbf4e22374
oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents:
5200
diff
changeset
|
1321 |
^ FileStream oldFileNamed:(self osNameForAccess) |
7cdbf4e22374
oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents:
5200
diff
changeset
|
1322 |
]. |
7cdbf4e22374
oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents:
5200
diff
changeset
|
1323 |
^ FileStream newFileNamed:(self osNameForAccess) |
615 | 1324 |
! |
1325 |
||
1326 |
writeStream |
|
1327 |
"return a stream for writing to the file represented by the receiver. |
|
1328 |
If the file does not already exist, it is created." |
|
1329 |
||
2947 | 1330 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 1331 |
|
1332 |
" |
|
1333 |
'/tmp/foo' asFilename writeStream |
|
1334 |
" |
|
1335 |
! ! |
|
1336 |
||
1337 |
!Filename methodsFor:'file operations'! |
|
1338 |
||
1339 |
addAccessRights:aCollection |
|
1340 |
"add the access rights as specified in aCollection for the file represented |
|
1341 |
by the receiver. The argument must be a collection of symbols, |
|
1342 |
such as #readUser, #writeGroup etc." |
|
1343 |
||
2922 | 1344 |
|access osName| |
1345 |
||
2947 | 1346 |
osName := self osNameForFile. |
2922 | 1347 |
access := OperatingSystem accessModeOf:osName. |
615 | 1348 |
aCollection do:[:accessSymbol | |
1349 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
1350 |
]. |
|
2922 | 1351 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1352 |
^ self accessDeniedError:self |
1353 |
] |
|
1354 |
||
1355 |
" |
|
1356 |
'foo' asFilename writeStream close. |
|
1357 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
1358 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
1359 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
1360 |
" |
|
1361 |
! |
|
1362 |
||
2982 | 1363 |
basicMakeDirectory |
1364 |
"create a directory with the receivers name. |
|
1365 |
Return true if successful, false if not." |
|
1366 |
||
1367 |
^ OperatingSystem createDirectory:(self osNameForDirectory) |
|
1368 |
! |
|
1369 |
||
615 | 1370 |
copyTo:newName |
1371 |
"copy the file - the argument must be convertable to a filename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1372 |
Raises an exception, if an error occurs." |
615 | 1373 |
|
1374 |
|inStream outStream buffer bufferSize count newFile| |
|
1375 |
||
4324 | 1376 |
OperatingSystem isMSDOSlike ifTrue:[ |
1377 |
"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ? |
|
1378 |
bufferSize := 1 * 1024. |
|
1379 |
] ifFalse:[ |
|
1380 |
bufferSize := 8 * 1024. |
|
1381 |
]. |
|
1382 |
||
615 | 1383 |
buffer := ByteArray new:bufferSize. |
1384 |
inStream := self readStream. |
|
1385 |
inStream isNil ifTrue:[ |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1386 |
^ self fileNotFoundError:self |
615 | 1387 |
]. |
1388 |
||
1389 |
outStream := (newFile := newName asFilename) writeStream. |
|
1390 |
outStream isNil ifTrue:[ |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1391 |
inStream close. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1392 |
^ self fileCreationError:newFile |
615 | 1393 |
]. |
1394 |
||
1395 |
[inStream atEnd] whileFalse:[ |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1396 |
count := inStream nextBytes:bufferSize into:buffer. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1397 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1398 |
inStream close. |
5134 | 1399 |
outStream close. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1400 |
^ self fileCreationError:newFile |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1401 |
] |
615 | 1402 |
]. |
1403 |
outStream close. |
|
1404 |
inStream close. |
|
1405 |
||
1406 |
" |
|
1407 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
1408 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
1409 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1410 |
|
5134 | 1411 |
"Modified: / 23.12.1999 / 21:52:36 / cg" |
615 | 1412 |
! |
1413 |
||
1414 |
delete |
|
1415 |
"remove the file - same as remove, for ST-80 compatibility" |
|
1416 |
||
1417 |
self remove |
|
1418 |
! |
|
1419 |
||
1420 |
makeDirectory |
|
1421 |
"create a directory with the receivers name. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1422 |
Raises an exception if not successful" |
615 | 1423 |
|
2982 | 1424 |
(self basicMakeDirectory) ifFalse:[ |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1425 |
"/ |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1426 |
"/ could have existed before ... |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1427 |
"/ |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1428 |
(self exists and:[self isDirectory]) ifFalse:[ |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1429 |
self fileCreationError:self. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1430 |
^ false |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1431 |
] |
2982 | 1432 |
]. |
1433 |
^ true |
|
1970 | 1434 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1435 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 1436 |
! |
1437 |
||
844 | 1438 |
makeExecutable |
1439 |
"make the file executable - you must have permission to do so. |
|
1440 |
For directories, execution means: 'allow changing into it'" |
|
1441 |
||
1442 |
^ self addAccessRights:#(executeUser) |
|
1443 |
||
1444 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
1445 |
! |
|
1446 |
||
1447 |
makeExecutableForAll |
|
1448 |
"make the file executable for all - you must have permission to do so. |
|
1449 |
For directories, execution means: 'allow changing into it'" |
|
1450 |
||
1451 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
1452 |
||
1453 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
1454 |
! |
|
1455 |
||
4901 | 1456 |
makeExecutableForGroup |
1457 |
"make the file executable for the group - you must have permission to do so. |
|
1458 |
For directories, execution means: 'allow changing into it'" |
|
1459 |
||
1460 |
^ self addAccessRights:#(executeGroup) |
|
1461 |
||
1462 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
1463 |
! |
|
1464 |
||
615 | 1465 |
makeReadable |
1466 |
"make the file readable for the owner - you must have permission to do so." |
|
1467 |
||
1468 |
^ self addAccessRights:#(readUser) |
|
1469 |
! |
|
1470 |
||
1471 |
makeReadableForAll |
|
1472 |
"make the file readable for all - you must have permission to do so." |
|
1473 |
||
1474 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
1475 |
! |
|
1476 |
||
4901 | 1477 |
makeReadableForGroup |
1478 |
"make the file readable for the group - you must have permission to do so." |
|
1479 |
||
1480 |
^ self addAccessRights:#(readGroup) |
|
1481 |
! |
|
1482 |
||
615 | 1483 |
makeUnwritable |
1484 |
"make the file unwritable for all - you must have permission to do so." |
|
1485 |
||
1486 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
1487 |
! |
|
1488 |
||
1489 |
makeWritable |
|
1490 |
"make the file writableable for all - you must have permission to do so." |
|
1491 |
||
1492 |
^ self addAccessRights:#(writeUser) |
|
1493 |
! |
|
1494 |
||
1495 |
makeWritableForAll |
|
1496 |
"make the file writable for all - you must have permission to do so." |
|
1497 |
||
1498 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
1499 |
! |
|
1500 |
||
4901 | 1501 |
makeWritableForGroup |
1502 |
"make the file writable for the group - you must have permission to do so." |
|
1503 |
||
1504 |
^ self addAccessRights:#(writeGroup) |
|
1505 |
! |
|
1506 |
||
615 | 1507 |
moveTo:newName |
1508 |
"copy the file represented by the receiver, then delete it. |
|
1509 |
This is different to renaming in case of cross device moves. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1510 |
Raise an exception if not successful." |
615 | 1511 |
|
1512 |
self copyTo:newName. |
|
1513 |
self remove |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1514 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1515 |
"Modified: / 5.5.1999 / 13:37:44 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1516 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1517 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1518 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1519 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1520 |
Otherwise, copy the directory and recursively |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1521 |
and recursively all of its subfiles/subdirectories. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1522 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1523 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1524 |
|ok d| |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1525 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1526 |
self isDirectory ifFalse:[ |
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1527 |
d := destination asFilename. |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1528 |
(d exists and:[d isDirectory]) ifTrue:[ |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1529 |
d := d construct:self baseName. |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1530 |
]. |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1531 |
^ self copyTo:d |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1532 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1533 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1534 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1535 |
"/ however, if the command fails (or the OS does not support it), |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1536 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1537 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1538 |
ok := OperatingSystem |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1539 |
recursiveCopyDirectory:(self osNameForDirectory) |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1540 |
to:(destination asFilename osNameForDirectory). |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1541 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1542 |
ok ifFalse:[ |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1543 |
self recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1544 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1545 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1546 |
"Created: / 5.5.1999 / 13:35:01 / cg" |
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1547 |
"Modified: / 31.5.1999 / 13:11:34 / cg" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1548 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1549 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1550 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1551 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1552 |
Otherwise, copy the directory and all of its subfiles/subdirectories. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1553 |
This one walks down the directory hierarchy, not using any OS |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1554 |
command to do the copy. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1555 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1556 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1557 |
|destinationFilename d| |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1558 |
|
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1559 |
d := destination asFilename. |
4246 | 1560 |
"/ (d exists and:[d isDirectory]) ifTrue:[ |
1561 |
"/ d := d construct:self baseName. |
|
1562 |
"/ ]. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1563 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1564 |
self isDirectory ifTrue:[ |
4246 | 1565 |
destinationFilename := d asFilename construct:self baseName. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1566 |
destinationFilename makeDirectory. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1567 |
self directoryContents do:[:aFilenameString | |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1568 |
|src dst| |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1569 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1570 |
src := self construct:aFilenameString. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1571 |
src isDirectory ifTrue:[ |
4246 | 1572 |
src recursiveCopyWithoutOSCommandTo:destinationFilename |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1573 |
] ifFalse:[ |
4246 | 1574 |
src copyTo:(destinationFilename construct:aFilenameString) |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1575 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1576 |
] |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1577 |
] ifFalse:[ |
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
1578 |
self copyTo:d |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1579 |
] |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1580 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1581 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1582 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1583 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1584 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1585 |
|
4246 | 1586 |
"Modified: / 31.5.1999 / 18:12:31 / cg" |
615 | 1587 |
! |
1588 |
||
659 | 1589 |
recursiveMakeDirectory |
1590 |
"create a directory with the receivers name and all required intermediate |
|
1591 |
directories. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1592 |
Raises an exception if not successful." |
659 | 1593 |
|
2922 | 1594 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1595 |
^ self fileCreationError:self |
659 | 1596 |
] |
1597 |
||
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1598 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1599 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
659 | 1600 |
! |
1601 |
||
615 | 1602 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1603 |
"if I represent a regular file, remove it. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1604 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1605 |
Raise an exception if not successful." |
615 | 1606 |
|
1607 |
|ok| |
|
1608 |
||
3302 | 1609 |
"/ typically, an 'rm -rf' is faster and removes better; |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1610 |
"/ however, if the command fails (or the OS does not support it), |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1611 |
"/ fallBack doing a manual directory walk. |
3302 | 1612 |
|
1613 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
1614 |
ok ifFalse:[ |
|
1615 |
self recursiveRemoveWithoutOSCommand |
|
1616 |
]. |
|
1617 |
||
1618 |
" |
|
1619 |
'foo' asFilename makeDirectory. |
|
1620 |
'foo/bar' asFilename writeStream close. |
|
1621 |
('foo' asFilename remove) ifFalse:[ |
|
1622 |
Transcript showCR:'could not remove foo' |
|
1623 |
] |
|
1624 |
" |
|
1625 |
" |
|
1626 |
'foo' asFilename makeDirectory. |
|
1627 |
'foo/bar' asFilename writeStream close. |
|
1628 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
1629 |
Transcript showCR:'could not remove foo' |
|
1630 |
] |
|
1631 |
" |
|
1632 |
||
1633 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1634 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 1635 |
! |
1636 |
||
1637 |
recursiveRemoveWithoutOSCommand |
|
1638 |
"if I represent a regular file, remove it. |
|
1639 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
1640 |
Raise an error if not successful. |
|
1641 |
This one walks down the directory hierarchy, not using any OS |
|
1642 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1643 |
|
4939 | 1644 |
|files| |
1645 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1646 |
self isDirectory ifTrue:[ |
4939 | 1647 |
(files := self directoryContents) size > 0 ifTrue:[ |
1648 |
files do:[:aFilenameString | |
|
1649 |
|f| |
|
1650 |
||
1651 |
f := self construct:aFilenameString. |
|
1652 |
f isDirectory ifTrue:[ |
|
1653 |
f recursiveRemoveWithoutOSCommand |
|
1654 |
] ifFalse:[ |
|
1655 |
f remove |
|
1656 |
]. |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1657 |
]. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1658 |
] |
615 | 1659 |
]. |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1660 |
self remove |
615 | 1661 |
|
1662 |
" |
|
1663 |
'foo' asFilename makeDirectory. |
|
1664 |
'foo/bar' asFilename writeStream close. |
|
4940 | 1665 |
'foo' asFilename remove |
615 | 1666 |
" |
1667 |
" |
|
1668 |
'foo' asFilename makeDirectory. |
|
1669 |
'foo/bar' asFilename writeStream close. |
|
4940 | 1670 |
'foo' asFilename recursiveRemove |
615 | 1671 |
" |
1672 |
||
3302 | 1673 |
"Created: / 25.2.1998 / 19:50:40 / cg" |
1674 |
"Modified: / 25.2.1998 / 19:52:08 / cg" |
|
615 | 1675 |
! |
1676 |
||
1677 |
remove |
|
845 | 1678 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1679 |
Raises an exception if not successful. |
845 | 1680 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 1681 |
|
1682 |
|ok| |
|
1683 |
||
1684 |
self exists ifFalse:[ ^ self]. |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1685 |
(self isSymbolicLink not and:[self isDirectory]) ifTrue:[ |
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1686 |
ok := OperatingSystem removeDirectory:(self osNameForFile) |
615 | 1687 |
] ifFalse:[ |
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1688 |
ok := OperatingSystem removeFile:(self osNameForFile) |
615 | 1689 |
]. |
1690 |
ok ifFalse:[ |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1691 |
self removeError:self |
615 | 1692 |
]. |
1693 |
||
1694 |
" |
|
1695 |
(FileStream newFileNamed:'foo') close. |
|
1696 |
'foo' asFilename remove |
|
1697 |
" |
|
1698 |
||
1699 |
" |
|
1700 |
'foo' asFilename makeDirectory. |
|
1701 |
'foo/bar' asFilename writeStream close. |
|
1702 |
('foo' asFilename remove) ifFalse:[ |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1703 |
Transcript showCR:'could not remove foo' |
615 | 1704 |
] |
1705 |
" |
|
1706 |
||
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1707 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1708 |
"Modified: / 5.5.1999 / 13:41:12 / cg" |
615 | 1709 |
! |
1710 |
||
1711 |
removeAccessRights:aCollection |
|
1712 |
"remove the access rights as specified in aCollection for the file represented |
|
1713 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 1714 |
such as #readUser, #writeGroup etc. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1715 |
Raises an exception if not successful." |
615 | 1716 |
|
2922 | 1717 |
|access osName| |
1718 |
||
2947 | 1719 |
osName := self osNameForFile. |
2922 | 1720 |
access := OperatingSystem accessModeOf:osName. |
615 | 1721 |
aCollection do:[:accessSymbol | |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1722 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
615 | 1723 |
]. |
2922 | 1724 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1725 |
^ self accessDeniedError:self |
615 | 1726 |
]. |
1727 |
||
1728 |
" |
|
1729 |
'foo' asFilename writeStream close. |
|
1730 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
1731 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
1732 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
1733 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1734 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1735 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
615 | 1736 |
! |
1737 |
||
5086 | 1738 |
renameOrCopyTo:newName |
1739 |
"rename or copy the file - the argument must be convertable to a String. |
|
1740 |
Raises an exception if not successful. |
|
1741 |
This does basically the same as #renameTo:, with one exception: |
|
1742 |
if, under unix, the new fileName is on another device, a rename operation |
|
1743 |
fails, and #renameTo: raises an exception; |
|
1744 |
in contrast, this method falls back to copying the file." |
|
1745 |
||
1746 |
|newFilename| |
|
1747 |
||
1748 |
newFilename := newName asFilename. |
|
1749 |
||
1750 |
(OperatingSystem |
|
1751 |
renameFile:(self osNameForFile) |
|
1752 |
to:(newFilename osNameForFile) |
|
1753 |
) ifFalse:[ |
|
1754 |
self exists ifFalse:[ |
|
1755 |
^ self fileNotFoundError:self |
|
1756 |
]. |
|
1757 |
||
1758 |
OperatingSystem isUNIXlike ifTrue:[ |
|
1759 |
OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[ |
|
1760 |
"/ try to copy - and remove the original |
|
1761 |
"/ this helps with cross-device renames. |
|
1762 |
||
1763 |
self copyTo:newName. |
|
1764 |
^ self |
|
1765 |
]. |
|
1766 |
]. |
|
1767 |
^ self accessDeniedError:newName asFilename. |
|
1768 |
]. |
|
1769 |
||
1770 |
" |
|
1771 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1772 |
" |
|
1773 |
||
1774 |
"Modified: / 5.5.1999 / 13:41:27 / cg" |
|
1775 |
! |
|
1776 |
||
615 | 1777 |
renameTo:newName |
671 | 1778 |
"rename the file - the argument must be convertable to a String. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1779 |
Raises an exception if not successful." |
615 | 1780 |
|
2922 | 1781 |
(OperatingSystem |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1782 |
renameFile:(self osNameForFile) |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1783 |
to:(newName asFilename osNameForFile) |
2922 | 1784 |
) ifFalse:[ |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1785 |
self exists ifFalse:[ |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1786 |
^ self fileNotFoundError:self |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1787 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1788 |
^ self accessDeniedError:newName asFilename. |
615 | 1789 |
]. |
1790 |
||
1791 |
" |
|
1792 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1793 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1794 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1795 |
"Modified: / 5.5.1999 / 13:41:27 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1796 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1797 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1798 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1799 |
"change the files size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1800 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1801 |
(raises an exception, if not)" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1802 |
|
2922 | 1803 |
(OperatingSystem truncateFile:(self osNameForFile) to:newSize) ifFalse:[ |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1804 |
^ 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
|
1805 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1806 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1807 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1808 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1809 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1810 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1811 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1812 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1813 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1814 |
'test' asFilename truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1815 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1816 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1817 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
1818 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 1819 |
! ! |
1820 |
||
1821 |
!Filename methodsFor:'file queries'! |
|
1822 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1823 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1824 |
"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
|
1825 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1826 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1827 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1828 |
(i := self info) isNil ifTrue:[^ nil]. |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1829 |
^ i accessed |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1830 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1831 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1832 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1833 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1834 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1835 |
"Created: / 9.7.1996 / 10:19:15 / cg" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1836 |
"Modified: / 26.9.1997 / 13:05:51 / stefan" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1837 |
"Modified: / 17.8.1998 / 10:23:44 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1838 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1839 |
|
615 | 1840 |
dates |
1841 |
"return the files modification and access times as an object (currently a dictionary) |
|
1842 |
that responds to the at: message with arguments |
|
1843 |
#modified, #accessed or #statusChanged." |
|
1844 |
||
2922 | 1845 |
|info dates osName| |
1846 |
||
2947 | 1847 |
osName := self osNameForAccess. |
2922 | 1848 |
info := OperatingSystem infoOf:osName. |
615 | 1849 |
info isNil ifTrue:[ |
2922 | 1850 |
info := OperatingSystem linkInfoOf:osName. |
2629 | 1851 |
info isNil ifTrue:[ |
1852 |
^ nil |
|
1853 |
] |
|
615 | 1854 |
]. |
1855 |
dates := IdentityDictionary new. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1856 |
dates at:#modified put:(info modified). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1857 |
dates at:#accessed put:(info accessed). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1858 |
dates at:#statusChanged put:(info statusChanged). |
615 | 1859 |
^ dates |
1860 |
||
1861 |
" |
|
1862 |
Filename currentDirectory dates |
|
1863 |
'../regression' asFilename dates |
|
1864 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1865 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1866 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 1867 |
! |
1868 |
||
1869 |
fileSize |
|
1870 |
"return the size of the file in bytes" |
|
1871 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1872 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1873 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1874 |
(i := self info) isNil ifTrue:[^ nil]. |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1875 |
^ i size |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1876 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1877 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 1878 |
! |
1879 |
||
1880 |
fileType |
|
1881 |
"this returns a string describing the type of contents of |
|
1882 |
the file. This is done using the unix 'file' command, |
|
1883 |
(which usually is configurable by /etc/magic). |
|
3665 | 1884 |
On non-unix systems, this may simply return 'file', |
2922 | 1885 |
not knowning about the contents. |
1886 |
Warning: |
|
1887 |
Since the returned string differs among systems (and language settings), |
|
3665 | 1888 |
it is only useful for user-information; |
1889 |
NOT as a tag to be used by a program." |
|
1890 |
||
1891 |
|type buffer s n suffix idx baseNm| |
|
1892 |
||
1893 |
"/ since we cannot depend on a 'file' command being available, |
|
1894 |
"/ do the most obvious ones here. |
|
1895 |
"/ (also useful since the 'file' command takes some time, and the code |
|
1896 |
"/ below is faster for common things like directories) |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1897 |
|
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1898 |
self isSymbolicLink ifTrue:[ |
2906 | 1899 |
^ 'symbolic link to ' , (self linkInfo path) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1900 |
]. |
2573 | 1901 |
self isDirectory ifTrue:[ |
2906 | 1902 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
1903 |
self isExecutable ifFalse:[^ 'directory, locked']. |
|
1904 |
^ 'directory' |
|
2573 | 1905 |
]. |
3665 | 1906 |
(type := self type) == #characterSpecial ifTrue:[ |
1907 |
^ 'character device special file' |
|
1908 |
]. |
|
1909 |
type == #blockSpecial ifTrue:[ |
|
1910 |
^ 'block device special file' |
|
1911 |
]. |
|
1912 |
type == #socket ifTrue:[ |
|
1913 |
^ 'socket' |
|
1914 |
]. |
|
1915 |
||
1602 | 1916 |
self isReadable ifFalse:[^ 'unreadable']. |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1917 |
self fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 1918 |
|
2922 | 1919 |
suffix := self suffix asLowercase. |
1920 |
baseNm := self withoutSuffix baseName asLowercase. |
|
1921 |
||
1922 |
((#('st' 'rc' 'chg' 'htm' 'html' 'ps') includes:suffix) |
|
1923 |
or:[#('makefile') includes:baseNm]) ifTrue:[ |
|
1924 |
||
1925 |
buffer := String new:2024. |
|
1926 |
s := self readStream. |
|
1927 |
s notNil ifTrue:[ |
|
1928 |
n := s nextBytes:buffer size into:buffer. |
|
1929 |
s close. |
|
1930 |
||
1931 |
(suffix = 'st') ifTrue:[ |
|
2906 | 1932 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
1933 |
^ 'smalltalk source' |
|
1934 |
]. |
|
1935 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1936 |
^ 'smalltalk source' |
|
1937 |
]. |
|
1938 |
]. |
|
1939 |
||
1940 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1941 |
^ 'smalltalk changes / method source' |
|
1942 |
]. |
|
1943 |
||
1944 |
(suffix = 'rc') ifTrue:[ |
|
1945 |
(buffer findString:'ST/X startup') ~~ 0 ifTrue:[ |
|
1946 |
^ 'smalltalk startup script' |
|
1947 |
]. |
|
1948 |
]. |
|
2922 | 1949 |
|
2906 | 1950 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
1951 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
|
1952 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
|
1953 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
|
1954 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
|
1955 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
|
1956 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
|
1957 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
|
1958 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
|
1959 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
|
1960 |
ifTrue:[ |
|
1961 |
^ 'HTML document text' |
|
1962 |
] |
|
1963 |
]. |
|
1964 |
]. |
|
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1965 |
|
2906 | 1966 |
(suffix = 'ps') ifTrue:[ |
1967 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
|
1968 |
^ 'PostScript document' |
|
1969 |
]. |
|
1970 |
]. |
|
1971 |
||
1972 |
(baseNm = 'makefile') ifTrue:[ |
|
1973 |
(buffer startsWith:'#') ifTrue:[ |
|
1974 |
^ 'make rules' |
|
1975 |
] |
|
3665 | 1976 |
] |
2906 | 1977 |
] |
1602 | 1978 |
]. |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1979 |
|
2906 | 1980 |
^ 'file' |
615 | 1981 |
|
1982 |
" |
|
1983 |
'Makefile' asFilename fileType |
|
1984 |
'.' asFilename fileType |
|
3665 | 1985 |
'/dev/null' asFilename fileType |
1986 |
'/tmp/.X11-unix/X0' asFilename fileType |
|
615 | 1987 |
'smalltalk.rc' asFilename fileType |
1988 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
1989 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1990 |
|
3665 | 1991 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 1992 |
! |
1993 |
||
2836 | 1994 |
id |
1995 |
"return the files/directories file-id (inode number)" |
|
1996 |
||
2947 | 1997 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 1998 |
|
1999 |
" |
|
2000 |
Filename currentDirectory id |
|
2001 |
" |
|
2002 |
||
2003 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
2004 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
2005 |
! |
|
2006 |
||
615 | 2007 |
info |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2008 |
"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
|
2009 |
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
|
2010 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2011 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2012 |
type - a symbol giving the files fileType |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2013 |
mode - numeric access mode |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2014 |
uid - owners user id |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2015 |
gid - owners group id |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2016 |
size - files size |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2017 |
id - files number (i.e. inode number) |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2018 |
accessed - last access time (as osTime-stamp) |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2019 |
modified - last modification time (as osTime-stamp) |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2020 |
statusChanged - last staus change (as osTime-stamp) |
615 | 2021 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2022 |
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
|
2023 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2024 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2025 |
modified |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2026 |
size |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2027 |
type |
615 | 2028 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2029 |
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
|
2030 |
to either handle nil values, |
615 | 2031 |
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
|
2032 |
(i.e. instead of: |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2033 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2034 |
use |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2035 |
someFilename isDirectory |
615 | 2036 |
" |
2037 |
||
2947 | 2038 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 2039 |
|
2040 |
" |
|
2041 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2042 |
'/dev/null' asFilename info |
615 | 2043 |
'Make.proto' asFilename info |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2044 |
'source/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2045 |
'source/Point.st' asFilename linkInfo |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2046 |
'../../libbasic/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2047 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2048 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2049 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2050 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2051 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2052 |
'c:\' asFilename info |
615 | 2053 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2054 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
2055 |
"Modified: / 17.8.1998 / 10:24:10 / cg" |
615 | 2056 |
! |
2057 |
||
2058 |
linkInfo |
|
2059 |
"return the files info if its a symbolic link; nil otherwise. |
|
2060 |
On OS's which do not support symbolic links, nil is always returned. |
|
2061 |
The information is the same as returned by #info, except that if the |
|
2062 |
receiver represents a symbolic link, the links information |
|
2063 |
is returned |
|
2064 |
(while in this case, #info returns the info of the target file, |
|
2065 |
which is accessed via the symbolic link). |
|
2066 |
||
2067 |
In addition to the normal entries, Unix returns an additional entry: |
|
2629 | 2068 |
path -> the target files pathname |
615 | 2069 |
|
2070 |
See the comment in #info for more details." |
|
2071 |
||
2947 | 2072 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 2073 |
|
2074 |
" |
|
2075 |
Filename currentDirectory linkInfo |
|
2076 |
'/dev/null' asFilename linkInfo |
|
2077 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
2078 |
'Make.proto' asFilename linkInfo path |
615 | 2079 |
'source/Point.st' asFilename linkInfo |
2080 |
'../../libbasic/Point.st' asFilename linkInfo |
|
2081 |
" |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
2082 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
2083 |
"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
|
2084 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2085 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2086 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2087 |
"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
|
2088 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2089 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2090 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2091 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2092 |
^ i modified |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2093 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2094 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2095 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2096 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
2097 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2098 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2099 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2100 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 2101 |
! |
2102 |
||
2103 |
type |
|
2104 |
"return the symbolic type of the file" |
|
2105 |
||
2947 | 2106 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 2107 |
|
2108 |
" |
|
2109 |
Filename currentDirectory type |
|
2110 |
" |
|
2111 |
||
2112 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
2113 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 2114 |
! ! |
2115 |
||
2116 |
!Filename methodsFor:'file utilities'! |
|
2117 |
||
2118 |
edit |
|
2119 |
"start an editView on the file represented by the receiver" |
|
2120 |
||
2121 |
EditTextView openOn:self asString |
|
2122 |
||
2123 |
" |
|
2124 |
'smalltalk.rc' asFilename edit |
|
2125 |
" |
|
2126 |
! |
|
2127 |
||
2128 |
fileIn |
|
2129 |
"load smalltalk code from the file" |
|
2130 |
||
5200 | 2131 |
|s rslt| |
2132 |
||
2133 |
s := self readStream. |
|
2134 |
[ |
|
2135 |
rslt := s fileIn. |
|
2136 |
] valueNowOrOnUnwindDo:[ |
|
2137 |
s close. |
|
2138 |
]. |
|
2139 |
^ rslt. |
|
542 | 2140 |
! ! |
2141 |
||
2 | 2142 |
!Filename methodsFor:'instance creation'! |
2143 |
||
615 | 2144 |
construct:subname |
2145 |
"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
|
2146 |
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
|
2147 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 2148 |
The argument may not specify an absolute path name. |
2149 |
Please do not use this to create filenames with suffixes, |
|
2150 |
since some systems require special naming conventions. |
|
2151 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 2152 |
|
2903 | 2153 |
^ self class named:(self constructString:subname) |
615 | 2154 |
|
2155 |
" |
|
2156 |
'/tmp' asFilename construct:'foo' |
|
2157 |
'/' asFilename construct:'foo' |
|
2158 |
'/usr/tmp' asFilename construct:'foo' |
|
2159 |
'/foo/bar' asFilename construct:'baz' |
|
2922 | 2160 |
|
2161 |
Bad example; works on UNIX, but may not on others: |
|
2162 |
'foo/bar.baz' construct:'.suff' |
|
615 | 2163 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2164 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2165 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 2166 |
! |
2167 |
||
2922 | 2168 |
constructDirectory:subname |
2169 |
"same as #construct: on most systems. |
|
2170 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
2171 |
||
2172 |
^ self class named:(self constructDirectoryString:subname) |
|
2173 |
! |
|
2174 |
||
2175 |
constructDirectoryString:subName |
|
2176 |
"same as #constructString: on most systems. |
|
2177 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
2178 |
||
2179 |
^ self constructString:subName |
|
2180 |
! |
|
2181 |
||
2182 |
constructString:subName |
|
2911 | 2183 |
"taking the receiver as a directory name, construct a new |
2184 |
filename-string for an entry within this directory |
|
2922 | 2185 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 2186 |
The argument may not specify an absolute path name. |
2187 |
The code below works for UNIX & MSDOS; |
|
2188 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
2189 |
||
2190 |
|sepString sub| |
|
2191 |
||
2192 |
sub := subName asString. |
|
2911 | 2193 |
sepString := self class separator asString. |
2194 |
nameString = sepString ifTrue:[ |
|
2195 |
"I am the root" |
|
2960 | 2196 |
^ sepString , sub |
2911 | 2197 |
]. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2198 |
(nameString endsWith:sepString) ifTrue:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2199 |
^ nameString , sub |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2200 |
]. |
2960 | 2201 |
^ nameString , sepString , sub |
2911 | 2202 |
|
2203 |
" |
|
2204 |
'/tmp' asFilename constructString:'foo' |
|
2205 |
'/' asFilename constructString:'foo' |
|
2206 |
'/usr/tmp' asFilename constructString:'foo' |
|
2207 |
'/foo/bar' asFilename constructString:'baz' |
|
2208 |
" |
|
2209 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2210 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2211 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2212 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2213 |
"Modified: / 27.7.1998 / 19:47:51 / cg" |
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2214 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2215 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2216 |
filenameFor:fileName |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2217 |
"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
|
2218 |
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
|
2219 |
(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
|
2220 |
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
|
2221 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2222 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2223 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2224 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2225 |
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
|
2226 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2227 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2228 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2229 |
'/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
|
2230 |
'/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
|
2231 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2232 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2233 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
2 | 2234 |
! ! |
2235 |
||
195 | 2236 |
!Filename methodsFor:'misc'! |
2237 |
||
2238 |
, aString |
|
2239 |
"this allows filenames to understand how names are concatenated. |
|
308 | 2240 |
Returns a string consisting of the receivers name, concatenated |
195 | 2241 |
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
|
2242 |
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
|
2243 |
See also: #withSuffix: which is new and better." |
195 | 2244 |
|
2906 | 2245 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 2246 |
^ (nameString , aString asString) |
195 | 2247 |
|
2248 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2249 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2250 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2251 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2252 |
'Makefile' asFilename construct:'.bak' |
195 | 2253 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2254 |
|
2906 | 2255 |
"Modified: 7.9.1997 / 23:45:36 / cg" |
195 | 2256 |
! ! |
2257 |
||
615 | 2258 |
!Filename methodsFor:'printing & storing'! |
174 | 2259 |
|
615 | 2260 |
printOn:aStream |
4392 | 2261 |
"append a user printed representation of the receiver to aStream. |
2262 |
The format is suitable for a human - not meant to be read back." |
|
174 | 2263 |
|
2906 | 2264 |
aStream nextPutAll:(self class name). |
2265 |
aStream nextPutAll:'('''. |
|
615 | 2266 |
nameString printOn:aStream. |
2267 |
aStream nextPutAll:''')' |
|
2906 | 2268 |
|
2269 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 2270 |
! |
2271 |
||
615 | 2272 |
storeOn:aStream |
2273 |
"append a printed representation of the receiver to aStream, |
|
2274 |
which allows reconstructing it via readFrom:" |
|
328 | 2275 |
|
615 | 2276 |
aStream nextPut:$(. |
2277 |
nameString storeOn:aStream. |
|
2278 |
aStream nextPutAll:' asFilename)' |
|
1 | 2279 |
! ! |
2280 |
||
202 | 2281 |
!Filename methodsFor:'private accessing'! |
1 | 2282 |
|
68 | 2283 |
setName:aString |
38 | 2284 |
"set the filename" |
2285 |
||
3666 | 2286 |
nameString := self nameWithSpecialExpansions:aString. |
2287 |
||
2288 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 2289 |
! ! |
2290 |
||
2 | 2291 |
!Filename methodsFor:'queries'! |
2292 |
||
615 | 2293 |
canBeWritten |
2294 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 2295 |
|
615 | 2296 |
^ self isWritable |
92 | 2297 |
|
328 | 2298 |
" |
615 | 2299 |
'/foo/bar' asFilename canBeWritten |
2300 |
'/tmp' asFilename canBeWritten |
|
2301 |
'Makefile' asFilename canBeWritten |
|
328 | 2302 |
" |
2303 |
! |
|
2304 |
||
68 | 2305 |
exists |
92 | 2306 |
"return true, if such a file exists." |
68 | 2307 |
|
2947 | 2308 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 2309 |
|
85 | 2310 |
" |
92 | 2311 |
'/foo/bar' asFilename exists |
2312 |
'/tmp' asFilename exists |
|
2313 |
'Makefile' asFilename exists |
|
85 | 2314 |
" |
77 | 2315 |
! |
2316 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2317 |
filesMatching:aPattern |
2550 | 2318 |
"given the receiver, representing a directory; |
2319 |
return a collection of files matching a pattern. |
|
2320 |
The pattern may be a simple matchPattern, or a set of |
|
2321 |
multiple patterns separated by semicolons." |
|
2322 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2323 |
|matchers notCaseSensitive| |
2550 | 2324 |
|
2325 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2326 |
notCaseSensitive := self class isCaseSensitive not. |
2550 | 2327 |
^ self directoryContents |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2328 |
select:[:name | |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2329 |
(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0 |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2330 |
] |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2331 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2332 |
" |
2550 | 2333 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2334 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2335 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2336 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2337 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 2338 |
! |
2339 |
||
2340 |
filesMatchingWithoutDotDirs:aPattern |
|
2341 |
"given the receiver, representing a directory; |
|
2342 |
return a collection of files matching a pattern. |
|
2343 |
Exclude '.' and '..' from the returned list. |
|
2344 |
The pattern may be a simple matchPattern, or a set of |
|
2345 |
multiple patterns separated by semicolons." |
|
2346 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2347 |
|matchers notCaseSensitive| |
2550 | 2348 |
|
2349 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2350 |
notCaseSensitive := self class isCaseSensitive not. |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2351 |
|
2550 | 2352 |
^ self directoryContents |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2353 |
select:[:name | |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2354 |
name ~= '.' |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2355 |
and:[name ~= '..' |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2356 |
and:[(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0]] |
2550 | 2357 |
] |
2358 |
||
2359 |
" |
|
2360 |
Filename currentDirectory filesMatching:'M*' |
|
2361 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
2362 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
2363 |
" |
|
2364 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2365 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2366 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2367 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2368 |
|
615 | 2369 |
isAbsolute |
2370 |
"return true, if the receiver represents an absolute pathname |
|
2371 |
(in contrast to one relative to the current directory)." |
|
356 | 2372 |
|
2629 | 2373 |
(nameString startsWith:self class separator) ifTrue:[^ true]. |
2374 |
^ self isVolumeAbsolute |
|
328 | 2375 |
|
2376 |
" |
|
615 | 2377 |
'/foo/bar' asFilename isAbsolute |
2378 |
'..' asFilename isAbsolute |
|
2379 |
'..' asAbsoluteFilename isAbsolute |
|
2380 |
'source/SBrowser.st' asFilename isAbsolute |
|
2381 |
" |
|
2382 |
! |
|
2383 |
||
2384 |
isDirectory |
|
2385 |
"return true, if the receiver represents an existing, |
|
2386 |
readable directories pathname." |
|
2387 |
||
2947 | 2388 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
615 | 2389 |
|
2390 |
" |
|
2391 |
'/foo/bar' asFilename isDirectory |
|
2392 |
'/tmp' asFilename isDirectory |
|
2393 |
'Makefile' asFilename isDirectory |
|
3843 | 2394 |
'c:\' asFilename isDirectory |
2395 |
'd:\' asFilename isDirectory |
|
615 | 2396 |
" |
3843 | 2397 |
|
2398 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
615 | 2399 |
! |
2400 |
||
2401 |
isExecutable |
|
2402 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
2403 |
For directories, true is returned if the directory can be entered. |
|
2404 |
See isExecutableProgram for a related check." |
|
2405 |
||
2947 | 2406 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 2407 |
|
2408 |
" |
|
2409 |
'/foo/bar' asFilename isExecutable |
|
2410 |
'/tmp' asFilename isExecutable |
|
2411 |
'Makefile' asFilename isExecutable |
|
2412 |
'/bin/ls' asFilename isExecutable |
|
356 | 2413 |
" |
2414 |
! |
|
2415 |
||
615 | 2416 |
isExecutableProgram |
2417 |
"return true, if such a file exists and is an executable program. |
|
2418 |
(i.e. for directories, false is returned.)" |
|
356 | 2419 |
|
2922 | 2420 |
|osName| |
2421 |
||
2947 | 2422 |
osName := self osNameForAccess. |
2922 | 2423 |
^ (OperatingSystem isExecutable:osName) |
2424 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 2425 |
|
2426 |
" |
|
615 | 2427 |
'/tmp' asFilename isExecutable |
2428 |
'/bin/ls' asFilename isExecutable |
|
2429 |
'/tmp' asFilename isExecutableProgram |
|
2430 |
'/bin/ls' asFilename isExecutableProgram |
|
2431 |
" |
|
2432 |
! |
|
2433 |
||
2922 | 2434 |
isExplicitRelative |
2435 |
"return true, if this name is an explicit relative name |
|
2436 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
2437 |
||
2438 |
^ false |
|
2439 |
! |
|
2440 |
||
2441 |
isHidden |
|
2442 |
"return true, if the receiver represents a hidden file. |
|
2443 |
The definitions of hidden files depends on the OS used; |
|
2444 |
on UNIX, a name starting with a period is considered hidden; |
|
2445 |
on MSDOS, the files hidden attribute is used. |
|
2446 |
VMS has no concept of hidden files." |
|
2447 |
||
2448 |
^ false |
|
2449 |
! |
|
2450 |
||
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2451 |
isImplicit |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2452 |
"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
|
2453 |
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
|
2454 |
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
|
2455 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2456 |
^ false |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2457 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2458 |
"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
|
2459 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2460 |
|
615 | 2461 |
isReadable |
2462 |
"return true, if such a file exists and is readable." |
|
2463 |
||
2947 | 2464 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 2465 |
|
2466 |
" |
|
2467 |
'/foo/bar' asFilename isReadable |
|
2468 |
'/tmp' asFilename isReadable |
|
2469 |
'Makefile' asFilename isReadable |
|
328 | 2470 |
" |
2471 |
! |
|
2472 |
||
615 | 2473 |
isRelative |
2474 |
"return true, if this name is interpreted relative to some |
|
2475 |
directory (opposite of absolute)" |
|
328 | 2476 |
|
615 | 2477 |
^ self isAbsolute not |
2175 | 2478 |
|
2479 |
" |
|
2480 |
'./foo/bar' asFilename isRelative |
|
2481 |
'../../foo/bar' asFilename isRelative |
|
2482 |
'/foo/bar' asFilename isRelative |
|
2483 |
'bar' asFilename isRelative |
|
2484 |
" |
|
2485 |
||
2486 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
615 | 2487 |
! |
328 | 2488 |
|
3045 | 2489 |
isRootDirectory |
3046 | 2490 |
"return true, if I represent the root directory |
2491 |
(i.e. I have no parentDir)" |
|
2492 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2493 |
"/ mhmh - should we use: |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2494 |
"/ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2495 |
"/ parentDir := self construct:'..'. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2496 |
"/ (parentDir exists |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2497 |
"/ and:[parentDir isDirectory |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2498 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2499 |
"/ ^ false |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2500 |
"/ ]. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2501 |
"/ ^ true |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2502 |
"/ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2503 |
|
3046 | 2504 |
^ self pathName = Filename rootDirectory pathName |
2505 |
||
2506 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
3045 | 2507 |
! |
2508 |
||
615 | 2509 |
isSymbolicLink |
2510 |
"return true, if the file represented by the receiver is a symbolic |
|
2511 |
link. Notice that not all OS's support symbolic links; those that do |
|
2512 |
not will always return false." |
|
2513 |
||
2947 | 2514 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
328 | 2515 |
|
2516 |
" |
|
615 | 2517 |
'Make.proto' asFilename isSymbolicLink |
2518 |
'Makefile' asFilename isSymbolicLink |
|
2519 |
" |
|
2520 |
! |
|
2521 |
||
2629 | 2522 |
isVolumeAbsolute |
2523 |
"return true, if the receiver represents an absolute pathname |
|
2524 |
on some disk volume (MSDOS only)" |
|
2525 |
||
2526 |
^ false |
|
2906 | 2527 |
|
2528 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
2629 | 2529 |
! |
2530 |
||
615 | 2531 |
isWritable |
2532 |
"return true, if such a file exists and is writable." |
|
2533 |
||
2947 | 2534 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 2535 |
|
2536 |
" |
|
2537 |
'/foo/bar' asFilename isWritable |
|
2538 |
'/tmp' asFilename isWritable |
|
2539 |
'Makefile' asFilename isWritable |
|
328 | 2540 |
" |
174 | 2541 |
! |
2542 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2543 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2544 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2545 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2546 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2547 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2548 |
"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
|
2549 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2550 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2551 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2552 |
|
3865 | 2553 |
binaryContentsOfEntireFile |
3864 | 2554 |
"return the binary contents of the file as a byteArray; |
4897 | 2555 |
or nil, if the file is unreadable/non-existing." |
3864 | 2556 |
|
2557 |
|s contents| |
|
2558 |
||
2559 |
s := self readStream. |
|
2560 |
s isNil ifTrue:[^ nil]. |
|
2561 |
s binary. |
|
2562 |
[ |
|
2563 |
contents := s contentsOfEntireFile |
|
2564 |
] valueNowOrOnUnwindDo:[s close]. |
|
2565 |
^ contents |
|
2566 |
||
3865 | 2567 |
"Created: / 3.10.1998 / 17:56:39 / cg" |
3864 | 2568 |
! |
2569 |
||
1540 | 2570 |
contents |
2571 |
"return the contents of the file as a collection of lines; |
|
4897 | 2572 |
or nil, if the file is unreadable/non-existing. |
3876 | 2573 |
See also #contentsOfEntireFile, which returns a string for textFiles." |
1540 | 2574 |
|
2575 |
|s contents| |
|
2576 |
||
2577 |
s := self readStream. |
|
2578 |
s isNil ifTrue:[^ nil]. |
|
2579 |
||
2580 |
[ |
|
3876 | 2581 |
contents := s contents |
1540 | 2582 |
] valueNowOrOnUnwindDo:[s close]. |
2583 |
^ contents |
|
2584 |
||
5226 | 2585 |
" |
2586 |
'Makefile' asFilename contents |
|
2587 |
" |
|
2588 |
||
3876 | 2589 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
2590 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
2591 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
1540 | 2592 |
! |
2593 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2594 |
contentsOfEntireFile |
1540 | 2595 |
"return the contents of the file as a string; |
4897 | 2596 |
or nil, if the file is unreadable/non-existing. |
3876 | 2597 |
See also #contents, which returns the lines as stringCollection for textFiles." |
1049
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 |
|s contents| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2600 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2601 |
s := self readStream. |
1535 | 2602 |
s isNil ifTrue:[^ nil]. |
2603 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2604 |
[ |
3876 | 2605 |
contents := s contentsOfEntireFile |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2606 |
] valueNowOrOnUnwindDo:[s close]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2607 |
^ contents |
1523 | 2608 |
|
5226 | 2609 |
" |
2610 |
'Makefile' asFilename contentsOfEntireFile |
|
2611 |
" |
|
2612 |
||
3876 | 2613 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
2614 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2615 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2616 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2617 |
directoryContents |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2618 |
"return the contents of the directory as a collection of strings. |
4897 | 2619 |
This excludes any entries for '.' or '..'. |
2620 |
Returns nil for non-existing directories; however, this behavior |
|
2621 |
may be changed in the near future, to raise an exception instead. |
|
5226 | 2622 |
So users of this method better test for existing directory before. |
2623 |
Notice: this returns the file-names as strings; see also |
|
2624 |
#directoryContentsAsFilenames, which returns fileName objects." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2625 |
|
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2626 |
|s contents| |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2627 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
3713
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2628 |
s isNil ifTrue:[^nil]. |
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2629 |
|
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2630 |
contents := s contents. |
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2631 |
s close. |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2632 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2633 |
contents remove:'.' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2634 |
contents remove:'..' ifAbsent:nil. |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2635 |
^ contents. |
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2636 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2637 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2638 |
'.' asFilename directoryContents |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2639 |
'/XXXdoesNotExist' asFilename directoryContents |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2640 |
" |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2641 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2642 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2643 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
2960 | 2644 |
! |
2645 |
||
4897 | 2646 |
directoryContentsAsFilenames |
2647 |
"return the contents of the directory as a collection of filenames. |
|
2648 |
This excludes any entries for '.' or '..'. |
|
2649 |
Returns nil for non-existing directories; however, this behavior |
|
2650 |
may be changed in the near future, to raise an exception instead. |
|
5226 | 2651 |
So users of this method better test for existing directory before. |
2652 |
Notice: this returns the file-names as fileName objects; see also |
|
2653 |
#directoryContents, which returns strings." |
|
4897 | 2654 |
|
2655 |
|names| |
|
2656 |
||
2657 |
names := self directoryContents. |
|
2658 |
names isNil ifTrue:[^ nil]. |
|
2659 |
^ names asOrderedCollection collect:[:entry | self construct:entry]. |
|
2660 |
||
2661 |
" |
|
2662 |
'.' asFilename directoryContentsAsFilenames |
|
2663 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
|
2664 |
" |
|
2665 |
||
2666 |
! |
|
2667 |
||
5174
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2668 |
directoryContentsAsFilenamesDo:aBlock |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2669 |
"evaluate aBlock for each file in the directory represented by the receiver. |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2670 |
The block is invoked with a filename as argument. |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2671 |
The enumerations order is undefined - i.e. usually NOT sorted by |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2672 |
filenames (but by creation time - on some systems). |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2673 |
This excludes entries for '.' or '..'. |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2674 |
NoOp for non-existing directories; however, this behavior |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2675 |
may be changed in the near future, to raise an exception instead. |
5226 | 2676 |
So users of this method better test for existing directory before. |
2677 |
Notice: this enumerates fileName objects; see also |
|
2678 |
#directoryContentsDo:, which enumerates strings." |
|
5174
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2679 |
|
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2680 |
self directoryContentsAsFilenames do:aBlock. |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2681 |
|
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2682 |
" |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2683 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2684 |
" |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2685 |
|
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2686 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2687 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2688 |
! |
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2689 |
|
4897 | 2690 |
directoryContentsDo:aBlock |
5174
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2691 |
"evaluate aBlock for each file in the directory represented by the receiver. |
4897 | 2692 |
The block is invoked with a string as argument. |
5174
077a6f90fb4b
added #directoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
5134
diff
changeset
|
2693 |
The enumerations order is undefined - i.e. usually NOT sorted by |
4897 | 2694 |
filenames (but by creation time - on some systems). |
2695 |
This excludes entries for '.' or '..'. |
|
2696 |
NoOp for non-existing directories; however, this behavior |
|
2697 |
may be changed in the near future, to raise an exception instead. |
|
5226 | 2698 |
So users of this method better test for existing directory before. |
2699 |
Notice: this enumerates strings; see also |
|
2700 |
#directoryContentsDo:, which enumerates fileName objects." |
|
4897 | 2701 |
|
5132 | 2702 |
self directoryContents do:aBlock. |
4897 | 2703 |
|
2704 |
" |
|
2705 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
2706 |
" |
|
2707 |
||
2708 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
5132 | 2709 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
4897 | 2710 |
! |
2711 |
||
2960 | 2712 |
fullDirectoryContents |
2713 |
"return the full contents of the directory as a collection of strings. |
|
2714 |
This is much like #directoryContents, but includes an entry for the |
|
4897 | 2715 |
parent directory, if there is one. |
2716 |
Returns nil for non-existing directories; however, this behavior |
|
2717 |
may be changed in the near future, to raise an exception instead. |
|
2718 |
So users of this method better test for existing directory before." |
|
2960 | 2719 |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2720 |
|files| |
2960 | 2721 |
|
2722 |
files := self directoryContents. |
|
3302 | 2723 |
files isNil ifTrue:[ |
2724 |
"/ mhmh - that one does not exist |
|
2725 |
^ files |
|
2726 |
]. |
|
2960 | 2727 |
|
3843 | 2728 |
"/ add/remove parentDirectory if there is one/none |
2960 | 2729 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2730 |
files remove:'.' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2731 |
self isRootDirectory ifTrue:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2732 |
files remove:'..' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2733 |
] ifFalse:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2734 |
(files includes:'..') ifFalse:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2735 |
files addFirst:'..'. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2736 |
] |
2960 | 2737 |
]. |
2738 |
^ files |
|
3046 | 2739 |
|
2740 |
" |
|
2741 |
'.' asFilename fullDirectoryContents |
|
2742 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
3843 | 2743 |
'd:\FET' asFilename fullDirectoryContents |
3046 | 2744 |
" |
2745 |
||
3843 | 2746 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2747 |
! |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2748 |
|
5011 | 2749 |
mimeTypeOfContents |
2750 |
"this tries to guess the mime type of contents of |
|
2751 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
2752 |
or the contents is unknown. |
|
2753 |
This is done using some heuristics, and may need some improvement" |
|
2754 |
||
2755 |
|type buffer s n suffix idx idx2 baseNm| |
|
2756 |
||
2757 |
self isDirectory ifTrue:[ |
|
2758 |
^ 'nil' |
|
2759 |
]. |
|
2760 |
(type := self type) == #characterSpecial ifTrue:[ |
|
2761 |
^ nil |
|
2762 |
]. |
|
2763 |
type == #blockSpecial ifTrue:[ |
|
2764 |
^ nil |
|
2765 |
]. |
|
2766 |
type == #socket ifTrue:[ |
|
2767 |
^ nil |
|
2768 |
]. |
|
2769 |
||
2770 |
self isReadable ifFalse:[^ nil]. |
|
2771 |
self fileSize == 0 ifTrue:[^ nil]. |
|
2772 |
||
2773 |
suffix := self suffix asLowercase. |
|
2774 |
baseNm := self withoutSuffix baseName asLowercase. |
|
2775 |
||
2776 |
"/ read some data from the file ... |
|
2777 |
buffer := String new:2024. |
|
2778 |
s := self readStream. |
|
2779 |
s isNil ifTrue:[^ nil]. |
|
2780 |
||
2781 |
n := s nextBytes:buffer size into:buffer. |
|
2782 |
s close. |
|
2783 |
||
2784 |
(idx := buffer findString:'MIMEType:') ~~ 0 ifTrue:[ |
|
2785 |
idx := idx + 'MIMEType:' size. |
|
5032
2eb84639ab45
fixed mimeTypeOfContents: scanning for 'MIMEType:' was wrong.
Claus Gittinger <cg@exept.de>
parents:
5012
diff
changeset
|
2786 |
idx := buffer indexOfNonSeparatorStartingAt:idx. |
2eb84639ab45
fixed mimeTypeOfContents: scanning for 'MIMEType:' was wrong.
Claus Gittinger <cg@exept.de>
parents:
5012
diff
changeset
|
2787 |
idx2 := buffer indexOfSeparatorStartingAt:idx. |
2eb84639ab45
fixed mimeTypeOfContents: scanning for 'MIMEType:' was wrong.
Claus Gittinger <cg@exept.de>
parents:
5012
diff
changeset
|
2788 |
idx2 > idx ifTrue:[ |
2eb84639ab45
fixed mimeTypeOfContents: scanning for 'MIMEType:' was wrong.
Claus Gittinger <cg@exept.de>
parents:
5012
diff
changeset
|
2789 |
^ buffer copyFrom:idx to:idx2-1 |
5011 | 2790 |
]. |
2791 |
]. |
|
2792 |
||
5303 | 2793 |
(buffer findString:'interchangeVersion:') ~~ 0 ifTrue:[ |
2794 |
^ 'application/x-smalltalk-source-sif' |
|
2795 |
]. |
|
5011 | 2796 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
2797 |
^ 'application/x-smalltalk-source' |
|
2798 |
]. |
|
2799 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
2800 |
^ 'application/x-smalltalk-source' |
|
2801 |
]. |
|
2802 |
||
2803 |
(buffer findString:'<BODY:') ~~ 0 ifTrue:[ |
|
2804 |
^ 'text/html' |
|
2805 |
]. |
|
2806 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
|
2807 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
|
2808 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
|
2809 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
|
2810 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
|
2811 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
|
2812 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
|
2813 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
|
2814 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
|
2815 |
ifTrue:[ |
|
2816 |
^ 'text/html' |
|
2817 |
] |
|
2818 |
]. |
|
2819 |
||
2820 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
|
2821 |
^ 'application/postscript' |
|
2822 |
]. |
|
2823 |
||
2824 |
(buffer findString:'#!! /bin/sh') ~~ 0 ifTrue:[ |
|
2825 |
^ 'application/x-sh' |
|
2826 |
]. |
|
2827 |
(buffer findString:'#!!/bin/sh') ~~ 0 ifTrue:[ |
|
2828 |
^ 'application/x-sh' |
|
2829 |
]. |
|
2830 |
||
2831 |
^ nil |
|
2832 |
||
2833 |
" |
|
2834 |
'Makefile' asFilename mimeTypeOfContents |
|
2835 |
'.' asFilename mimeTypeOfContents |
|
2836 |
'/dev/null' asFilename mimeTypeOfContents |
|
2837 |
'/tmp/.X11-unix/X0' asFilename mimeTypeOfContents |
|
2838 |
'smalltalk.rc' asFilename mimeTypeOfContents |
|
2839 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents |
|
2840 |
'../../rules/stmkmf' asFilename mimeTypeOfContents |
|
2841 |
" |
|
2842 |
||
5012 | 2843 |
"Modified: / 19.11.1999 / 15:58:29 / cg" |
5011 | 2844 |
! |
2845 |
||
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2846 |
recursiveDirectoryContents |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2847 |
"return the contents of the directory and all subdirectories |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2848 |
as a collection of strings. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2849 |
This excludes any entries for '.' or '..'. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2850 |
Subdirectory files are included with a relative pathname. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2851 |
Warning: this may take a long time to execute." |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2852 |
|
3868 | 2853 |
|fileNames dirNames| |
2854 |
||
2855 |
fileNames := OrderedCollection new. |
|
2856 |
dirNames := OrderedCollection new. |
|
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2857 |
self directoryContents do:[:f | |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2858 |
(self construct:f) isDirectory ifTrue:[ |
3868 | 2859 |
dirNames add:f |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2860 |
] ifFalse:[ |
3868 | 2861 |
fileNames add:f |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2862 |
] |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2863 |
]. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2864 |
|
3868 | 2865 |
dirNames do:[:dN | |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2866 |
|dd subFiles| |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2867 |
|
3868 | 2868 |
dd := dN asFilename. |
2869 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
|
2870 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
|
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2871 |
]. |
3868 | 2872 |
^ fileNames. |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2873 |
|
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2874 |
" |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2875 |
'.' asFilename recursiveDirectoryContents |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2876 |
'../../clients' asFilename recursiveDirectoryContents |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2877 |
" |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2878 |
|
5127 | 2879 |
! |
2880 |
||
2881 |
recursiveDirectoryContentsDo:aBlock |
|
2882 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2883 |
The walk is bread-first. |
|
2884 |
This excludes any entries for '.' or '..'. |
|
2885 |
Subdirectory files are included with a relative pathname. |
|
2886 |
Warning: this may take a long time to execute." |
|
2887 |
||
2888 |
self recursiveDirectoryContentsDo:aBlock directoryPrefix:'' |
|
2889 |
||
2890 |
" |
|
2891 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
|
2892 |
" |
|
2893 |
||
2894 |
! |
|
2895 |
||
2896 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
|
2897 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2898 |
The walk is bread-first. |
|
2899 |
This excludes any entries for '.' or '..'. |
|
2900 |
Subdirectory files are included with a relative pathname. |
|
2901 |
Warning: this may take a long time to execute." |
|
2902 |
||
2903 |
|fileNames dirNames p| |
|
2904 |
||
2905 |
fileNames := OrderedCollection new. |
|
2906 |
dirNames := OrderedCollection new. |
|
2907 |
self directoryContentsDo:[:f | |t| |
|
2908 |
(t := self construct:f) isSymbolicLink ifFalse:[ |
|
2909 |
t isDirectory ifTrue:[ |
|
2910 |
dirNames add:f |
|
2911 |
] ifFalse:[ |
|
2912 |
fileNames add:f |
|
2913 |
] |
|
2914 |
] |
|
2915 |
]. |
|
2916 |
||
2917 |
aPrefix size > 0 ifTrue:[ |
|
2918 |
p := aPrefix , self separator asString |
|
2919 |
] ifFalse:[ |
|
2920 |
p := '' |
|
2921 |
]. |
|
2922 |
||
2923 |
fileNames do:[:aFile | aBlock value:(p , aFile)]. |
|
2924 |
dirNames do:[:dN | |
|
2925 |
(self construct:dN) |
|
2926 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN) |
|
2927 |
]. |
|
2928 |
||
2929 |
" |
|
2930 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
|
2931 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
|
2932 |
" |
|
2933 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2934 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2935 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2936 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2937 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2938 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2939 |
"return my baseName as a string. |
2012 | 2940 |
- thats the file/directory name without leading parent-dirs. |
2922 | 2941 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
2942 |
and '/usr/lib' asFilename baseName -> lib). |
|
2943 |
This method does not check if the path is valid |
|
2944 |
||
2911 | 2945 |
See also: #pathName, #directoryName and #directoryPathName. |
2946 |
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
|
2947 |
|
2922 | 2948 |
|len index sep endIdx| |
2949 |
||
2950 |
sep := self separator. |
|
2951 |
len := nameString size. |
|
2952 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
2953 |
^ nameString |
|
2954 |
]. |
|
2955 |
||
2956 |
endIdx := len. |
|
2957 |
len > 1 ifTrue:[ |
|
2958 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
|
2959 |
]. |
|
2960 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
2961 |
index == 0 ifTrue:[ |
|
2962 |
^ nameString copyTo:endIdx |
|
2963 |
]. |
|
2964 |
^ 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
|
2965 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2966 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2967 |
'/foo/bar' asFilename baseName |
4903 | 2968 |
'/foo/bar.cc' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2969 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2970 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2971 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2972 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2973 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2974 |
'../../libbasic/Object.st' asFilename baseName |
3851 | 2975 |
'/' asFilename baseName |
2976 |
'\' asFilename baseName |
|
2977 |
'c:\' asFilename baseName |
|
2978 |
'\\idefix' asFilename baseName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2979 |
" |
2012 | 2980 |
|
3851 | 2981 |
"Modified: / 24.9.1998 / 13:06:23 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2982 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2983 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2984 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2985 |
"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
|
2986 |
- 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
|
2987 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2988 |
(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
|
2989 |
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
|
2990 |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
2991 |
^ self class named:(self directoryName) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2992 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2993 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2994 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2995 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2996 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2997 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2998 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2999 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3000 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3001 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3002 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3003 |
"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
|
3004 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3005 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3006 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3007 |
"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
|
3008 |
- 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
|
3009 |
the receiver is contained in. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3010 |
This method does not check if the path is valid. |
2922 | 3011 |
|
3012 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
3013 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
3014 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3015 |
(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
|
3016 |
a string instead of a Filename instance). |
2922 | 3017 |
|
2012 | 3018 |
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
|
3019 |
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
|
3020 |
|
3954 | 3021 |
|index sep sepString p rest| |
2922 | 3022 |
|
3023 |
sep := self separator. |
|
3024 |
sepString := sep asString. |
|
3025 |
(nameString = sepString) ifTrue:[ |
|
3026 |
"/ |
|
3027 |
"/ the trivial '/' case |
|
3028 |
"/ |
|
3029 |
^ nameString |
|
3030 |
]. |
|
3031 |
||
3032 |
"/ |
|
3893 | 3033 |
"/ strip off multiple trailing slashes |
2922 | 3034 |
"/ |
3035 |
p := nameString. |
|
3036 |
[p endsWith:sepString] whileTrue:[ |
|
3037 |
(p = sepString) ifTrue:[ |
|
3038 |
^ p |
|
3039 |
]. |
|
3040 |
p := p copyWithoutLast:1 |
|
3041 |
]. |
|
3042 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
3043 |
"/ strip off trailing components |
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
3044 |
|
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3045 |
index := p lastIndexOf:sep startingAt:p size. |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3046 |
index == 0 ifTrue:[ |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3047 |
"/ no separator found |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3048 |
p = '.' ifTrue:[ |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3049 |
^ '..' |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3050 |
]. |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3051 |
p = '..' ifTrue:[ |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3052 |
^ '../..' |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3053 |
]. |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3054 |
^ '.' |
2922 | 3055 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3056 |
rest := p copyFrom:(index+1). |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3057 |
rest = '.' ifTrue:[ |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3058 |
^ p , '.' |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3059 |
]. |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3060 |
rest = '..' ifTrue:[ |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3061 |
^ p , '/..' |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3062 |
]. |
3893 | 3063 |
index == 1 ifTrue:[ |
3064 |
^ '/' |
|
3065 |
]. |
|
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3066 |
^ p copyTo:(index - 1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3067 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3068 |
" |
3893 | 3069 |
'/home' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3070 |
'/foo/bar/' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3071 |
'/foo/bar/' asFilename directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3072 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3073 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3074 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3075 |
'bitmaps' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3076 |
'.' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3077 |
'.' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3078 |
'..' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3079 |
'..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3080 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3081 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3082 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3083 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
3084 |
"Modified: / 7.9.1995 / 10:42:03 / claus" |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
3085 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 3086 |
"Modified: / 27.10.1998 / 13:19:26 / ps" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3087 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3088 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3089 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3090 |
"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
|
3091 |
- 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
|
3092 |
the receiver is contained in. |
2012 | 3093 |
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
|
3094 |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3095 |
^ (self class named:self pathName) directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3096 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3097 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3098 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3099 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3100 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3101 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3102 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3103 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3104 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3105 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3106 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3107 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3108 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3109 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3110 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3111 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3112 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 3113 |
"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
|
3114 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3115 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3116 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3117 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3118 |
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
|
3119 |
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
|
3120 |
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
|
3121 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3122 |
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
|
3123 |
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
|
3124 |
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
|
3125 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3126 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3127 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3128 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3129 |
'mak' asFilename filenameCompletion |
1517 | 3130 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3131 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3132 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3133 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3134 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3135 |
|
1517 | 3136 |
"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
|
3137 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3138 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3139 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3140 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3141 |
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
|
3142 |
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
|
3143 |
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
|
3144 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3145 |
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
|
3146 |
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
|
3147 |
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
|
3148 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3149 |
|dir baseName matching matchLen try allMatching |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3150 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 3151 |
|
3152 |
nm := self nameWithSpecialExpansions:nameString. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3153 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3154 |
sepString := self class separator asString. |
3666 | 3155 |
(nm endsWith:sepString) ifTrue:[ |
2906 | 3156 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3157 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3158 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3159 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3160 |
baseName := self baseName. |
3666 | 3161 |
baseName ~= nm ifTrue:[ |
2906 | 3162 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3163 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3164 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3165 |
self isAbsolute ifTrue:[ |
2906 | 3166 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3167 |
] ifFalse:[ |
2906 | 3168 |
aDirectory isNil ifTrue:[ |
3169 |
dir := self directory |
|
3170 |
] ifFalse:[ |
|
3666 | 3171 |
dir := (aDirectory construct:nm) directory |
2906 | 3172 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3173 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3174 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3175 |
caseless := self class isCaseSensitive not. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3176 |
caseless ifTrue:[ |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3177 |
lcBaseName := baseName asLowercase |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3178 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3179 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3180 |
matching := OrderedCollection new. |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3181 |
dir class errorReporter openErrorSignal handle:[:ex| |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3182 |
^ #(). |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3183 |
] do:[ |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3184 |
dir directoryContents do:[:fileName | |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3185 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3186 |
((caseless and:[fileName asLowercase startsWith:lcBaseName]) |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
3187 |
or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[ |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3188 |
matching add:fileName |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3189 |
] |
2906 | 3190 |
] |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3191 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3192 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3193 |
(nMatch := matching size) > 1 ifTrue:[ |
2906 | 3194 |
" |
3195 |
find the longest common prefix |
|
3196 |
" |
|
3197 |
matchLen := baseName size. |
|
3198 |
matchLen > matching first size ifTrue:[ |
|
3199 |
try := baseName. |
|
3200 |
allMatching := false |
|
3201 |
] ifFalse:[ |
|
3202 |
try := matching first copyTo:matchLen. |
|
3203 |
allMatching := true. |
|
3204 |
]. |
|
3205 |
||
3206 |
[allMatching] whileTrue:[ |
|
3207 |
matching do:[:aName | |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
3208 |
((caseless and:[aName asLowercase startsWith:try asLowercase]) |
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
3209 |
or:[caseless not and:[aName startsWith:try]]) ifFalse:[ |
2906 | 3210 |
allMatching := false |
3211 |
] |
|
3212 |
]. |
|
3213 |
allMatching ifTrue:[ |
|
3214 |
matchLen < matching first size ifTrue:[ |
|
3215 |
matchLen := matchLen + 1. |
|
3216 |
try := matching first copyTo:matchLen. |
|
3217 |
] ifFalse:[ |
|
3218 |
allMatching := false |
|
3219 |
] |
|
3220 |
] ifFalse:[ |
|
3221 |
try := matching first copyTo:matchLen - 1. |
|
3222 |
] |
|
3223 |
]. |
|
3224 |
" |
|
3225 |
and set my name to the last full match |
|
3226 |
" |
|
3666 | 3227 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3228 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3229 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3230 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3231 |
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
|
3232 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3233 |
prefix notNil ifTrue:[ |
2906 | 3234 |
prefix = sepString ifTrue:[ |
3235 |
"/ avoid introducing double slashes |
|
3236 |
prefix := '' |
|
3237 |
]. |
|
3238 |
matching := matching collect:[:n | prefix , sepString , n]. |
|
3239 |
nMatch == 1 ifTrue:[ |
|
3666 | 3240 |
nameString := nm := matching first |
2906 | 3241 |
] ifFalse:[ |
3242 |
nMatch > 1 ifTrue:[ |
|
3666 | 3243 |
nameString := nm := prefix , sepString , nm |
2906 | 3244 |
] |
3245 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3246 |
] ifFalse:[ |
2906 | 3247 |
nMatch == 1 ifTrue:[ |
3666 | 3248 |
nameString := nm := matching first |
2906 | 3249 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3250 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3251 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3252 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3253 |
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
|
3254 |
(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
|
3255 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3256 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3257 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3258 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3259 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3260 |
'../' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3261 |
'/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3262 |
'/usr/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3263 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3264 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3265 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3266 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3267 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3268 |
'../../libpr' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3269 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3270 |
|
3666 | 3271 |
"Modified: / 22.9.1997 / 18:03:33 / stefan" |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
3272 |
"Modified: / 30.4.1999 / 09:39:52 / cg" |
2903 | 3273 |
! |
3274 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3275 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3276 |
"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
|
3277 |
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
|
3278 |
(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
|
3279 |
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
|
3280 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3281 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3282 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3283 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3284 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3285 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3286 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3287 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3288 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3289 |
"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
|
3290 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3291 |
|
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3292 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3293 |
"return the full pathname of the file represented by the receiver, |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3294 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3295 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3296 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3297 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3298 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
3299 |
|
615 | 3300 |
name |
3301 |
"return the name of the file represented by the receiver as a string. |
|
883 | 3302 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 3303 |
See also: pathName" |
174 | 3304 |
|
615 | 3305 |
self isAbsolute ifTrue:[^ self pathName]. |
3306 |
^ nameString |
|
174 | 3307 |
|
3308 |
" |
|
615 | 3309 |
'/foo/bar' asFilename name |
3310 |
'/foo/bar' asFilename pathName |
|
3311 |
'.' asFilename name |
|
3312 |
'.' asFilename pathName |
|
3313 |
'../..' asFilename name |
|
883 | 3314 |
'../..' asFilename pathName |
615 | 3315 |
'bitmaps' asFilename name |
3316 |
'bitmaps' asFilename pathName |
|
3317 |
'/tmp/../usr' asFilename name |
|
883 | 3318 |
'/tmp/../usr' asFilename pathName |
3319 |
'source/..' asFilename name |
|
3320 |
'source/..' asFilename pathName |
|
3321 |
'/tmp/..' asFilename name |
|
3322 |
'/tmp/..' asFilename pathName |
|
92 | 3323 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
3324 |
|
883 | 3325 |
"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
|
3326 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
3327 |
|
615 | 3328 |
pathName |
3329 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 3330 |
as a string. This will not include ..'s. |
3331 |
If the path represented by the receiver does NOT represent a valid path, |
|
3332 |
no compression will be done (for now; this may change). |
|
3333 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
3334 |
|
1317 | 3335 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
3336 |
|
1317 | 3337 |
"/ sep := self class separator. |
3338 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
3339 |
"/ parentName := self class parentDirectoryName. |
|
3340 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
3341 |
"/ ^ nameString |
|
3342 |
"/ ] |
|
3343 |
"/ ]. |
|
3344 |
p := OperatingSystem pathNameOf:nameString. |
|
3345 |
^ p |
|
2 | 3346 |
|
92 | 3347 |
" |
1317 | 3348 |
'/foo/bar' asFilename pathName |
3349 |
'.' asFilename pathName |
|
3350 |
'../..' asFilename pathName |
|
3351 |
'../..' asFilename name |
|
3352 |
'/tmp/../usr' asFilename pathName |
|
3353 |
'/././usr' asFilename pathName |
|
92 | 3354 |
" |
159 | 3355 |
|
1317 | 3356 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 3357 |
! |
3358 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3359 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3360 |
"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
|
3361 |
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
|
3362 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3363 |
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
|
3364 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3365 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3366 |
|t target path| |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3367 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3368 |
self isSymbolicLink ifFalse:[ |
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3369 |
self exists ifFalse:[^ nil]. |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3370 |
^ self pathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3371 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3372 |
t := self. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3373 |
[t isSymbolicLink] whileTrue:[ |
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3374 |
path := t linkInfo path. |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3375 |
path isNil ifTrue:[ |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3376 |
"/ cannot happen |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3377 |
^ nil |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3378 |
]. |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3379 |
target := (self class named:t directoryName) construct:path. |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3380 |
target exists ifFalse:[^ nil]. |
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
3381 |
t := target asFilename |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3382 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3383 |
t exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3384 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3385 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3386 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3387 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3388 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3389 |
'../..' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3390 |
'include/abbrev.stc' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3391 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3392 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3393 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3394 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
3395 |
|
615 | 3396 |
tail |
3397 |
"the files name without directory prefix as a string. |
|
3398 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 3399 |
|
615 | 3400 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3401 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3402 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3403 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3404 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3405 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3406 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3407 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3408 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 3409 |
! |
3410 |
||
3411 |
volume |
|
3412 |
"return the disc volume part of the name or an empty string. |
|
2906 | 3413 |
This is only used with MSDOS and VMS filenames |
3414 |
- by default (and on unix), an empty string is returned" |
|
3415 |
||
2629 | 3416 |
^ '' |
2906 | 3417 |
|
3418 |
"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
|
3419 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3420 |
|
2922 | 3421 |
!Filename methodsFor:'special accessing'! |
3422 |
||
3665 | 3423 |
nameWithSpecialExpansions:aString |
3424 |
"return the nameString, expanding any OS specific |
|
3425 |
macros. This should be redefined for OS's where such macros |
|
3426 |
are common. |
|
3427 |
On unix, a ~/ prefix is expanded to the users home dir (as in csh)" |
|
3428 |
||
3429 |
^ aString |
|
3430 |
||
3431 |
"Modified: / 21.7.1998 / 10:43:20 / cg" |
|
3432 |
"Created: / 21.7.1998 / 10:45:58 / cg" |
|
3433 |
! |
|
3434 |
||
2922 | 3435 |
osName |
3436 |
"special - return the OS's name for the receiver." |
|
3437 |
||
3438 |
self isDirectory ifTrue:[ |
|
3439 |
^ self osNameForDirectory |
|
3440 |
]. |
|
3441 |
^ self osNameForFile |
|
3442 |
! |
|
3443 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3444 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3445 |
"internal - return the OS's name for the receiver to |
3665 | 3446 |
access its fileInfo. |
3447 |
This may be redefined for systems, where a special suffix must be |
|
3448 |
added in order to access directories (or others) as a file. |
|
3449 |
(i.e. under VMS, a '.dir' suffix is added to access directories)" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3450 |
|
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3451 |
^ nameString |
3665 | 3452 |
|
3453 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3454 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
3455 |
|
2922 | 3456 |
osNameForDirectory |
3753 | 3457 |
"internal - return the OS's name for the receiver to |
2922 | 3458 |
access it as a directory." |
3459 |
||
3460 |
^ nameString |
|
3753 | 3461 |
|
3462 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 3463 |
! |
3464 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3465 |
osNameForDirectoryContents |
3753 | 3466 |
"internal - return the OS's name for the receiver to |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3467 |
access it as a directory when reading its contents." |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3468 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3469 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3470 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3471 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 3472 |
"Modified: / 12.8.1998 / 14:44:34 / cg" |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3473 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3474 |
|
2922 | 3475 |
osNameForFile |
3476 |
"internal - return the OS's name for the receiver to |
|
3477 |
access it as a file." |
|
3478 |
||
3479 |
^ nameString |
|
3480 |
! ! |
|
3481 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3482 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3483 |
|
2906 | 3484 |
hasSuffix:aSuffixString |
3485 |
"return true if my suffix is the same as aString. |
|
3486 |
This cares for systems, where case is ignored in filenames" |
|
3487 |
||
3488 |
|mySuffix| |
|
3489 |
||
3490 |
mySuffix := self suffix. |
|
3491 |
self class isCaseSensitive ifTrue:[ |
|
3492 |
^ mySuffix = aSuffixString |
|
3493 |
]. |
|
3494 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
3495 |
||
3496 |
" |
|
3497 |
'abc.st' asFilename hasSuffix:'st' |
|
3498 |
'abc.ST' asFilename hasSuffix:'st' |
|
3499 |
" |
|
3500 |
||
3501 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
3502 |
! |
|
3503 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3504 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3505 |
"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
|
3506 |
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
|
3507 |
the prefix everything before, except for the period. |
1517 | 3508 |
The directory name part is stripped off (i.e. the returned prefix |
3509 |
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
|
3510 |
(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
|
3511 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
1517 | 3512 |
See also: #withoutSuffix and #withSuffix |
3513 |
Notice: |
|
2629 | 3514 |
there is currently no known system which uses other than |
3515 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3516 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3517 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3518 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3519 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3520 |
idx := nm lastIndexOf:(self class suffixSeparator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3521 |
idx == 0 ifTrue:[ |
2629 | 3522 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3523 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3524 |
^ Array |
2629 | 3525 |
with:(nm copyTo:idx-1) |
3526 |
with:(nm copyFrom:idx+1) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3527 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3528 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3529 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3530 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3531 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 3532 |
'/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
|
3533 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3534 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3535 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 3536 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3537 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3538 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3539 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 3540 |
"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
|
3541 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3542 |
|
2906 | 3543 |
suffix |
3544 |
"return my suffix. |
|
3545 |
The suffix is the namepart after the final period character, |
|
3546 |
or the empty string, if the name does not contain a period." |
|
3547 |
||
3548 |
^ self prefixAndSuffix at:2 |
|
3549 |
||
3550 |
" |
|
3551 |
'abc.st' asFilename suffix |
|
3552 |
'abc' asFilename suffix |
|
3553 |
'a.b.c' asFilename suffix |
|
3554 |
" |
|
3555 |
||
3556 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
3557 |
! |
|
3558 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3559 |
withSuffix:aSuffix |
2922 | 3560 |
"return a new filename for the receivers name with a different suffix. |
1993 | 3561 |
If the name already has a suffix, the new suffix replacaes it; |
3562 |
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
|
3563 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3564 |
^ self class named: |
2629 | 3565 |
(self withoutSuffix name |
3566 |
, self class suffixSeparator asString |
|
3567 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3568 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3569 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3570 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3571 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3572 |
'a.b.c' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3573 |
'/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
|
3574 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 3575 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 3576 |
'/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
|
3577 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3578 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3579 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1993 | 3580 |
"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
|
3581 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3582 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3583 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3584 |
"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
|
3585 |
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
|
3586 |
|
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3587 |
|nm idx idxFromEnd| |
2922 | 3588 |
|
3589 |
nm := self baseName. |
|
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3590 |
idx := nm lastIndexOf:(self class suffixSeparator). |
2922 | 3591 |
(idx == 0) ifTrue:[^ self]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3592 |
|
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3593 |
idxFromEnd := nm size - idx. |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3594 |
idx := nameString size - idxFromEnd. |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3595 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3596 |
^ 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
|
3597 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3598 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3599 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3600 |
'abc' asFilename withoutSuffix |
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3601 |
'/abc' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3602 |
'/abc.d' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3603 |
'./abc' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3604 |
'./abc.d' asFilename withoutSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3605 |
'a.b.c' asFilename withoutSuffix |
1516 | 3606 |
'/foo/bar/baz.c' asFilename withoutSuffix |
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3607 |
'/foo/bar.x/baz.c' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
3608 |
'/foo/bar.x/baz' asFilename withoutSuffix |
1516 | 3609 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
3610 |
'/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
|
3611 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3612 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3613 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1516 | 3614 |
"Modified: 3.7.1996 / 10:49:58 / cg" |
174 | 3615 |
! ! |
3616 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3617 |
!Filename class methodsFor:'documentation'! |
630 | 3618 |
|
3619 |
version |
|
5303 | 3620 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.181 2000-03-21 11:07:58 cg Exp $' |
630 | 3621 |
! ! |
2906 | 3622 |
Filename initialize! |