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