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