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