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