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