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