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