author | Stefan Vogel <sv@exept.de> |
Mon, 22 Jun 2009 23:56:50 +0200 | |
changeset 11784 | dc0f068adfd6 |
parent 11781 | 6488fd6cc498 |
child 11877 | aa347ed8ce60 |
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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
279 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
358 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
430 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
543 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
625 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
648 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
687 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
705 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
819 |
self isAbstract 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 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
920 |
self isAbstract 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 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
981 |
self isAbstract ifTrue:[ |
10663
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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1011 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1036 |
self isAbstract 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 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1154 |
self isAbstract 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 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1176 |
isAbstract |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1177 |
"return true, if this is not a concrete class" |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1178 |
|
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1179 |
^ self == Filename |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1180 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1181 |
|
2903 | 1182 |
isBadCharacter:aCharacter |
1183 |
"return true, if aCharacter is unallowed in a filename." |
|
1184 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1185 |
self isAbstract ifTrue:[ |
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1186 |
^ ConcreteClass isBadCharacter:aCharacter |
2906 | 1187 |
]. |
1188 |
||
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1189 |
^ aCharacter isControlCharacter |
2903 | 1190 |
! |
1191 |
||
1192 |
isCaseSensitive |
|
1193 |
"return true, if filenames are case sensitive. |
|
1194 |
We ask the OS about this, to be independent here." |
|
1195 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1196 |
self isAbstract ifTrue:[ |
8668 | 1197 |
^ ConcreteClass isCaseSensitive |
2906 | 1198 |
]. |
1199 |
||
2903 | 1200 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 1201 |
|
1202 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 1203 |
! |
1204 |
||
615 | 1205 |
localNameStringFrom:aString |
1206 |
"ST-80 compatibility. |
|
1207 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 1208 |
GUESS: |
8243 | 1209 |
does it strip off any volume characters and make a path relative ?" |
2922 | 1210 |
|
1211 |
|sep| |
|
615 | 1212 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1213 |
self isAbstract ifTrue:[ |
8243 | 1214 |
^ ConcreteClass localNameStringFrom:aString |
2906 | 1215 |
]. |
1216 |
||
8243 | 1217 |
sep := self separatorString. |
2922 | 1218 |
(aString startsWith:sep) ifTrue:[ |
8243 | 1219 |
^ aString copyFrom:sep size + 1 |
615 | 1220 |
]. |
1221 |
^ aString |
|
1222 |
||
1223 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 1224 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 1225 |
! |
1226 |
||
2908 | 1227 |
maxComponentLength |
1228 |
"return the maximum number of characters a filename component may |
|
1229 |
be in size. This depends on the OperatingSystem." |
|
1230 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1231 |
self isAbstract ifTrue:[ |
8668 | 1232 |
^ ConcreteClass maxComponentLength |
2908 | 1233 |
]. |
1234 |
^ OperatingSystem maxFileNameLength |
|
1235 |
! |
|
1236 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1237 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1238 |
"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
|
1239 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1240 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1241 |
self isAbstract ifTrue:[ |
8668 | 1242 |
^ ConcreteClass maxLength |
2908 | 1243 |
]. |
1244 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1245 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1246 |
"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
|
1247 |
"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
|
1248 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1249 |
|
3171 | 1250 |
nullFilename |
1251 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
1252 |
The default is nil here" |
|
1253 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1254 |
self isAbstract ifTrue:[ |
8668 | 1255 |
^ ConcreteClass nullFilename |
3171 | 1256 |
]. |
1257 |
||
8754 | 1258 |
^ OperatingSystem getNullDevice |
3171 | 1259 |
|
1260 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1261 |
! |
|
1262 |
||
615 | 1263 |
parentDirectoryName |
1264 |
"return the name used for the parent directory. |
|
1265 |
This is '..' for unix and dos-like systems. |
|
1266 |
(there may be more in the future." |
|
1267 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1268 |
self isAbstract ifTrue:[ |
8668 | 1269 |
^ ConcreteClass parentDirectoryName |
2906 | 1270 |
]. |
1271 |
||
1272 |
^ OperatingSystem parentDirectoryName |
|
1273 |
||
1274 |
" |
|
1275 |
Filename parentDirectoryName |
|
1276 |
" |
|
1277 |
||
1278 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1279 |
! |
1280 |
||
1281 |
separator |
|
1282 |
"return the file/directory separator. |
|
2906 | 1283 |
This is to be redefined in concrete classes; |
1284 |
the following default usually leads to a flat view of |
|
1285 |
the fileSystem (huh - BS2000 ?)" |
|
1286 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1287 |
self isAbstract ifTrue:[ |
8243 | 1288 |
^ ConcreteClass separator |
1289 |
]. |
|
1290 |
^ $_ |
|
1291 |
||
1292 |
" |
|
8754 | 1293 |
Filename separator |
1294 |
PCFilename separator |
|
8243 | 1295 |
" |
2906 | 1296 |
|
1297 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1298 |
! |
1299 |
||
8243 | 1300 |
separatorString |
1301 |
"return the file/directory separator as a string." |
|
1302 |
||
1303 |
^ self separator asString |
|
1304 |
||
1305 |
" |
|
1306 |
Filename separatorString |
|
1307 |
" |
|
1308 |
! |
|
1309 |
||
615 | 1310 |
suffixSeparator |
1311 |
"return the filename suffix separator. |
|
1312 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 1313 |
(there is currently no known system, where this differs)" |
615 | 1314 |
|
1315 |
^ $. |
|
1316 |
||
1317 |
" |
|
1318 |
Filename suffixSeparator |
|
1319 |
" |
|
1320 |
||
1321 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1322 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1323 |
! |
1324 |
||
2906 | 1325 |
tempFileNameTemplate |
1326 |
"return a template for temporary files. |
|
1327 |
This is expanded with the current processID and a sequenceNumber |
|
1328 |
to generate a unique filename." |
|
1329 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1330 |
self isAbstract ifTrue:[ |
8668 | 1331 |
^ ConcreteClass tempFileNameTemplate |
2906 | 1332 |
]. |
1333 |
||
1334 |
^ 'stxtmp_%1_%2' |
|
1335 |
||
1336 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1337 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1338 |
! |
|
1339 |
||
615 | 1340 |
volumes |
1341 |
"ST-80 compatibility. |
|
2896 | 1342 |
GUESS: does it return the available drives on MSDOS systems ? |
1343 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1344 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1345 |
self isAbstract ifTrue:[ |
8679 | 1346 |
^ ConcreteClass volumes |
2906 | 1347 |
]. |
1348 |
||
2896 | 1349 |
^ OperatingSystem getDriveList |
615 | 1350 |
|
8679 | 1351 |
" |
1352 |
Filename volumes |
|
1353 |
" |
|
615 | 1354 |
! ! |
1355 |
||
6383 | 1356 |
!Filename class methodsFor:'utilities'! |
1357 |
||
6802 | 1358 |
nameFromComponents:aCollectionOfDirectoryNames |
1359 |
"return a filenameString from components given in aCollectionOfDirectoryNames. |
|
1360 |
If the first component is the name of the root directory (i.e. '/'), |
|
1361 |
an absolute path-string is returned." |
|
1362 |
||
1363 |
|sep s| |
|
1364 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1365 |
self isAbstract ifTrue:[ |
6802 | 1366 |
^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames |
1367 |
]. |
|
1368 |
||
1369 |
"/ fallBack - works on Unix & MSDOS |
|
1370 |
||
8243 | 1371 |
sep := self separatorString. |
6802 | 1372 |
s := ''. |
1373 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
|
1374 |
index == 1 ifTrue:[ |
|
7074 | 1375 |
s := component. |
1376 |
] ifFalse:[ |
|
1377 |
(index == 2 and:[ (s endsWith:sep) ]) ifTrue:[ |
|
6802 | 1378 |
s := s , component |
7074 | 1379 |
] ifFalse:[ |
1380 |
s := s , sep , component |
|
6802 | 1381 |
] |
1382 |
]. |
|
1383 |
]. |
|
1384 |
^ s |
|
1385 |
||
1386 |
" |
|
1387 |
Filename nameFromComponents:#('/' 'foo' 'bar' 'baz') |
|
1388 |
Filename nameFromComponents:#('foo' 'bar' 'baz') |
|
7074 | 1389 |
Filename nameFromComponents:#('/') |
1390 |
||
1391 |
|comps| |
|
1392 |
comps := Filename components:'/foo/bar/baz'. |
|
1393 |
Filename nameFromComponents:comps |
|
1394 |
||
1395 |
|comps| |
|
1396 |
comps := Filename components:'\foo\bar\baz'. |
|
1397 |
Filename nameFromComponents:comps |
|
1398 |
||
1399 |
|comps| |
|
1400 |
comps := Filename components:'c:\foo\bar\baz'. |
|
1401 |
Filename nameFromComponents:comps |
|
1402 |
||
1403 |
|comps| |
|
1404 |
comps := Filename components:'foo\bar\baz'. |
|
1405 |
Filename nameFromComponents:comps |
|
1406 |
||
1407 |
|comps| |
|
1408 |
comps := Filename components:'foo'. |
|
1409 |
Filename nameFromComponents:comps |
|
1410 |
||
1411 |
|comps| |
|
1412 |
comps := Filename components:'\'. |
|
1413 |
Filename nameFromComponents:comps |
|
1414 |
||
1415 |
|comps| |
|
1416 |
comps := Filename components:'c:\'. |
|
1417 |
Filename nameFromComponents:comps |
|
6802 | 1418 |
" |
1419 |
||
1420 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
1421 |
! |
|
1422 |
||
6383 | 1423 |
readingFile:aPathName do:aBlock |
1424 |
"create a read-stream on a file, evaluate aBlock, passing that stream, |
|
1425 |
and return the blocks value. |
|
1426 |
Ensures that the stream is closed." |
|
1427 |
||
6529 | 1428 |
^ aPathName asFilename readingFileDo:aBlock. |
1429 |
||
1430 |
" |
|
1431 |
read the first line from some file: |
|
1432 |
||
1433 |
|rslt| |
|
1434 |
||
1435 |
rslt := |
|
1436 |
Filename |
|
1437 |
readingFile:'/etc/passwd' |
|
1438 |
do:[:s | |
|
1439 |
s nextLine |
|
1440 |
]. |
|
1441 |
Transcript showCR:rslt. |
|
1442 |
" |
|
1443 |
||
1444 |
" |
|
1445 |
find all used shells in /etc/passwd and count their usage: |
|
1446 |
||
6383 | 1447 |
|rslt| |
1448 |
||
6529 | 1449 |
rslt := |
1450 |
Filename |
|
1451 |
readingFile:'/etc/passwd' |
|
1452 |
do: |
|
1453 |
[:s | |
|
1454 |
|shells| |
|
1455 |
||
1456 |
shells := Bag new. |
|
1457 |
s linesDo: |
|
1458 |
[:line | |
|
1459 |
|parts| |
|
1460 |
||
1461 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
1462 |
shells add:(parts seventh). |
|
1463 |
]. |
|
1464 |
shells contents |
|
1465 |
]. |
|
1466 |
Transcript showCR:rslt. |
|
1467 |
" |
|
6383 | 1468 |
! ! |
1469 |
||
7261 | 1470 |
!Filename methodsFor:'Compatibility-VW5.4'! |
6139 | 1471 |
|
1472 |
asLogicalFileSpecification |
|
1473 |
^ self |
|
1474 |
||
1475 |
"Created: / 30.10.2001 / 17:31:10 / cg" |
|
6447 | 1476 |
! |
1477 |
||
10583 | 1478 |
canBeWritten |
1479 |
"same as isWritable - for ST-80 compatibility" |
|
1480 |
||
1481 |
^ self isWritable |
|
1482 |
||
1483 |
" |
|
1484 |
'/foo/bar' asFilename canBeWritten |
|
1485 |
'/tmp' asFilename canBeWritten |
|
1486 |
'Makefile' asFilename canBeWritten |
|
1487 |
" |
|
1488 |
! |
|
1489 |
||
7596 | 1490 |
definitelyExists |
1491 |
"for now - a kludge" |
|
1492 |
||
1493 |
^ self exists |
|
1494 |
! |
|
1495 |
||
6447 | 1496 |
extension |
6454 | 1497 |
"return the receiver's extension; |
1498 |
that is the characters from and including |
|
1499 |
the last period or nil, if there is none." |
|
1500 |
||
1501 |
|string idx| |
|
1502 |
||
1503 |
string := self asString. |
|
1504 |
idx := string lastIndexOf:$.. |
|
1505 |
idx > 1 ifTrue:[ |
|
1506 |
^ string copyFrom:idx |
|
1507 |
]. |
|
1508 |
^ nil |
|
1509 |
||
1510 |
" |
|
1511 |
'foo.html' asFilename extension |
|
1512 |
'foo.bar' asFilename extension |
|
1513 |
'foo.bar.baz' asFilename extension |
|
1514 |
'foo.' asFilename extension |
|
1515 |
'foo' asFilename extension |
|
1516 |
'.login' asFilename extension |
|
1517 |
" |
|
6139 | 1518 |
! ! |
1519 |
||
615 | 1520 |
!Filename methodsFor:'comparing'! |
1521 |
||
1522 |
= aFilename |
|
1523 |
"return true, if the argument represents the same filename" |
|
1524 |
||
1525 |
|str| |
|
1526 |
||
1527 |
self species == aFilename species ifTrue:[ |
|
9453 | 1528 |
str := aFilename asString. |
1529 |
self class isCaseSensitive ifTrue:[ |
|
1530 |
^ nameString = str |
|
1531 |
]. |
|
1532 |
^ nameString sameAs:str |
|
615 | 1533 |
]. |
1534 |
^ false |
|
1535 |
! |
|
1536 |
||
5877 | 1537 |
contentsIsPrefixOf:aFilename |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1538 |
"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
|
1539 |
is the same as or a prefix of the contents of the file represented by the argument, aFilename. |
3868 | 1540 |
This compares the files actual contents; not the filenames." |
1541 |
||
8771 | 1542 |
|f2 s1 s2 bufferSize buffer1 buffer2 n| |
1543 |
||
1544 |
bufferSize := 8192 * 4. |
|
4979 | 1545 |
|
1546 |
f2 := aFilename asFilename. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1547 |
self fileSize > f2 fileSize ifTrue:[^ false]. |
3868 | 1548 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1549 |
[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1550 |
s1 := self readStream. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1551 |
s2 := f2 readStream. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1552 |
s1 binary. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1553 |
s2 binary. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1554 |
|
8771 | 1555 |
buffer1 := ByteArray new:bufferSize. |
1556 |
buffer2 := ByteArray new:bufferSize. |
|
7776 | 1557 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1558 |
[s1 atEnd] whileFalse:[ |
8771 | 1559 |
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
|
1560 |
n == 0 ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1561 |
"/ receiver shorter. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1562 |
^ true |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1563 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1564 |
(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
|
1565 |
"/ aFilename shorter |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1566 |
^ false |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1567 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1568 |
buffer1 ~= buffer2 ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1569 |
^ false |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1570 |
] |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1571 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1572 |
"/ receiver shorter or same size. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1573 |
] ensure:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1574 |
s1 notNil ifTrue:[s1 close]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1575 |
s2 notNil ifTrue:[s2 close]. |
3868 | 1576 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1577 |
^ true |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1578 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1579 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1580 |
|s| |
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 := 'testFile1' 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 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1588 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1589 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1590 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1591 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1592 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1593 |
|
5877 | 1594 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1595 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1596 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1597 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1598 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1599 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1600 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1601 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1602 |
|
5877 | 1603 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1604 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1605 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1606 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1607 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1608 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1609 |
|
5877 | 1610 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1611 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1612 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1613 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1614 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1615 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1616 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1617 |
|
5877 | 1618 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
1619 |
||
1620 |
" |
|
1621 |
! |
|
1622 |
||
1623 |
contentsStartsWithContentsOf:aFilename |
|
1624 |
"return true if the contents of the file represented by aFilename |
|
1625 |
is the same as or a prefix of the contents of the file represented by the receiver. |
|
1626 |
This compares the files actual contents; not the filenames." |
|
1627 |
||
1628 |
^ aFilename asFilename contentsIsPrefixOf:self |
|
1629 |
||
1630 |
" |
|
1631 |
|s| |
|
1632 |
||
1633 |
s := 'testFile1' asFilename writeStream. |
|
1634 |
s nextPutAll:'11111'. |
|
1635 |
s nextPutAll:'22222'. |
|
1636 |
s nextPutAll:'33333'. |
|
1637 |
s close. |
|
1638 |
||
1639 |
s := 'testFile2' asFilename writeStream. |
|
1640 |
s nextPutAll:'11111'. |
|
1641 |
s nextPutAll:'22222'. |
|
1642 |
s nextPutAll:'33333'. |
|
1643 |
s close. |
|
1644 |
||
1645 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1646 |
||
1647 |
s := 'testFile2' asFilename writeStream. |
|
1648 |
s nextPutAll:'11111'. |
|
1649 |
s nextPutAll:'22222'. |
|
1650 |
s nextPutAll:'33333'. |
|
1651 |
s nextPutAll:'44444'. |
|
1652 |
s close. |
|
1653 |
||
1654 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1655 |
||
1656 |
s := 'testFile2' asFilename writeStream. |
|
1657 |
s nextPutAll:'11111'. |
|
1658 |
s nextPutAll:'22222'. |
|
1659 |
s close. |
|
1660 |
||
1661 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
1662 |
||
1663 |
s := 'testFile2' asFilename writeStream. |
|
1664 |
s nextPutAll:'11111'. |
|
1665 |
s nextPutAll:'22222'. |
|
1666 |
s nextPutAll:'33334'. |
|
1667 |
s close. |
|
1668 |
||
1669 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1670 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1671 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1672 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1673 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1674 |
hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1675 |
"return an integer useful as a hash-key" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1676 |
|
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
1677 |
self class isCaseSensitive ifFalse:[ |
11425 | 1678 |
^ nameString asUppercase hash |
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
1679 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1680 |
^ nameString hash |
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 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1683 |
sameContentsAs:aFilename |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1684 |
"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
|
1685 |
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
|
1686 |
This compares the files actual contents; not the filenames." |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1687 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1688 |
|f2| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1689 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1690 |
f2 := aFilename asFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1691 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
5877 | 1692 |
^ self contentsIsPrefixOf:f2. |
3868 | 1693 |
|
1694 |
" |
|
1695 |
'Make.proto' asFilename sameContentsAs:'Makefile' |
|
7122 | 1696 |
'Make.proto' asFilename sameContentsAs:'Make.proto' |
3868 | 1697 |
" |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1698 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1699 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1700 |
|s| |
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 := 'testFile1' 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 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1709 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1710 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1711 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1712 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1713 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1714 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifFalse:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1715 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1716 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1717 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1718 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1719 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1720 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1721 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1722 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1723 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1724 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1725 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1726 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1727 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1728 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1729 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1730 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
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 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1733 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1734 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1735 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1736 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1737 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1738 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1739 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1740 |
" |
615 | 1741 |
! ! |
1742 |
||
1743 |
!Filename methodsFor:'converting'! |
|
1744 |
||
1745 |
asAbsoluteFilename |
|
1746 |
"return the receiver converted to a filename with |
|
1747 |
an absolute pathname." |
|
1748 |
||
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
1749 |
^ self class named:self pathName |
7332 | 1750 |
|
1751 |
" |
|
1752 |
'.' asFilename |
|
1753 |
'.' asFilename asAbsoluteFilename |
|
9173 | 1754 |
'c:' asFilename asAbsoluteFilename |
7332 | 1755 |
" |
615 | 1756 |
! |
1757 |
||
10769 | 1758 |
asAutoDeletedFilename |
11784 | 1759 |
^ AutoDeletedFilename basicNew setName:self name |
10769 | 1760 |
! |
1761 |
||
6802 | 1762 |
asCanonicalizedFilename |
1763 |
"return the receiver converted to a filename without intermediate ..'s and .'s |
|
1764 |
(similar to an absolute pathname, but symlinks are not resolved)." |
|
1765 |
||
1766 |
^ self class named:(self class canonicalize:nameString) |
|
7074 | 1767 |
|
1768 |
" |
|
1769 |
'c:\test\work' asFilename asCanonicalizedFilename |
|
1770 |
'/test/work' asFilename asCanonicalizedFilename |
|
1771 |
" |
|
6802 | 1772 |
! |
1773 |
||
615 | 1774 |
asFilename |
1970 | 1775 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 1776 |
|
1777 |
"Thats pretty easy here :-)" |
|
1778 |
^ self |
|
1970 | 1779 |
|
1780 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 1781 |
! |
1782 |
||
1783 |
asString |
|
1784 |
"return the receiver converted to a string" |
|
1785 |
||
1786 |
^ nameString |
|
1787 |
! |
|
1788 |
||
6256 | 1789 |
asURI |
1790 |
"return the receiver converted to a string" |
|
1791 |
||
1792 |
^ FileURI fromFilename:self. |
|
1793 |
! |
|
1794 |
||
5890 | 1795 |
components |
1796 |
"return the receivers filename components - that is the name of each directory |
|
1797 |
along the pathName (that DOES include the root directory)" |
|
1798 |
||
1799 |
^ self class components:self name |
|
1800 |
||
1801 |
" |
|
1802 |
'.' asFilename asAbsoluteFilename components |
|
1803 |
'Makefile' asFilename asAbsoluteFilename components |
|
1804 |
" |
|
1805 |
! |
|
1806 |
||
615 | 1807 |
makeLegalFilename |
1970 | 1808 |
"convert the receivers name to be a legal filename. |
1809 |
This removes/replaces invalid characters and/or compresses |
|
1810 |
the name as required by the OS. |
|
615 | 1811 |
The implementation may change in the future to be more |
1812 |
OS specific." |
|
1813 |
||
1814 |
" |
|
1815 |
actually, in Unix spaces are allowed - but it makes life |
|
1816 |
so hard; therefore, replace them by underscores ... |
|
1817 |
" |
|
3658 | 1818 |
(nameString includes:Character space) ifTrue:[ |
9453 | 1819 |
nameString := nameString copyReplaceAll:(Character space) with:$_. |
3658 | 1820 |
]. |
615 | 1821 |
" |
1822 |
need more - especially on SYS5.3 type systems, |
|
1823 |
we may want to contract the fileName to 14 characters. |
|
1824 |
" |
|
1825 |
^ self |
|
1826 |
||
1827 |
" |
|
1828 |
'hello world' asFilename makeLegalFilename |
|
1829 |
" |
|
1970 | 1830 |
|
3658 | 1831 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
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 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1834 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1835 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1836 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1837 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1838 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1839 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 1840 |
! ! |
1841 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1842 |
!Filename methodsFor:'enumerating-contents'! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1843 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1844 |
allDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1845 |
"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
|
1846 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1847 |
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
|
1848 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1849 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1850 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1851 |
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
|
1852 |
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
|
1853 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1854 |
self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | |
9453 | 1855 |
|eachFileOrDirectory| |
1856 |
||
1857 |
eachFileOrDirectory := self construct:eachFileOrDirectoryName. |
|
1858 |
eachFileOrDirectory isDirectory ifTrue:[ |
|
1859 |
aBlock value:eachFileOrDirectory |
|
1860 |
] |
|
5889
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 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1863 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1864 |
'.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1865 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1866 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1867 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1868 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1869 |
allParentDirectoriesDo:aBlock |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1870 |
"evaluate aBlock for all (recursive) directories along the parent directory path. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1871 |
The block is invoked with a filename-arguments." |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1872 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1873 |
|parent here| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1874 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1875 |
here := self. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1876 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1877 |
[here notNil and:[parent ~= here]] whileTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1878 |
aBlock value:parent. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1879 |
here := parent. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1880 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1881 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1882 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1883 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1884 |
'.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1885 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1886 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1887 |
|
9362 | 1888 |
directories |
1889 |
"return a collection of directories contained in the directory represented by the receiver." |
|
1890 |
||
10557 | 1891 |
^ self directoryContentsAsFilenames |
1892 |
select:[:eachFileOrDirectory | eachFileOrDirectory isDirectory] |
|
9362 | 1893 |
|
1894 |
" |
|
1895 |
'.' asFilename directories. |
|
1896 |
" |
|
10557 | 1897 |
|
1898 |
"Modified: / 29-05-2007 / 12:02:56 / cg" |
|
9362 | 1899 |
! |
1900 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1901 |
directoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1902 |
"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
|
1903 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1904 |
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
|
1905 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1906 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1907 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1908 |
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
|
1909 |
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
|
1910 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1911 |
self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
9453 | 1912 |
eachFileOrDirectory isDirectory ifTrue:[ |
1913 |
aBlock value:eachFileOrDirectory |
|
1914 |
] |
|
5889
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 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1917 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1918 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1919 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1920 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1921 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1922 |
directoryContentsAsFilenamesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1923 |
"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
|
1924 |
The block is invoked with a filename-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1925 |
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
|
1926 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1927 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1928 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1929 |
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
|
1930 |
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
|
1931 |
Notice: this enumerates fileName objects; see also |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1932 |
#directoryContentsDo:, which enumerates strings." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1933 |
|
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
1934 |
self directoryContentsDo:[:entry | |
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
1935 |
aBlock value:(self construct:entry). |
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
1936 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1937 |
|
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 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1940 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1941 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1942 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1943 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1944 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1945 |
|
7464 | 1946 |
directoryContentsDo:aBlock |
1947 |
"evaluate aBlock for each file in the directory represented by the receiver. |
|
1948 |
The block is invoked with a string as argument. |
|
1949 |
The enumerations order is undefined - i.e. usually NOT sorted by |
|
1950 |
filenames (but by creation time - on some systems). |
|
1951 |
This excludes entries for '.' or '..'. |
|
7473 | 1952 |
An exception is raised it the directory does not exist.. |
7464 | 1953 |
So users of this method better test for existing directory before. |
1954 |
Notice: this enumerates strings; see also |
|
1955 |
#directoryContentsAsFilenamesDo:, which enumerates fileName objects." |
|
1956 |
||
1957 |
|s fn| |
|
1958 |
||
7846 | 1959 |
FileStream openErrorSignal |
1960 |
handle:[:ex |] |
|
1961 |
do:[ |
|
1962 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
|
1963 |
]. |
|
1964 |
s isNil ifTrue:[^ self]. |
|
7464 | 1965 |
|
1966 |
[ |
|
1967 |
[s atEnd] whileFalse:[ |
|
1968 |
fn := s nextLine. |
|
1969 |
((fn ~= '.') and:[fn ~= '..']) ifTrue:[ |
|
1970 |
aBlock value:fn |
|
1971 |
] |
|
1972 |
] |
|
1973 |
] ensure:[ |
|
1974 |
s close |
|
1975 |
]. |
|
1976 |
||
1977 |
" |
|
1978 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
7473 | 1979 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
7464 | 1980 |
" |
1981 |
||
1982 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
1983 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
|
1984 |
! |
|
1985 |
||
9382 | 1986 |
files |
9383 | 1987 |
"return a collection of files contained in the directory represented by the receiver." |
9382 | 1988 |
|
10557 | 1989 |
^ self directoryContentsAsFilenames |
1990 |
select:[:eachFileOrDirectory | eachFileOrDirectory isDirectory not] |
|
9382 | 1991 |
|
1992 |
" |
|
1993 |
'.' asFilename files. |
|
1994 |
" |
|
10557 | 1995 |
|
1996 |
"Modified: / 29-05-2007 / 12:02:15 / cg" |
|
9382 | 1997 |
! |
1998 |
||
9806 | 1999 |
filesDo:aBlock |
2000 |
"evaluate aBlock for all files contained in the directory represented by the receiver." |
|
2001 |
||
10557 | 2002 |
^ self directoryContentsAsFilenames |
2003 |
do:[:eachFileOrDirectory | |
|
2004 |
eachFileOrDirectory isDirectory ifFalse:[ aBlock value: eachFileOrDirectory]]. |
|
9806 | 2005 |
|
2006 |
" |
|
2007 |
'.' asFilename filesDo:[:f | Transcript showCR:f]. |
|
2008 |
" |
|
2009 |
||
2010 |
"Created: / 29-08-2006 / 11:03:15 / cg" |
|
10557 | 2011 |
"Modified: / 29-05-2007 / 12:02:46 / cg" |
9806 | 2012 |
! |
2013 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2014 |
recursiveDirectoryContentsDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2015 |
"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
|
2016 |
The block is invoked with a string-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2017 |
The walk is bread-first. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2018 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2019 |
Subdirectory files are included with a relative pathname. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2020 |
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
|
2021 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2022 |
self recursiveDirectoryContentsDo:aBlock directoryPrefix:'' |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2023 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2024 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2025 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2026 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2027 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2028 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2029 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2030 |
"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
|
2031 |
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
|
2032 |
The walk is breadth-first. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2033 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2034 |
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
|
2035 |
A proceedable exception is raised forn non-accessable directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2036 |
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
|
2037 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2038 |
|fileNames dirNames p| |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2039 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2040 |
fileNames := OrderedCollection new. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2041 |
dirNames := OrderedCollection new. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2042 |
self directoryContentsDo:[:f | |t| |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2043 |
t := self construct:f. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2044 |
t isDirectory ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2045 |
t isSymbolicLink ifFalse:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2046 |
dirNames add:f |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2047 |
] |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2048 |
] ifFalse:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2049 |
fileNames add:f |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2050 |
] |
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 |
aPrefix size > 0 ifTrue:[ |
8243 | 2054 |
p := aPrefix , self separator |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2055 |
] ifFalse:[ |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2056 |
p := '' |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2057 |
]. |
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 |
fileNames do:[:aFile | aBlock value:(p , aFile)]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2060 |
dirNames do:[:dN | |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2061 |
aBlock value:(p , dN). |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2062 |
(self construct:dN) |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2063 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN) |
5889
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 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2067 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2068 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2069 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2070 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2071 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2072 |
withAllDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2073 |
"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
|
2074 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2075 |
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
|
2076 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2077 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2078 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2079 |
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
|
2080 |
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
|
2081 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2082 |
self isDirectory ifTrue:[ |
9453 | 2083 |
aBlock value:self. |
2084 |
self allDirectoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2085 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2086 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2087 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2088 |
'.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2089 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2090 |
! ! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2091 |
|
542 | 2092 |
!Filename methodsFor:'error handling'! |
2093 |
||
615 | 2094 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2095 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2096 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2097 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2098 |
|
4820 | 2099 |
|errNo errString| |
2100 |
||
2101 |
errNo := OperatingSystem lastErrorNumber. |
|
2102 |
errString := OperatingSystem lastErrorString. |
|
2103 |
errString size == 0 ifTrue:[ |
|
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2104 |
errString := ''. |
4820 | 2105 |
] ifFalse:[ |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2106 |
errString := ' (' , errString , ')' |
4820 | 2107 |
]. |
2108 |
||
615 | 2109 |
^ OperatingSystem accessDeniedErrorSignal |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2110 |
raiseRequestWith:filename |
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2111 |
errorString:(' : ' , filename asString , errString) |
4820 | 2112 |
|
2113 |
"Modified: / 26.9.1999 / 16:11:44 / cg" |
|
615 | 2114 |
! |
2115 |
||
2116 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2117 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2118 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2119 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2120 |
|
615 | 2121 |
^ OperatingSystem accessDeniedErrorSignal |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2122 |
raiseRequestWith:filename |
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2123 |
errorString:(' - cannot create/write file: ' , filename asString) |
542 | 2124 |
! |
2125 |
||
2126 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2127 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2128 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2129 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2130 |
|
542 | 2131 |
^ OperatingSystem fileNotFoundErrorSignal |
9453 | 2132 |
raiseRequestWith:filename |
2133 |
errorString:('file not found: ' , filename asString) |
|
542 | 2134 |
! |
2135 |
||
2136 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2137 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2138 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2139 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2140 |
|
542 | 2141 |
^ OperatingSystem accessDeniedErrorSignal |
9453 | 2142 |
raiseRequestWith:filename |
2143 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 2144 |
! |
2145 |
||
2146 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2147 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2148 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2149 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2150 |
|
615 | 2151 |
^ OperatingSystem errorSignal |
9453 | 2152 |
raiseRequestWith:filename |
2153 |
errorString:string |
|
615 | 2154 |
! ! |
2155 |
||
2156 |
!Filename methodsFor:'file access'! |
|
2157 |
||
3015 | 2158 |
appendStream |
2159 |
"return a stream for appending to the file represented by the receiver. |
|
2160 |
If the file does not already exist, it is created. |
|
2161 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
2162 |
||
2163 |
^ self appendingWriteStream |
|
2164 |
! |
|
2165 |
||
615 | 2166 |
appendingWriteStream |
2167 |
"return a stream for appending to the file represented by the receiver. |
|
5720 | 2168 |
If the file does not already exist, it is created; |
2169 |
if it does exist, writes are appended at the end." |
|
615 | 2170 |
|
2947 | 2171 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
5720 | 2172 |
|
2173 |
" |
|
2174 |
|s| |
|
2175 |
||
2176 |
s := '/tmp/foo' asFilename writeStream. |
|
2177 |
s nextPutAll:'1234567890'. |
|
2178 |
s close. |
|
2179 |
||
2180 |
s := '/tmp/foo' asFilename appendingWriteStream. |
|
2181 |
s nextPutAll:'abcdef'. |
|
2182 |
s close. |
|
2183 |
||
2184 |
'/tmp/foo' asFilename contents |
|
2185 |
" |
|
615 | 2186 |
! |
2187 |
||
2188 |
newReadWriteStream |
|
2189 |
"return a stream for read/write the file represented by the receiver. |
|
5720 | 2190 |
If the file does not already exist, it is created; |
2191 |
if it does exist, it is truncated." |
|
615 | 2192 |
|
2947 | 2193 |
^ FileStream newFileNamed:(self osNameForAccess) |
5720 | 2194 |
|
2195 |
" |
|
2196 |
|s| |
|
2197 |
||
2198 |
s := '/tmp/foo' asFilename writeStream. |
|
2199 |
s nextPutAll:'1234567890'. |
|
2200 |
s close. |
|
2201 |
||
2202 |
s := '/tmp/foo' asFilename newReadWriteStream. |
|
2203 |
s nextPutAll:'12345'. |
|
2204 |
s close. |
|
2205 |
||
2206 |
'/tmp/foo' asFilename contents |
|
2207 |
" |
|
615 | 2208 |
! |
2209 |
||
2210 |
readStream |
|
2211 |
"return a stream for reading from the file represented by the receiver. |
|
7828 | 2212 |
Raises an error if the file does not exist." |
615 | 2213 |
|
2947 | 2214 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 2215 |
|
2216 |
" |
|
2217 |
'/tmp/foo' asFilename readStream |
|
2218 |
" |
|
2219 |
! |
|
2220 |
||
2221 |
readWriteStream |
|
2222 |
"return a stream for read/write the file represented by the receiver. |
|
7828 | 2223 |
If the file does not already exist, it is created. |
2224 |
If the file does exist, it is NOT truncated, but rewritten at the beginning." |
|
615 | 2225 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2226 |
^ FileStream fileNamed:(self osNameForAccess) |
5720 | 2227 |
|
2228 |
" |
|
2229 |
|s| |
|
2230 |
||
2231 |
s := '/tmp/foo' asFilename writeStream. |
|
2232 |
s nextPutAll:'1234567890'. |
|
2233 |
s close. |
|
2234 |
||
7828 | 2235 |
s := '/tmp/foo' asFilename readWriteStream. |
5720 | 2236 |
s nextPutAll:'abcdef'. |
2237 |
s close. |
|
2238 |
||
2239 |
'/tmp/foo' asFilename contents |
|
7828 | 2240 |
'/tmp/foo' asFilename remove |
5720 | 2241 |
" |
615 | 2242 |
! |
2243 |
||
2244 |
writeStream |
|
2245 |
"return a stream for writing to the file represented by the receiver. |
|
5720 | 2246 |
If the file does not already exist, it is created; |
2247 |
if it does exist, it is truncated." |
|
615 | 2248 |
|
2947 | 2249 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 2250 |
|
2251 |
" |
|
2252 |
'/tmp/foo' asFilename writeStream |
|
2253 |
" |
|
5720 | 2254 |
|
2255 |
" |
|
2256 |
|s| |
|
2257 |
||
2258 |
s := '/tmp/foo' asFilename writeStream. |
|
2259 |
s nextPutAll:'1234567890'. |
|
2260 |
s close. |
|
2261 |
||
2262 |
s := '/tmp/foo' asFilename writeStream. |
|
2263 |
s nextPutAll:'12345'. |
|
2264 |
s close. |
|
2265 |
||
2266 |
'/tmp/foo' asFilename contents |
|
2267 |
" |
|
615 | 2268 |
! ! |
2269 |
||
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2270 |
!Filename methodsFor:'file access - migration'! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2271 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2272 |
appendingWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2273 |
"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
|
2274 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2275 |
if it does exist, writes are appended at the end. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2276 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2277 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2278 |
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
|
2279 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2280 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2281 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2282 |
FileStream appendingOldFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2283 |
] on:FileStream openErrorSignal do:[:ex| nil]. |
8140
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 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2286 |
newReadWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2287 |
"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
|
2288 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2289 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2290 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2291 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2292 |
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
|
2293 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2294 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2295 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2296 |
FileStream newFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2297 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2298 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2299 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2300 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2301 |
"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
|
2302 |
If the file does not already exist, nil is returned. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2303 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2304 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2305 |
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
|
2306 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2307 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2308 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2309 |
FileStream readonlyFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2310 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
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 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2313 |
'/tmp/foo' asFilename readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2314 |
'/tmp/foo' asFilename readStream |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2315 |
" |
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 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2318 |
readWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2319 |
"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
|
2320 |
If the file does not already exist, it is created. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2321 |
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
|
2322 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2323 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2324 |
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
|
2325 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2326 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2327 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2328 |
FileStream fileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2329 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
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 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2332 |
writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2333 |
"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
|
2334 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2335 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2336 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2337 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2338 |
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
|
2339 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2340 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2341 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2342 |
FileStream newFileForWritingNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2343 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2344 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2345 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2346 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2347 |
'/etc/foo' asFilename writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2348 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2349 |
! ! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2350 |
|
6223 | 2351 |
!Filename methodsFor:'file accessRights'! |
615 | 2352 |
|
2353 |
addAccessRights:aCollection |
|
2354 |
"add the access rights as specified in aCollection for the file represented |
|
2355 |
by the receiver. The argument must be a collection of symbols, |
|
2356 |
such as #readUser, #writeGroup etc." |
|
2357 |
||
2922 | 2358 |
|access osName| |
2359 |
||
2947 | 2360 |
osName := self osNameForFile. |
2922 | 2361 |
access := OperatingSystem accessModeOf:osName. |
615 | 2362 |
aCollection do:[:accessSymbol | |
9453 | 2363 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
615 | 2364 |
]. |
2922 | 2365 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
9453 | 2366 |
^ self accessDeniedError:self |
615 | 2367 |
] |
2368 |
||
2369 |
" |
|
2370 |
'foo' asFilename writeStream close. |
|
2371 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
2372 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
2373 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
2374 |
" |
|
2375 |
! |
|
2376 |
||
6223 | 2377 |
makeExecutable |
2378 |
"make the file executable - you must have permission to do so. |
|
2379 |
For directories, execution means: 'allow changing into it'" |
|
2380 |
||
2381 |
^ self addAccessRights:#(executeUser) |
|
2382 |
||
2383 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
2384 |
! |
|
2385 |
||
2386 |
makeExecutableForAll |
|
2387 |
"make the file executable for all - you must have permission to do so. |
|
2388 |
For directories, execution means: 'allow changing into it'" |
|
2389 |
||
2390 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
2391 |
||
2392 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
2393 |
! |
|
2394 |
||
2395 |
makeExecutableForGroup |
|
2396 |
"make the file executable for the group - you must have permission to do so. |
|
2397 |
For directories, execution means: 'allow changing into it'" |
|
2398 |
||
2399 |
^ self addAccessRights:#(executeGroup) |
|
2400 |
||
2401 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
2402 |
! |
|
2403 |
||
2404 |
makeReadable |
|
2405 |
"make the file readable for the owner - you must have permission to do so." |
|
2406 |
||
2407 |
^ self addAccessRights:#(readUser) |
|
2408 |
! |
|
2409 |
||
2410 |
makeReadableForAll |
|
2411 |
"make the file readable for all - you must have permission to do so." |
|
2412 |
||
2413 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
2414 |
! |
|
2415 |
||
2416 |
makeReadableForGroup |
|
2417 |
"make the file readable for the group - you must have permission to do so." |
|
2418 |
||
2419 |
^ self addAccessRights:#(readGroup) |
|
2420 |
! |
|
2421 |
||
2422 |
makeUnwritable |
|
2423 |
"make the file unwritable for all - you must have permission to do so." |
|
2424 |
||
2425 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
2426 |
! |
|
2427 |
||
2428 |
makeWritable |
|
2429 |
"make the file writableable for all - you must have permission to do so." |
|
2430 |
||
2431 |
^ self addAccessRights:#(writeUser) |
|
2432 |
! |
|
2433 |
||
2434 |
makeWritableForAll |
|
2435 |
"make the file writable for all - you must have permission to do so." |
|
2436 |
||
2437 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
2438 |
! |
|
2439 |
||
2440 |
makeWritableForGroup |
|
2441 |
"make the file writable for the group - you must have permission to do so." |
|
2442 |
||
2443 |
^ self addAccessRights:#(writeGroup) |
|
2444 |
! |
|
2445 |
||
2446 |
removeAccessRights:aCollection |
|
2447 |
"remove the access rights as specified in aCollection for the file represented |
|
2448 |
by the receiver. The argument must be a collection of symbols, |
|
2449 |
such as #readUser, #writeGroup etc. |
|
2450 |
Raises an exception if not successful." |
|
2451 |
||
2452 |
|access osName| |
|
2453 |
||
2454 |
osName := self osNameForFile. |
|
2455 |
access := OperatingSystem accessModeOf:osName. |
|
2456 |
aCollection do:[:accessSymbol | |
|
9453 | 2457 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
6223 | 2458 |
]. |
2459 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
|
9453 | 2460 |
^ self accessDeniedError:self |
6223 | 2461 |
]. |
2462 |
||
2463 |
" |
|
2464 |
'foo' asFilename writeStream close. |
|
2465 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
2466 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
2467 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
2468 |
" |
|
2469 |
||
2470 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2471 |
! |
|
2472 |
||
2473 |
symbolicAccessRights |
|
2474 |
"return the access rights of the file as a aCollection of access symbols. |
|
2475 |
The returned collection consists of symbols like: |
|
2476 |
#readUser, #writeGroup etc." |
|
2477 |
||
2478 |
|access osName| |
|
2479 |
||
2480 |
osName := self osNameForFile. |
|
2481 |
access := OperatingSystem accessModeOf:osName. |
|
2482 |
||
2483 |
^ |
|
2484 |
#( readUser writeUser executeUser |
|
2485 |
readGroup writeGroup executeGroup |
|
2486 |
readOthers writeOthers executeOthers |
|
2487 |
) select:[:eachSymbolicAccessSymbol | |
|
2488 |
access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol). |
|
2489 |
]. |
|
2490 |
||
2491 |
" |
|
2492 |
'Makefile' asFilename symbolicAccessRights |
|
2493 |
" |
|
2494 |
||
2495 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2496 |
! |
|
2497 |
||
2498 |
symbolicAccessRights:aCollectionOfSymbols |
|
2499 |
"set the access rights of the file given a aCollection of access symbols. |
|
2500 |
The collection must consist of symbols like: |
|
2501 |
#readUser, #writeGroup etc." |
|
2502 |
||
2503 |
|access osName| |
|
2504 |
||
2505 |
osName := self osNameForFile. |
|
2506 |
access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol | |
|
2507 |
bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol) |
|
2508 |
]. |
|
2509 |
||
2510 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
|
2511 |
^ self accessDeniedError:self |
|
2512 |
]. |
|
2513 |
||
2514 |
" |
|
2515 |
|rights| |
|
2516 |
||
2517 |
rights := 'Makefile' asFilename symbolicAccessRights. |
|
2518 |
'Makefile' asFilename symbolicAccessRights:(rights , #(executeOthers)). |
|
2519 |
" |
|
2520 |
||
2521 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2522 |
! ! |
|
2523 |
||
2524 |
!Filename methodsFor:'file operations'! |
|
2525 |
||
7329 | 2526 |
appendTo:newNameOrStream |
2527 |
"append the file - the argument must be convertable to a filename. |
|
2528 |
Raises an exception, if an error occurs." |
|
2529 |
||
2530 |
|inStream outStream outStreamToClose| |
|
2531 |
||
2532 |
inStream := self readStream. |
|
8769 | 2533 |
inStream isNil ifTrue:[ |
2534 |
^ self fileNotFoundError:self |
|
2535 |
]. |
|
2536 |
||
7329 | 2537 |
[ |
2538 |
newNameOrStream isStream ifTrue:[ |
|
2539 |
outStream := newNameOrStream. |
|
2540 |
] ifFalse:[ |
|
2541 |
outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream. |
|
2542 |
]. |
|
2543 |
||
8769 | 2544 |
inStream binary. |
2545 |
outStream binary. |
|
2546 |
||
7329 | 2547 |
[ |
2548 |
inStream copyToEndInto:outStream. |
|
2549 |
] on:OperatingSystem errorSignal do:[:ex| |
|
2550 |
^ self fileCreationError:newNameOrStream |
|
2551 |
] |
|
2552 |
] ensure:[ |
|
2553 |
inStream close. |
|
2554 |
outStreamToClose notNil ifTrue:[outStreamToClose close]. |
|
2555 |
]. |
|
2556 |
||
2557 |
" |
|
2558 |
'/etc/group' asFilename appendTo:'/tmp/Makefile.foo'. |
|
2559 |
'Makefile' asFilename appendTo:'/tmp/Makefile.foo' |
|
2560 |
'Makefile' asFilename copyTo:'/' |
|
2561 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
2562 |
" |
|
2563 |
||
2564 |
"Modified: / 23.12.1999 / 21:52:36 / cg" |
|
2565 |
! |
|
2566 |
||
2982 | 2567 |
basicMakeDirectory |
2568 |
"create a directory with the receivers name. |
|
2569 |
Return true if successful, false if not." |
|
2570 |
||
2571 |
^ OperatingSystem createDirectory:(self osNameForDirectory) |
|
2572 |
! |
|
2573 |
||
10020 | 2574 |
copyTo:newNameArg |
9235 | 2575 |
"Copy the files contents into another file. |
2576 |
The argument must be convertable to a filename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2577 |
Raises an exception, if an error occurs." |
615 | 2578 |
|
10020 | 2579 |
|newName inStream outStream| |
2580 |
||
2581 |
newName := newNameArg asFilename. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2582 |
|
8535 | 2583 |
"Contents is not copied if newName represent same file as me." |
10020 | 2584 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
8535 | 2585 |
|
615 | 2586 |
inStream := self readStream. |
8535 | 2587 |
inStream isNil ifTrue:[ |
2588 |
^ self fileNotFoundError:self |
|
2589 |
]. |
|
8769 | 2590 |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2591 |
[ |
10020 | 2592 |
outStream := newName writeStream. |
8535 | 2593 |
outStream isNil ifTrue:[ |
10020 | 2594 |
^ self fileCreationError:newName |
8535 | 2595 |
]. |
8769 | 2596 |
inStream binary. |
2597 |
outStream binary. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2598 |
|
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2599 |
[ |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2600 |
inStream copyToEndInto:outStream. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2601 |
] on:OperatingSystem errorSignal do:[:ex| |
10020 | 2602 |
^ self fileCreationError:newName |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2603 |
] |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2604 |
] ensure:[ |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2605 |
inStream close. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2606 |
outStream notNil ifTrue:[outStream close]. |
615 | 2607 |
]. |
2608 |
||
2609 |
" |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2610 |
'Makefile' asFilename copyTo:'/tmp/Makefile.foo' |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2611 |
'Makefile' asFilename copyTo:'/' |
615 | 2612 |
'smalltalk' asFilename copyTo:'/dev/null' |
2613 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2614 |
|
10020 | 2615 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
2616 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
615 | 2617 |
! |
2618 |
||
6983 | 2619 |
createAsEmptyFile |
2620 |
"create an empty file with the receivers name. |
|
2621 |
Raises an exception if not successful |
|
2622 |
(either already existing or creation not possible)" |
|
2623 |
||
2624 |
|writeStream| |
|
2625 |
||
2626 |
self exists ifTrue:[ |
|
2627 |
OperatingSystem accessDeniedErrorSignal |
|
2628 |
raiseRequestWith:self |
|
2629 |
errorString:(' - file exists: ' , self asString). |
|
2630 |
^ self |
|
2631 |
]. |
|
2632 |
||
2633 |
FileStream openErrorSignal handle:[:ex| |
|
2634 |
self fileCreationError:self. |
|
2635 |
^ self |
|
2636 |
] do:[ |
|
2637 |
writeStream := self newReadWriteStream. |
|
2638 |
]. |
|
2639 |
writeStream close. |
|
2640 |
! |
|
2641 |
||
615 | 2642 |
delete |
2643 |
"remove the file - same as remove, for ST-80 compatibility" |
|
2644 |
||
2645 |
self remove |
|
2646 |
! |
|
2647 |
||
2648 |
makeDirectory |
|
2649 |
"create a directory with the receivers name. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2650 |
Raises an exception if not successful" |
615 | 2651 |
|
2982 | 2652 |
(self basicMakeDirectory) ifFalse:[ |
9453 | 2653 |
"/ |
2654 |
"/ could have existed before ... |
|
2655 |
"/ |
|
2656 |
(self exists and:[self isDirectory]) ifFalse:[ |
|
2657 |
self fileCreationError:self. |
|
2658 |
^ false |
|
2659 |
] |
|
2982 | 2660 |
]. |
2661 |
^ true |
|
1970 | 2662 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2663 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 2664 |
! |
2665 |
||
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2666 |
moveFileTo:newName |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2667 |
"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
|
2668 |
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
|
2669 |
Raise an exception if not successful. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2670 |
(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
|
2671 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2672 |
[self renameTo:newName] |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2673 |
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
|
2674 |
do:[:ex | |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2675 |
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
|
2676 |
ex reject |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2677 |
]. |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2678 |
self copyTo:newName. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2679 |
self remove |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2680 |
]. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2681 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2682 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2683 |
|f s| |
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 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2686 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2687 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2688 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2689 |
f renameTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2690 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2691 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2692 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2693 |
|f s| |
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 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2696 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2697 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2698 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2699 |
f moveTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2700 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2701 |
! |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2702 |
|
615 | 2703 |
moveTo:newName |
2704 |
"copy the file represented by the receiver, then delete it. |
|
2705 |
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
|
2706 |
Raise an exception if not successful. |
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
2707 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
615 | 2708 |
|
6771 | 2709 |
[self renameTo:newName] |
2710 |
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
|
2711 |
do:[:ex | |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2712 |
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
|
2713 |
ex reject |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2714 |
]. |
10836
861c0030d55b
dont try to copy-delete if the rename failed due to accessdenied
sr
parents:
10813
diff
changeset
|
2715 |
ex signal == OperatingSystem accessDeniedErrorSignal ifTrue:[ |
861c0030d55b
dont try to copy-delete if the rename failed due to accessdenied
sr
parents:
10813
diff
changeset
|
2716 |
ex reject |
861c0030d55b
dont try to copy-delete if the rename failed due to accessdenied
sr
parents:
10813
diff
changeset
|
2717 |
]. |
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2718 |
|
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
2719 |
self isDirectory ifTrue:[ |
6997 | 2720 |
self recursiveMoveDirectoryTo:newName. |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
2721 |
] ifFalse:[ |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2722 |
self moveFileTo:newName. |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
2723 |
]. |
6771 | 2724 |
]. |
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2725 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2726 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2727 |
|f s| |
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 |
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
|
2730 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2731 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2732 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2733 |
f renameTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2734 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2735 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2736 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2737 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2738 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2739 |
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
|
2740 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2741 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2742 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2743 |
f moveTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2744 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2745 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2746 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2747 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2748 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2749 |
Otherwise, copy the directory and recursively |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2750 |
and recursively all of its subfiles/subdirectories. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2751 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2752 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2753 |
|ok d| |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2754 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2755 |
self isDirectory ifFalse:[ |
9453 | 2756 |
d := destination asFilename. |
2757 |
(d exists and:[d isDirectory]) ifTrue:[ |
|
2758 |
d := d construct:self baseName. |
|
2759 |
]. |
|
2760 |
^ self copyTo:d |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2761 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2762 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2763 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2764 |
"/ 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
|
2765 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2766 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2767 |
ok := OperatingSystem |
9453 | 2768 |
recursiveCopyDirectory:(self osNameForDirectory) |
2769 |
to:(destination asFilename osNameForDirectory). |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2770 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2771 |
ok ifFalse:[ |
9453 | 2772 |
self recursiveCopyWithoutOSCommandTo:destination |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2773 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2774 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2775 |
"Created: / 5.5.1999 / 13:35:01 / cg" |
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2776 |
"Modified: / 31.5.1999 / 13:11:34 / cg" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2777 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2778 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2779 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2780 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2781 |
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
|
2782 |
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
|
2783 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2784 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2785 |
|destinationFilename d| |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2786 |
|
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2787 |
d := destination asFilename. |
4246 | 2788 |
"/ (d exists and:[d isDirectory]) ifTrue:[ |
2789 |
"/ d := d construct:self baseName. |
|
2790 |
"/ ]. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2791 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2792 |
self isDirectory ifTrue:[ |
11192
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2793 |
d asFilename exists ifFalse:[ |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2794 |
destinationFilename := d asFilename. |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2795 |
] ifTrue:[ |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2796 |
destinationFilename := d asFilename construct:self baseName. |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2797 |
]. |
9453 | 2798 |
destinationFilename makeDirectory. |
2799 |
self directoryContents do:[:aFilenameString | |
|
2800 |
|src dst| |
|
2801 |
||
2802 |
src := self construct:aFilenameString. |
|
2803 |
src isDirectory ifTrue:[ |
|
2804 |
src recursiveCopyWithoutOSCommandTo:destinationFilename |
|
2805 |
] ifFalse:[ |
|
2806 |
src copyTo:(destinationFilename construct:aFilenameString) |
|
2807 |
]. |
|
2808 |
] |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2809 |
] ifFalse:[ |
9453 | 2810 |
self copyTo:d |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2811 |
] |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2812 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2813 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2814 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2815 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2816 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2817 |
|
4246 | 2818 |
"Modified: / 31.5.1999 / 18:12:31 / cg" |
615 | 2819 |
! |
2820 |
||
659 | 2821 |
recursiveMakeDirectory |
2822 |
"create a directory with the receivers name and all required intermediate |
|
2823 |
directories. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2824 |
Raises an exception if not successful." |
659 | 2825 |
|
2922 | 2826 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
9453 | 2827 |
^ self fileCreationError:self |
659 | 2828 |
] |
2829 |
||
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2830 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2831 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
659 | 2832 |
! |
2833 |
||
6997 | 2834 |
recursiveMoveDirectoryTo:newName |
2835 |
"recursively copy the directory represented by the receiver, then delete it. |
|
2836 |
This is different to renaming in case of cross device moves. |
|
2837 |
Raise an exception if not successful. |
|
2838 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
|
2839 |
||
2840 |
[self renameTo:newName] |
|
2841 |
on:(OperatingSystem errorSignal) |
|
2842 |
do:[ |
|
2843 |
self recursiveCopyTo:newName. |
|
2844 |
self recursiveRemove |
|
2845 |
]. |
|
2846 |
! |
|
2847 |
||
615 | 2848 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2849 |
"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
|
2850 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2851 |
Raise an exception if not successful." |
615 | 2852 |
|
2853 |
|ok| |
|
2854 |
||
3302 | 2855 |
"/ typically, an 'rm -rf' is faster and removes better; |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2856 |
"/ 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
|
2857 |
"/ fallBack doing a manual directory walk. |
3302 | 2858 |
|
2859 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
2860 |
ok ifFalse:[ |
|
9453 | 2861 |
self recursiveRemoveWithoutOSCommand |
3302 | 2862 |
]. |
2863 |
||
2864 |
" |
|
2865 |
'foo' asFilename makeDirectory. |
|
2866 |
'foo/bar' asFilename writeStream close. |
|
2867 |
('foo' asFilename remove) ifFalse:[ |
|
9453 | 2868 |
Transcript showCR:'could not remove foo' |
3302 | 2869 |
] |
2870 |
" |
|
2871 |
" |
|
2872 |
'foo' asFilename makeDirectory. |
|
2873 |
'foo/bar' asFilename writeStream close. |
|
2874 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
9453 | 2875 |
Transcript showCR:'could not remove foo' |
3302 | 2876 |
] |
2877 |
" |
|
2878 |
||
2879 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2880 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 2881 |
! |
2882 |
||
2883 |
recursiveRemoveWithoutOSCommand |
|
2884 |
"if I represent a regular file, remove it. |
|
2885 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
2886 |
Raise an error if not successful. |
|
2887 |
This one walks down the directory hierarchy, not using any OS |
|
2888 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2889 |
|
4939 | 2890 |
|files| |
2891 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2892 |
self isDirectory ifTrue:[ |
9453 | 2893 |
(files := self directoryContents) size > 0 ifTrue:[ |
2894 |
files do:[:aFilenameString | |
|
2895 |
|f| |
|
2896 |
||
2897 |
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
|
2898 |
Error handle:[:ex | |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2899 |
f isDirectory ifFalse:[ ex reject ]. |
9453 | 2900 |
f recursiveRemoveWithoutOSCommand |
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2901 |
] do:[ |
9453 | 2902 |
f remove |
2903 |
]. |
|
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2904 |
|
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2905 |
"/ f isDirectory ifTrue:[ |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2906 |
"/ f recursiveRemoveWithoutOSCommand |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2907 |
"/ ] ifFalse:[ |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2908 |
"/ f remove |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2909 |
"/ ]. |
9453 | 2910 |
]. |
2911 |
] |
|
615 | 2912 |
]. |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2913 |
self remove |
615 | 2914 |
|
2915 |
" |
|
2916 |
'foo' asFilename makeDirectory. |
|
2917 |
'foo/bar' asFilename writeStream close. |
|
4940 | 2918 |
'foo' asFilename remove |
615 | 2919 |
" |
2920 |
" |
|
2921 |
'foo' asFilename makeDirectory. |
|
2922 |
'foo/bar' asFilename writeStream close. |
|
4940 | 2923 |
'foo' asFilename recursiveRemove |
615 | 2924 |
" |
2925 |
||
3302 | 2926 |
"Created: / 25.2.1998 / 19:50:40 / cg" |
2927 |
"Modified: / 25.2.1998 / 19:52:08 / cg" |
|
615 | 2928 |
! |
2929 |
||
2930 |
remove |
|
845 | 2931 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2932 |
Raises an exception if not successful. |
845 | 2933 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 2934 |
|
8741 | 2935 |
|linkInfo osName ok| |
2936 |
||
2937 |
osName := self osNameForFile. |
|
2938 |
linkInfo := self linkInfo. |
|
2939 |
(linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[ |
|
2940 |
ok := OperatingSystem removeDirectory:osName |
|
615 | 2941 |
] ifFalse:[ |
8741 | 2942 |
ok := OperatingSystem removeFile:osName |
615 | 2943 |
]. |
2944 |
ok ifFalse:[ |
|
6392
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
2945 |
self exists ifTrue:[ |
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
2946 |
self removeError:self |
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
2947 |
] |
615 | 2948 |
]. |
2949 |
||
2950 |
" |
|
2951 |
(FileStream newFileNamed:'foo') close. |
|
2952 |
'foo' asFilename remove |
|
2953 |
" |
|
2954 |
||
2955 |
" |
|
2956 |
'foo' asFilename makeDirectory. |
|
2957 |
'foo/bar' asFilename writeStream close. |
|
8738 | 2958 |
'foo' asFilename remove. 'expect an exception' |
2959 |
'foo' asFilename recursiveRemove. |
|
615 | 2960 |
" |
2961 |
||
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
2962 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2963 |
"Modified: / 5.5.1999 / 13:41:12 / cg" |
615 | 2964 |
! |
2965 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2966 |
removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2967 |
"remove the directory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2968 |
Raises an exception if not successful (or if its not a directory). |
5596 | 2969 |
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
|
2970 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2971 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2972 |
|ok| |
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 |
ok := OperatingSystem removeDirectory:(self osNameForFile). |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2975 |
ok ifFalse:[ |
9453 | 2976 |
self exists ifFalse:[ ^ self]. |
2977 |
self removeError:self |
|
5595
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 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2981 |
(FileStream newFileNamed:'foo') close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2982 |
'foo' asFilename removeDirectory |
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 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2986 |
'foo' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2987 |
'foo' asFilename removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2988 |
" |
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 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2992 |
'foo/bar' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2993 |
('foo' asFilename remove) ifFalse:[ |
9453 | 2994 |
Transcript showCR:'could not remove foo' |
5595
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 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2997 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2998 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2999 |
"Modified: / 5.5.1999 / 13:41:12 / cg" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3000 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3001 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3002 |
removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3003 |
"remove the file. |
5596 | 3004 |
Raises an exception if not successful (or if its not a file). |
3005 |
Use #remove if it is not known if the receiver is a directory or file. |
|
3006 |
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
|
3007 |
|
8738 | 3008 |
(OperatingSystem removeFile:self osNameForFile) ifFalse:[ |
3009 |
self exists ifTrue:[ |
|
3010 |
self removeError:self |
|
3011 |
]. |
|
5595
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 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3015 |
(FileStream newFileNamed:'foo') close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3016 |
'foo' asFilename removeFile |
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 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3019 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3020 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3021 |
'foo' asFilename removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3022 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3023 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3024 |
|
5086 | 3025 |
renameOrCopyTo:newName |
3026 |
"rename or copy the file - the argument must be convertable to a String. |
|
3027 |
Raises an exception if not successful. |
|
3028 |
This does basically the same as #renameTo:, with one exception: |
|
3029 |
if, under unix, the new fileName is on another device, a rename operation |
|
3030 |
fails, and #renameTo: raises an exception; |
|
3031 |
in contrast, this method falls back to copying the file." |
|
3032 |
||
3033 |
|newFilename| |
|
3034 |
||
3035 |
newFilename := newName asFilename. |
|
3036 |
||
3037 |
(OperatingSystem |
|
9453 | 3038 |
renameFile:(self osNameForFile) |
3039 |
to:(newFilename osNameForFile) |
|
5086 | 3040 |
) ifFalse:[ |
9453 | 3041 |
self exists ifFalse:[ |
3042 |
^ self fileNotFoundError:self |
|
3043 |
]. |
|
3044 |
||
3045 |
OperatingSystem isUNIXlike ifTrue:[ |
|
3046 |
OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[ |
|
3047 |
"/ try to copy - and remove the original |
|
3048 |
"/ this helps with cross-device renames. |
|
3049 |
||
3050 |
self copyTo:newName. |
|
3051 |
^ self |
|
3052 |
]. |
|
3053 |
]. |
|
3054 |
^ self accessDeniedError:newName asFilename. |
|
5086 | 3055 |
]. |
3056 |
||
3057 |
" |
|
3058 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
3059 |
" |
|
3060 |
||
3061 |
"Modified: / 5.5.1999 / 13:41:27 / cg" |
|
3062 |
! |
|
3063 |
||
615 | 3064 |
renameTo:newName |
671 | 3065 |
"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
|
3066 |
Raises an exception if not successful." |
615 | 3067 |
|
2922 | 3068 |
(OperatingSystem |
9453 | 3069 |
renameFile:(self osNameForFile) |
3070 |
to:(newName asFilename osNameForFile) |
|
2922 | 3071 |
) ifFalse:[ |
9453 | 3072 |
self exists ifFalse:[ |
3073 |
^ self fileNotFoundError:self |
|
3074 |
]. |
|
3075 |
^ self accessDeniedError:newName asFilename. |
|
615 | 3076 |
]. |
3077 |
||
3078 |
" |
|
3079 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
3080 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3081 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3082 |
"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
|
3083 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3084 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3085 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3086 |
"change the files size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3087 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3088 |
(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
|
3089 |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3090 |
(OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3091 |
^ 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
|
3092 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3093 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3094 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3095 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3096 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3097 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3098 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3099 |
s close. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3100 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3101 |
'test' asFilename truncateTo:100. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3102 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3103 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3104 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3105 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 3106 |
! ! |
3107 |
||
3108 |
!Filename methodsFor:'file queries'! |
|
3109 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3110 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3111 |
"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
|
3112 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3113 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3114 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3115 |
(i := self info) isNil ifTrue:[^ nil]. |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3116 |
^ i accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3117 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3118 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3119 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3120 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3121 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3122 |
"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
|
3123 |
"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
|
3124 |
"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
|
3125 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3126 |
|
6977 | 3127 |
creationTime |
3128 |
"return a timeStamp containing the files creation time. |
|
3129 |
NOTICE: only windoof distinguishes creation from modification; |
|
6978 | 3130 |
under unix, nil is returned (callers should fall back and use mod-time then" |
6977 | 3131 |
|
3132 |
|i| |
|
3133 |
||
3134 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
|
6978 | 3135 |
^ i creationTime |
3136 |
||
3137 |
" |
|
3138 |
Filename currentDirectory creationTime |
|
6977 | 3139 |
" |
3140 |
||
3141 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
|
3142 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
|
3143 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
|
3144 |
! |
|
3145 |
||
615 | 3146 |
dates |
3147 |
"return the files modification and access times as an object (currently a dictionary) |
|
3148 |
that responds to the at: message with arguments |
|
3149 |
#modified, #accessed or #statusChanged." |
|
3150 |
||
2922 | 3151 |
|info dates osName| |
3152 |
||
2947 | 3153 |
osName := self osNameForAccess. |
2922 | 3154 |
info := OperatingSystem infoOf:osName. |
615 | 3155 |
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
|
3156 |
"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
|
3157 |
Answer the dates of the link itself" |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3158 |
info := OperatingSystem linkInfoOf:osName. |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3159 |
info isNil ifTrue:[ |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3160 |
^ nil |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3161 |
] |
615 | 3162 |
]. |
3163 |
dates := IdentityDictionary new. |
|
6978 | 3164 |
dates at:#created put:(info creationTime). |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3165 |
dates at:#modified put:(info modificationTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3166 |
dates at:#accessed put:(info accessTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3167 |
dates at:#statusChanged put:(info statusChangeTime). |
615 | 3168 |
^ dates |
3169 |
||
3170 |
" |
|
6978 | 3171 |
Filename currentDirectory dates |
615 | 3172 |
'../regression' asFilename dates |
3173 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3174 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3175 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 3176 |
! |
3177 |
||
3178 |
fileSize |
|
3179 |
"return the size of the file in bytes" |
|
3180 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3181 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3182 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3183 |
(i := self info) isNil ifTrue:[^ nil]. |
6794
498d85323172
use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents:
6793
diff
changeset
|
3184 |
^ i fileSize |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3185 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3186 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 3187 |
! |
3188 |
||
3189 |
fileType |
|
3190 |
"this returns a string describing the type of contents of |
|
3191 |
the file. This is done using the unix 'file' command, |
|
3192 |
(which usually is configurable by /etc/magic). |
|
3665 | 3193 |
On non-unix systems, this may simply return 'file', |
2922 | 3194 |
not knowning about the contents. |
3195 |
Warning: |
|
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3196 |
Since the returned string differs among systems (and language settings), |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3197 |
it is only useful for user-information; |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3198 |
NOT as a tag to be used by a program." |
3665 | 3199 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3200 |
|buffer s n suffix idx baseNm info| |
3665 | 3201 |
|
3202 |
"/ since we cannot depend on a 'file' command being available, |
|
3203 |
"/ do the most obvious ones here. |
|
3204 |
"/ (also useful since the 'file' command takes some time, and the code |
|
3205 |
"/ 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
|
3206 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3207 |
info := self linkInfo. |
9060 | 3208 |
info isNil ifTrue:[ |
3209 |
^ 'removed' "/ could happen, when coming from a snapshot image |
|
3210 |
]. |
|
3211 |
||
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3212 |
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
|
3213 |
^ 'symbolic link to ' , info path |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3214 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3215 |
info isDirectory ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3216 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3217 |
self isExecutable ifFalse:[^ 'directory, locked']. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3218 |
^ 'directory' |
2573 | 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 isCharacterSpecial ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3221 |
^ 'character device special file' |
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 isBlockSpecial ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3224 |
^ 'block device special file' |
3665 | 3225 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3226 |
info isSocket ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3227 |
^ 'socket' |
3665 | 3228 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3229 |
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
|
3230 |
^ 'fifo' |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3231 |
]. |
3665 | 3232 |
|
1602 | 3233 |
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
|
3234 |
info fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 3235 |
|
2922 | 3236 |
suffix := self suffix asLowercase. |
3237 |
baseNm := self withoutSuffix baseName asLowercase. |
|
3238 |
||
6826 | 3239 |
((#('st' 'rc' 'chg' 'htm' 'html' 'ps' 'cls' 'pac') includes:suffix) |
2922 | 3240 |
or:[#('makefile') includes:baseNm]) ifTrue:[ |
3241 |
||
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
3242 |
buffer := String new:2048. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
3243 |
s := self readStreamOrNil. |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3244 |
s notNil ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3245 |
n := s nextBytes:buffer size into:buffer. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3246 |
s close. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3247 |
buffer := buffer asLowercase. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3248 |
(#('st' 'cls') includes:suffix) ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3249 |
#( |
6826 | 3250 |
('from squeak' 'smalltalk source (Squeak)') |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3251 |
('from dolphin' 'smalltalk source (Dolphin)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3252 |
('from visualworks' 'smalltalk source (VisualWorks)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3253 |
('categoriesforclass' 'smalltalk source (Dolphin)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3254 |
('methodsfor!!' 'smalltalk source (Dolphin, ST/V or V''age)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3255 |
('subclass:' 'smalltalk source') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3256 |
('methodsfor:' 'smalltalk source') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3257 |
) pairsDo:[:pattern :what | |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3258 |
(buffer findString:pattern) ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3259 |
^ what |
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 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3263 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3264 |
(buffer findString:'methodsfor:') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3265 |
^ 'smalltalk changes / method source' |
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 = 'rc') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3269 |
(buffer findString:'st/x startup') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3270 |
^ 'smalltalk startup script' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3271 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3272 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3273 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3274 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3275 |
(idx := buffer findString:'<h') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3276 |
((buffer continuesWith:'<head' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3277 |
or:[(buffer continuesWith:'<html' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3278 |
or:[(buffer continuesWith:'<h1' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3279 |
or:[(buffer continuesWith:'<h2' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3280 |
or:[(buffer continuesWith:'<h3' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3281 |
or:[(buffer continuesWith:'<h4' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3282 |
or:[(buffer continuesWith:'<h5' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3283 |
or:[(buffer continuesWith:'<h6' startingAt:idx)]]]]]]]) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3284 |
ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3285 |
^ 'HTML document text' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3286 |
] |
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 |
]. |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
3289 |
|
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3290 |
(suffix = 'ps') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3291 |
(buffer findString:'%!!ps-adobe') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3292 |
^ 'PostScript document' |
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 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3296 |
(baseNm = 'makefile') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3297 |
(buffer startsWith:'#') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3298 |
^ 'make rules' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3299 |
] |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3300 |
] |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3301 |
] |
1602 | 3302 |
]. |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3303 |
|
2906 | 3304 |
^ 'file' |
615 | 3305 |
|
3306 |
" |
|
3307 |
'Makefile' asFilename fileType |
|
3308 |
'.' asFilename fileType |
|
3665 | 3309 |
'/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
|
3310 |
'/usr/tmp' asFilename fileType |
3665 | 3311 |
'/tmp/.X11-unix/X0' asFilename fileType |
615 | 3312 |
'smalltalk.rc' asFilename fileType |
3313 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3314 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3315 |
|
3665 | 3316 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 3317 |
! |
3318 |
||
2836 | 3319 |
id |
3320 |
"return the files/directories file-id (inode number)" |
|
3321 |
||
2947 | 3322 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 3323 |
|
3324 |
" |
|
3325 |
Filename currentDirectory id |
|
3326 |
" |
|
3327 |
||
3328 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
3329 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
3330 |
! |
|
3331 |
||
615 | 3332 |
info |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3333 |
"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
|
3334 |
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
|
3335 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3336 |
|
9453 | 3337 |
type - a symbol giving the files fileType |
3338 |
mode - numeric access mode |
|
3339 |
uid - owners user id |
|
3340 |
gid - owners group id |
|
3341 |
size - files size |
|
3342 |
id - files number (i.e. inode number) |
|
3343 |
accessed - last access time (as osTime-stamp) |
|
3344 |
modified - last modification time (as osTime-stamp) |
|
3345 |
statusChanged - last staus change (as osTime-stamp) |
|
615 | 3346 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3347 |
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
|
3348 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3349 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
9453 | 3350 |
modified |
3351 |
size |
|
3352 |
type |
|
615 | 3353 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3354 |
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
|
3355 |
to either handle nil values, |
615 | 3356 |
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
|
3357 |
(i.e. instead of: |
9453 | 3358 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3359 |
use |
9453 | 3360 |
someFilename isDirectory |
615 | 3361 |
" |
3362 |
||
2947 | 3363 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 3364 |
|
3365 |
" |
|
3366 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3367 |
'/dev/null' asFilename info |
615 | 3368 |
'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
|
3369 |
'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
|
3370 |
'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
|
3371 |
'../../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
|
3372 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3373 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3374 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3375 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3376 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3377 |
'c:\' asFilename info |
615 | 3378 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3379 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3380 |
"Modified: / 17.8.1998 / 10:24:10 / cg" |
615 | 3381 |
! |
3382 |
||
3383 |
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
|
3384 |
"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
|
3385 |
instead of the link's target. |
615 | 3386 |
The information is the same as returned by #info, except that if the |
3387 |
receiver represents a symbolic link, the links information |
|
3388 |
is returned |
|
3389 |
(while in this case, #info returns the info of the target file, |
|
3390 |
which is accessed via the symbolic link). |
|
3391 |
||
3392 |
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
|
3393 |
path -> the target files pathname |
615 | 3394 |
|
3395 |
See the comment in #info for more details." |
|
3396 |
||
2947 | 3397 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 3398 |
|
3399 |
" |
|
3400 |
Filename currentDirectory linkInfo |
|
3401 |
'/dev/null' asFilename linkInfo |
|
3402 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3403 |
'Make.proto' asFilename linkInfo path |
615 | 3404 |
'source/Point.st' asFilename linkInfo |
3405 |
'../../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
|
3406 |
'/usr/tmp' asFilename linkInfo |
615 | 3407 |
" |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3408 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3409 |
"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
|
3410 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3411 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3412 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3413 |
"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
|
3414 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3415 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3416 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3417 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3418 |
^ i modificationTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3419 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3420 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3421 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3422 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3423 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3424 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3425 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3426 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 3427 |
! |
3428 |
||
3429 |
type |
|
3430 |
"return the symbolic type of the file" |
|
3431 |
||
2947 | 3432 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 3433 |
|
3434 |
" |
|
3435 |
Filename currentDirectory type |
|
3436 |
" |
|
3437 |
||
3438 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
3439 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 3440 |
! ! |
3441 |
||
3442 |
!Filename methodsFor:'file utilities'! |
|
3443 |
||
3444 |
edit |
|
3445 |
"start an editView on the file represented by the receiver" |
|
3446 |
||
3447 |
EditTextView openOn:self asString |
|
3448 |
||
3449 |
" |
|
3450 |
'smalltalk.rc' asFilename edit |
|
3451 |
" |
|
3452 |
! |
|
3453 |
||
3454 |
fileIn |
|
3455 |
"load smalltalk code from the file" |
|
3456 |
||
5200 | 3457 |
|s rslt| |
3458 |
||
3459 |
s := self readStream. |
|
3460 |
[ |
|
6422
d91c6082c200
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6402
diff
changeset
|
3461 |
rslt := s fileIn. |
d91c6082c200
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6402
diff
changeset
|
3462 |
] ensure:[ |
d91c6082c200
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6402
diff
changeset
|
3463 |
s close. |
5200 | 3464 |
]. |
3465 |
^ rslt. |
|
542 | 3466 |
! ! |
3467 |
||
2 | 3468 |
!Filename methodsFor:'instance creation'! |
3469 |
||
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3470 |
/ subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3471 |
"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
|
3472 |
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
|
3473 |
(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
|
3474 |
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
|
3475 |
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
|
3476 |
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
|
3477 |
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
|
3478 |
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
|
3479 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3480 |
^ 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
|
3481 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3482 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3483 |
'/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
|
3484 |
'/' 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
|
3485 |
'/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
|
3486 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3487 |
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
|
3488 |
'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
|
3489 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3490 |
! |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3491 |
|
615 | 3492 |
construct:subname |
3493 |
"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
|
3494 |
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
|
3495 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 3496 |
The argument may not specify an absolute path name. |
3497 |
Please do not use this to create filenames with suffixes, |
|
3498 |
since some systems require special naming conventions. |
|
3499 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 3500 |
|
11784 | 3501 |
|constructedName| |
3502 |
||
3503 |
constructedName := self constructString:subname. |
|
3504 |
^ self class named:constructedName. |
|
615 | 3505 |
|
3506 |
" |
|
3507 |
'/tmp' asFilename construct:'foo' |
|
3508 |
'/' asFilename construct:'foo' |
|
3509 |
'/usr/tmp' asFilename construct:'foo' |
|
3510 |
'/foo/bar' asFilename construct:'baz' |
|
6670 | 3511 |
'/foo/bar' asFilename construct:'baz' asFilename |
2922 | 3512 |
|
3513 |
Bad example; works on UNIX, but may not on others: |
|
11784 | 3514 |
'foo/bar.baz' asFilename construct:'.suff' |
615 | 3515 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3516 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3517 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 3518 |
! |
3519 |
||
2922 | 3520 |
constructDirectory:subname |
3521 |
"same as #construct: on most systems. |
|
3522 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
3523 |
||
3524 |
^ self class named:(self constructDirectoryString:subname) |
|
3525 |
! |
|
3526 |
||
3527 |
constructDirectoryString:subName |
|
3528 |
"same as #constructString: on most systems. |
|
3529 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
3530 |
||
3531 |
^ self constructString:subName |
|
3532 |
! |
|
3533 |
||
3534 |
constructString:subName |
|
2911 | 3535 |
"taking the receiver as a directory name, construct a new |
3536 |
filename-string for an entry within this directory |
|
2922 | 3537 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 3538 |
The argument may not specify an absolute path name. |
3539 |
The code below works for UNIX & MSDOS; |
|
3540 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3541 |
||
3542 |
|sepString sub| |
|
3543 |
||
3544 |
sub := subName asString. |
|
8243 | 3545 |
sepString := self class separatorString. |
3546 |
nameString size == 0 ifTrue:[ |
|
3547 |
^ sub |
|
2911 | 3548 |
]. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3549 |
(nameString endsWith:sepString) ifTrue:[ |
6247 | 3550 |
^ nameString , sub |
3551 |
]. |
|
2960 | 3552 |
^ nameString , sepString , sub |
2911 | 3553 |
|
3554 |
" |
|
3555 |
'/tmp' asFilename constructString:'foo' |
|
3556 |
'/' asFilename constructString:'foo' |
|
3557 |
'/usr/tmp' asFilename constructString:'foo' |
|
3558 |
'/foo/bar' asFilename constructString:'baz' |
|
6247 | 3559 |
'' asFilename constructString:'baz' |
2911 | 3560 |
" |
3561 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3562 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3563 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3564 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3565 |
"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
|
3566 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3567 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3568 |
filenameFor:fileName |
6973 | 3569 |
"return a filename representing the argument, fileName |
3570 |
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
|
3571 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3572 |
|f| |
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 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3575 |
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
|
3576 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3577 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3578 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3579 |
'/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
|
3580 |
'/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
|
3581 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3582 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3583 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
9263 | 3584 |
! |
3585 |
||
3586 |
secureConstruct:subname |
|
3587 |
"taking the receiver as a directory name, construct a new |
|
3588 |
filename for an entry within this directory |
|
3589 |
(i.e. for a file or a subdirectory in that directory). |
|
3590 |
The argument may not specify an absolute path name. |
|
3591 |
Please do not use this to create filenames with suffixes, |
|
3592 |
since some systems require special naming conventions. |
|
3593 |
See also: #withSuffix: (which is different, but often needed). |
|
3594 |
||
3595 |
This method differs from #construct:, by not permitting subName |
|
3596 |
to navigate above (via ..) the current filename." |
|
3597 |
||
3598 |
^ self class named:(self secureConstructString:subname) |
|
3599 |
||
3600 |
" |
|
3601 |
'/tmp' asFilename secureConstruct:'foo' |
|
3602 |
'/tmp' asFilename secureConstruct:'../foo' |
|
3603 |
'/tmp' asFilename secureConstruct:'/./foo' |
|
3604 |
'/tmp' asFilename secureConstruct:'foo/../bar' |
|
3605 |
'/' asFilename secureConstruct:'foo' |
|
3606 |
'/usr/tmp' asFilename secureConstruct:'foo' |
|
3607 |
'/foo/bar' asFilename secureConstruct:'baz' |
|
3608 |
'/foo/bar' asFilename secureConstruct:'baz' asFilename |
|
3609 |
||
3610 |
Bad example; works on UNIX, but may not on others: |
|
3611 |
'foo/bar.baz' secureConstruct:'.suff' |
|
3612 |
" |
|
3613 |
||
3614 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
|
3615 |
! |
|
3616 |
||
3617 |
secureConstructString:subName |
|
3618 |
"taking the receiver as a directory name, construct a new |
|
3619 |
filename-string for an entry within this directory |
|
3620 |
(i.e. for a file or a subdirectory in that directory). |
|
3621 |
||
3622 |
This method differs from #constructString, by not permitting subName |
|
3623 |
to navigate above (via ..) the current filename. |
|
3624 |
||
3625 |
The code below works for UNIX & MSDOS; |
|
3626 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3627 |
||
3628 |
|sepString sub normalizedPath pathStream| |
|
3629 |
||
3630 |
sepString := self class separatorString. |
|
3631 |
sub := subName asString. |
|
3632 |
||
3633 |
sub := sub asCollectionOfSubstringsSeparatedByAll:sepString. |
|
3634 |
normalizedPath := OrderedCollection new:sub size. |
|
3635 |
sub do:[:eachPathComponent| |
|
3636 |
eachPathComponent = '..' ifTrue:[ |
|
3637 |
normalizedPath isEmpty ifTrue:[ |
|
3638 |
self error:'secureConstruct: - trying to escape from: ', nameString. |
|
3639 |
]. |
|
3640 |
normalizedPath removeLast. |
|
3641 |
] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[ |
|
3642 |
normalizedPath add:eachPathComponent. |
|
3643 |
]] |
|
3644 |
]. |
|
3645 |
pathStream := WriteStream with:nameString. |
|
3646 |
(nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[ |
|
3647 |
pathStream nextPutAll:sepString. |
|
3648 |
]. |
|
3649 |
normalizedPath do:[:eachPathComponent| |
|
3650 |
pathStream nextPutAll:eachPathComponent. |
|
3651 |
] separatedBy:[ |
|
3652 |
pathStream nextPutAll:sepString. |
|
3653 |
]. |
|
3654 |
||
3655 |
^ pathStream contents. |
|
3656 |
||
3657 |
" |
|
3658 |
'/tmp' asFilename secureConstructString:'foo' |
|
3659 |
'/tmp' asFilename secureConstructString:'../foo' |
|
3660 |
'/tmp' asFilename secureConstructString:'foo/../bla' |
|
3661 |
'/tmp' asFilename secureConstructString:'foo/./bla' |
|
3662 |
'/tmp' asFilename secureConstructString:'/bla/foo/../../foo' |
|
3663 |
'/' asFilename secureConstructString:'foo' |
|
3664 |
'/usr/tmp' asFilename secureConstructString:'foo' |
|
3665 |
'/foo/bar' asFilename secureConstructString:'baz' |
|
3666 |
'' asFilename secureConstructString:'baz' |
|
3667 |
'' asFilename secureConstructString:'/baz' |
|
3668 |
" |
|
2 | 3669 |
! ! |
3670 |
||
195 | 3671 |
!Filename methodsFor:'misc'! |
3672 |
||
3673 |
, aString |
|
3674 |
"this allows filenames to understand how names are concatenated. |
|
308 | 3675 |
Returns a string consisting of the receivers name, concatenated |
195 | 3676 |
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
|
3677 |
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
|
3678 |
See also: #withSuffix: which is new and better." |
195 | 3679 |
|
5866 | 3680 |
<resource:#obsolete> |
3681 |
||
2906 | 3682 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 3683 |
^ (nameString , aString asString) |
195 | 3684 |
|
3685 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3686 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3687 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3688 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3689 |
'Makefile' asFilename construct:'.bak' |
195 | 3690 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3691 |
|
2906 | 3692 |
"Modified: 7.9.1997 / 23:45:36 / cg" |
9263 | 3693 |
! |
3694 |
||
3695 |
canonicalize |
|
3696 |
"normalize a filename by removing all empty path components or dots, |
|
3697 |
and by resolving parent directory '..' references. |
|
3698 |
||
3699 |
The code below works for UNIX & MSDOS; |
|
3700 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3701 |
||
3702 |
nameString := self class canonicalize:nameString. |
|
3703 |
||
3704 |
" |
|
3705 |
'/tmp/bla' asFilename canonicalize. |
|
3706 |
'/tmp/bla/../fasel' asFilename canonicalize. |
|
3707 |
'/tmp/bla/.././/fasel' asFilename canonicalize. |
|
3708 |
'..' asFilename canonicalize. |
|
3709 |
'bla/../fasel' asFilename canonicalize. |
|
3710 |
'//bla/../fasel' asFilename canonicalize. |
|
3711 |
" |
|
195 | 3712 |
! ! |
3713 |
||
615 | 3714 |
!Filename methodsFor:'printing & storing'! |
174 | 3715 |
|
615 | 3716 |
printOn:aStream |
4392 | 3717 |
"append a user printed representation of the receiver to aStream. |
3718 |
The format is suitable for a human - not meant to be read back." |
|
174 | 3719 |
|
2906 | 3720 |
aStream nextPutAll:(self class name). |
3721 |
aStream nextPutAll:'('''. |
|
615 | 3722 |
nameString printOn:aStream. |
3723 |
aStream nextPutAll:''')' |
|
2906 | 3724 |
|
3725 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 3726 |
! |
3727 |
||
615 | 3728 |
storeOn:aStream |
3729 |
"append a printed representation of the receiver to aStream, |
|
3730 |
which allows reconstructing it via readFrom:" |
|
328 | 3731 |
|
615 | 3732 |
aStream nextPut:$(. |
3733 |
nameString storeOn:aStream. |
|
3734 |
aStream nextPutAll:' asFilename)' |
|
1 | 3735 |
! ! |
3736 |
||
7258 | 3737 |
!Filename methodsFor:'private-accessing'! |
1 | 3738 |
|
6227 | 3739 |
getName |
3740 |
"get the raw filename" |
|
3741 |
||
3742 |
^ nameString |
|
3743 |
! |
|
3744 |
||
68 | 3745 |
setName:aString |
38 | 3746 |
"set the filename" |
3747 |
||
3666 | 3748 |
nameString := self nameWithSpecialExpansions:aString. |
3749 |
||
3750 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 3751 |
! ! |
3752 |
||
2 | 3753 |
!Filename methodsFor:'queries'! |
3754 |
||
68 | 3755 |
exists |
92 | 3756 |
"return true, if such a file exists." |
68 | 3757 |
|
2947 | 3758 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 3759 |
|
85 | 3760 |
" |
92 | 3761 |
'/foo/bar' asFilename exists |
3762 |
'/tmp' asFilename exists |
|
3763 |
'Makefile' asFilename exists |
|
85 | 3764 |
" |
77 | 3765 |
! |
3766 |
||
5928 | 3767 |
filenamesMatching:aPattern |
3768 |
"VW compatibility" |
|
3769 |
||
3770 |
^ (self filesMatching:aPattern) asOrderedCollection |
|
9453 | 3771 |
collect:[:eachName | self construct:eachName] |
5928 | 3772 |
|
3773 |
" |
|
3774 |
'/etc' asFilename filenamesMatching:'a*;c*' |
|
3775 |
" |
|
3776 |
||
3777 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
3778 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
3779 |
! |
|
3780 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3781 |
filesMatching:aPattern |
2550 | 3782 |
"given the receiver, representing a directory; |
3783 |
return a collection of files matching a pattern. |
|
3784 |
The pattern may be a simple matchPattern, or a set of |
|
3785 |
multiple patterns separated by semicolons." |
|
3786 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3787 |
|matchers notCaseSensitive| |
2550 | 3788 |
|
3789 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3790 |
notCaseSensitive := self class isCaseSensitive not. |
2550 | 3791 |
^ self directoryContents |
9453 | 3792 |
select:[:name | |
3793 |
(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0 |
|
3794 |
] |
|
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3795 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3796 |
" |
2550 | 3797 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3798 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3799 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3800 |
"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
|
3801 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 3802 |
! |
3803 |
||
3804 |
filesMatchingWithoutDotDirs:aPattern |
|
3805 |
"given the receiver, representing a directory; |
|
3806 |
return a collection of files matching a pattern. |
|
3807 |
Exclude '.' and '..' from the returned list. |
|
3808 |
The pattern may be a simple matchPattern, or a set of |
|
3809 |
multiple patterns separated by semicolons." |
|
3810 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3811 |
|matchers notCaseSensitive| |
2550 | 3812 |
|
3813 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3814 |
notCaseSensitive := self class isCaseSensitive not. |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3815 |
|
2550 | 3816 |
^ self directoryContents |
9453 | 3817 |
select:[:name | |
3818 |
name ~= '.' |
|
3819 |
and:[name ~= '..' |
|
3820 |
and:[(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0]] |
|
2550 | 3821 |
] |
3822 |
||
3823 |
" |
|
3824 |
Filename currentDirectory filesMatching:'M*' |
|
3825 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
3826 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
3827 |
" |
|
3828 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3829 |
"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
|
3830 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3831 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3832 |
|
9206 | 3833 |
fullAlternativePathName |
3834 |
^ nameString |
|
3835 |
! |
|
3836 |
||
615 | 3837 |
isExecutable |
3838 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
3839 |
For directories, true is returned if the directory can be entered. |
|
3840 |
See isExecutableProgram for a related check." |
|
3841 |
||
2947 | 3842 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 3843 |
|
3844 |
" |
|
3845 |
'/foo/bar' asFilename isExecutable |
|
3846 |
'/tmp' asFilename isExecutable |
|
3847 |
'Makefile' asFilename isExecutable |
|
3848 |
'/bin/ls' asFilename isExecutable |
|
356 | 3849 |
" |
3850 |
! |
|
3851 |
||
615 | 3852 |
isExecutableProgram |
3853 |
"return true, if such a file exists and is an executable program. |
|
3854 |
(i.e. for directories, false is returned.)" |
|
356 | 3855 |
|
2922 | 3856 |
|osName| |
3857 |
||
2947 | 3858 |
osName := self osNameForAccess. |
2922 | 3859 |
^ (OperatingSystem isExecutable:osName) |
3860 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 3861 |
|
3862 |
" |
|
615 | 3863 |
'/tmp' asFilename isExecutable |
3864 |
'/bin/ls' asFilename isExecutable |
|
3865 |
'/tmp' asFilename isExecutableProgram |
|
3866 |
'/bin/ls' asFilename isExecutableProgram |
|
3867 |
" |
|
3868 |
! |
|
3869 |
||
2922 | 3870 |
isHidden |
3871 |
"return true, if the receiver represents a hidden file. |
|
3872 |
The definitions of hidden files depends on the OS used; |
|
3873 |
on UNIX, a name starting with a period is considered hidden; |
|
3874 |
on MSDOS, the files hidden attribute is used. |
|
3875 |
VMS has no concept of hidden files." |
|
3876 |
||
3877 |
^ false |
|
3878 |
! |
|
3879 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3880 |
isMountPoint:aPathName |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3881 |
"return true, if I represent a mount-point. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3882 |
Warning: |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3883 |
the receiver must be an absolute pathname, |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3884 |
because a realPath is not used/generated for the query (to avoid automounting). |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3885 |
Aka: do not ask: '../../' asFilename isMountPoint; |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3886 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3887 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3888 |
self isAbsolute ifFalse:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3889 |
self error:'this query must be done on an absolute pathname'. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3890 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3891 |
^ OperatingSystem isMountPoint:(self name) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3892 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3893 |
|
615 | 3894 |
isReadable |
3895 |
"return true, if such a file exists and is readable." |
|
3896 |
||
2947 | 3897 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 3898 |
|
3899 |
" |
|
3900 |
'/foo/bar' asFilename isReadable |
|
3901 |
'/tmp' asFilename isReadable |
|
3902 |
'Makefile' asFilename isReadable |
|
328 | 3903 |
" |
3904 |
! |
|
3905 |
||
11529 | 3906 |
isSharedLibrary |
3907 |
"return true, if such a file exists and is a shared library." |
|
3908 |
||
3909 |
ObjectFileLoader isNil ifTrue:[ |
|
3910 |
"we cannot handle shared libraries, so there are no shared libraries" |
|
3911 |
^ false. |
|
3912 |
]. |
|
3913 |
self isRegularFile ifFalse:[ |
|
3914 |
^ false. |
|
3915 |
]. |
|
3916 |
^ ObjectFileLoader validBinaryExtensions includes:self suffix. |
|
3917 |
||
3918 |
" |
|
3919 |
'libstx_libbasic.so' asFilename isSharedLibrary |
|
3920 |
'libstx_libbasic.dll' asFilename isSharedLibrary |
|
3921 |
'/tmp' asFilename isSharedLibrary |
|
3922 |
" |
|
3923 |
! |
|
3924 |
||
615 | 3925 |
isWritable |
3926 |
"return true, if such a file exists and is writable." |
|
3927 |
||
2947 | 3928 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 3929 |
|
3930 |
" |
|
3931 |
'/foo/bar' asFilename isWritable |
|
3932 |
'/tmp' asFilename isWritable |
|
3933 |
'Makefile' asFilename isWritable |
|
328 | 3934 |
" |
174 | 3935 |
! |
3936 |
||
8946
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3937 |
nameWithSpecialExpansions:aString |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3938 |
"return the nameString, expanding any OS specific macros. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3939 |
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
|
3940 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3941 |
|dir user cutIdx idx userInfo| |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3942 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3943 |
(aString startsWith:'~') ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3944 |
dir := OperatingSystem getHomeDirectory. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3945 |
cutIdx := 2. |
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 |
(aString size > 1) ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3948 |
idx := aString indexOf:(self separator). |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3949 |
idx == 0 ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3950 |
user := aString copyFrom:2. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3951 |
cutIdx := aString size + 1. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3952 |
] ifFalse:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3953 |
user := aString copyFrom:2 to:(idx - 1). |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3954 |
cutIdx := idx. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3955 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3956 |
user size > 0 ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3957 |
userInfo := OperatingSystem userInfoOf:user. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3958 |
(userInfo notNil and:[userInfo includesKey:#dir]) ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3959 |
dir := userInfo at:#dir |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3960 |
] ifFalse:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3961 |
dir := nil |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3962 |
] |
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 |
dir isNil ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3965 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3966 |
^ aString |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3967 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3968 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3969 |
^ dir , (aString copyFrom:cutIdx) |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3970 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3971 |
^ aString |
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 |
Filename new nameWithSpecialExpansions:'~' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3975 |
Filename new nameWithSpecialExpansions:'~\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3976 |
Filename new nameWithSpecialExpansions:'~sv' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3977 |
Filename new nameWithSpecialExpansions:'~sv\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3978 |
Filename new nameWithSpecialExpansions:'~foo' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3979 |
Filename 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 |
UnixFilename new nameWithSpecialExpansions:'~' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3984 |
UnixFilename new nameWithSpecialExpansions:'~/work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3985 |
UnixFilename new nameWithSpecialExpansions:'~sv' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3986 |
UnixFilename new nameWithSpecialExpansions:'~sv/work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3987 |
UnixFilename new nameWithSpecialExpansions:'~foo' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3988 |
UnixFilename 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 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3992 |
PCFilename new nameWithSpecialExpansions:'~' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3993 |
PCFilename new nameWithSpecialExpansions:'~\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3994 |
PCFilename new nameWithSpecialExpansions:'~sv' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3995 |
PCFilename new nameWithSpecialExpansions:'~sv\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3996 |
PCFilename new nameWithSpecialExpansions:'~foo' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3997 |
PCFilename new nameWithSpecialExpansions:'~foo\bar' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3998 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3999 |
! |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4000 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4001 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4002 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4003 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4004 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4005 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4006 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
8947 | 4007 |
! |
4008 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4009 |
species |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4010 |
^ Filename concreteClass |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4011 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4012 |
|
8947 | 4013 |
withSpecialExpansions |
4014 |
"return a new filename, expanding any OS specific macros. |
|
4015 |
Here, a ~\ prefix is expanded to the users home dir (as in csh)" |
|
4016 |
||
4017 |
|newName| |
|
4018 |
||
4019 |
newName := self nameWithSpecialExpansions:nameString. |
|
4020 |
newName ~= nameString ifTrue:[ |
|
4021 |
^ newName asFilename. |
|
4022 |
]. |
|
4023 |
^ self. |
|
4024 |
||
4025 |
" |
|
4026 |
'~' asFilename withSpecialExpansions |
|
4027 |
'~\work' asFilename withSpecialExpansions |
|
4028 |
'~sv'asFilename withSpecialExpansions |
|
4029 |
'~sv\work' asFilename withSpecialExpansions |
|
4030 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4031 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4032 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4033 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4034 |
|
7291 | 4035 |
mimeTypeFromName |
4036 |
"return the mimeType as guessed from the files name/and or extension. |
|
4037 |
This could be less accurate than mimeTypeOfContents, but avoids |
|
4038 |
reading the file (is therefore much faster). |
|
4039 |
Also it works with non-existing files. |
|
4040 |
Returns nil for directories and other non-regular files." |
|
4041 |
||
4042 |
^ MIMETypes mimeTypeForFilename:(self name) |
|
4043 |
||
4044 |
" |
|
4045 |
'Makefile' asFilename mimeTypeFromName |
|
4046 |
'.' asFilename mimeTypeFromName |
|
4047 |
'/dev/null' asFilename mimeTypeFromName |
|
4048 |
'/tmp/.X11-unix/X0' asFilename mimeTypeFromName |
|
4049 |
'smalltalk.rc' asFilename mimeTypeFromName |
|
4050 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName |
|
4051 |
'../../rules/stmkmf' asFilename mimeTypeFromName |
|
4052 |
'/bläh' asFilename mimeTypeFromName |
|
10902 | 4053 |
'/x.zip' asFilename mimeTypeFromName |
4054 |
'/x.gz' asFilename mimeTypeFromName |
|
7291 | 4055 |
" |
4056 |
! |
|
4057 |
||
5011 | 4058 |
mimeTypeOfContents |
4059 |
"this tries to guess the mime type of contents of |
|
4060 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
4061 |
or the contents is unknown. |
|
4062 |
This is done using some heuristics, and may need some improvement" |
|
4063 |
||
10153 | 4064 |
|type buffer lcBuffer s size idx idx2| |
5011 | 4065 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4066 |
type := self type. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4067 |
type isNil ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4068 |
type == #directory ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4069 |
type == #characterSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4070 |
type == #blockSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4071 |
type == #socket ifTrue:[ ^ nil ]. |
5011 | 4072 |
self fileSize == 0 ifTrue:[^ nil]. |
4073 |
||
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4074 |
s := self readStreamOrNil. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4075 |
s isNil ifTrue:[^ nil]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4076 |
|
5011 | 4077 |
"/ read some data from the file ... |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
4078 |
buffer := String new:2048. |
5011 | 4079 |
|
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4080 |
s errorSignal handle:[:ex | |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4081 |
size := 0. |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4082 |
] do:[ |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4083 |
size := s nextBytes:buffer size into:buffer. |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4084 |
]. |
5011 | 4085 |
s close. |
11406
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 |
^ MIMETypes mimeTypeOfData:buffer |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4088 |
|
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4089 |
"/ lcBuffer := buffer asLowercase. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4090 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4091 |
"/ (idx := lcBuffer findString:'mimetype:') ~~ 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4092 |
"/ idx := idx + 'mimetype:' size. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4093 |
"/ idx := lcBuffer indexOfNonSeparatorStartingAt:idx. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4094 |
"/ idx2 := lcBuffer indexOfSeparatorStartingAt:idx. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4095 |
"/ idx2 > idx ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4096 |
"/ ^ lcBuffer copyFrom:idx to:idx2-1 |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4097 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4098 |
"/ ]. |
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 |
"/ ( '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
|
4102 |
"/ #'application/x-ms-shortcut' ) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4103 |
"/ ( 'top' 'WALTOP' |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4104 |
"/ #'application/x-waltop-digital-notepad' ) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4105 |
"/ ) triplesDo:[:suffixMatch :pattern :what | |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4106 |
"/ |patternString| |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4107 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4108 |
"/ (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
|
4109 |
"/ patternString := pattern asString. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4110 |
"/ (buffer startsWith:patternString) ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4111 |
"/ ^ what |
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 |
"/ ] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4114 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4115 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4116 |
"/ #( |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4117 |
"/ ('<body:' #'text/html') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4118 |
"/ ('%!!ps-adobe' #'application/postscript') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4119 |
"/ ('%PDF-' #'application/pdf') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4120 |
"/ ('#!! /bin/sh' #'application/x-sh') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4121 |
"/ ('#!!/bin/sh' #'application/x-sh') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4122 |
"/ "/ ('#!! /bin/bash' 'application/x-bash') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4123 |
"/ "/ ('#!!/bin/bash' 'application/x-bash') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4124 |
"/ ('<?xml version=' #'text/xml') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4125 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4126 |
"/ ('from dolphin' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4127 |
"/ ('from visualworks' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4128 |
"/ ('categoriesforclass' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4129 |
"/ ('methodsfor!!' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4130 |
"/ ('subclass:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4131 |
"/ ('methodsfor:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4132 |
"/ ('interchangeversion:' #'application/x-smalltalk-source-sif') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4133 |
"/ ('subclass:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4134 |
"/ ('methodsfor:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4135 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4136 |
"/ ) pairsDo:[:pattern :what | |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4137 |
"/ (lcBuffer findString:pattern) ~~ 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4138 |
"/ ^ what |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4139 |
"/ ] |
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 |
"/ (idx := lcBuffer findString:'<h') ~~ 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4143 |
"/ ((lcBuffer continuesWith:'<head' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4144 |
"/ or:[(lcBuffer continuesWith:'<html' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4145 |
"/ or:[(lcBuffer continuesWith:'<h1' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4146 |
"/ or:[(lcBuffer continuesWith:'<h2' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4147 |
"/ or:[(lcBuffer continuesWith:'<h3' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4148 |
"/ or:[(lcBuffer continuesWith:'<h4' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4149 |
"/ or:[(lcBuffer continuesWith:'<h5' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4150 |
"/ or:[(lcBuffer continuesWith:'<h6' startingAt:idx)]]]]]]]) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4151 |
"/ ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4152 |
"/ ^ #'text/html' |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4153 |
"/ ] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4154 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4155 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4156 |
"/ [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
|
4157 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4158 |
"/ size == 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4159 |
"/ ^ #'text/plain' |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4160 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4161 |
"/ ^ nil |
5011 | 4162 |
|
4163 |
" |
|
6753
1a4a541850f2
add search for unprintable characters on mimeTypeContents
penk
parents:
6729
diff
changeset
|
4164 |
'Makefile' asFilename mimeTypeOfContents |
1a4a541850f2
add search for unprintable characters on mimeTypeContents
penk
parents:
6729
diff
changeset
|
4165 |
'.' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4166 |
'/dev/null' asFilename mimeTypeOfContents |
10153 | 4167 |
'/tmp/.X11-unix/X0' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4168 |
'smalltalk.rc' asFilename mimeTypeOfContents |
5011 | 4169 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents |
10153 | 4170 |
'../../rules/stmkmf' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4171 |
'/bläh' asFilename mimeTypeOfContents |
10153 | 4172 |
'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
|
4173 |
'G:\A\A01.TOP' asFilename mimeTypeOfContents |
10153 | 4174 |
" |
4175 |
||
4176 |
"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
|
4177 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4178 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4179 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4180 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4181 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4182 |
"return my baseName as a string. |
2012 | 4183 |
- thats the file/directory name without leading parent-dirs. |
2922 | 4184 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
4185 |
and '/usr/lib' asFilename baseName -> lib). |
|
7075 | 4186 |
This method does not check if the path is valid. |
4187 |
The code here should work for Unix and MSDOS, but needs to be redefined |
|
4188 |
for VMS (and maybe others as well). |
|
2911 | 4189 |
See also: #pathName, #directoryName and #directoryPathName. |
4190 |
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
|
4191 |
|
2922 | 4192 |
|len index sep endIdx| |
4193 |
||
4194 |
sep := self separator. |
|
4195 |
len := nameString size. |
|
4196 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
7075 | 4197 |
^ nameString |
2922 | 4198 |
]. |
4199 |
||
4200 |
endIdx := len. |
|
4201 |
len > 1 ifTrue:[ |
|
7075 | 4202 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
2922 | 4203 |
]. |
4204 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
4205 |
^ 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
|
4206 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4207 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4208 |
'/foo/bar' asFilename baseName |
4903 | 4209 |
'/foo/bar.cc' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4210 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4211 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4212 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4213 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4214 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4215 |
'../../libbasic/Object.st' asFilename baseName |
3851 | 4216 |
'/' asFilename baseName |
4217 |
'\' asFilename baseName |
|
4218 |
'c:\' asFilename baseName |
|
4219 |
'\\idefix' asFilename baseName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4220 |
" |
2012 | 4221 |
|
3851 | 4222 |
"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
|
4223 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4224 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4225 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4226 |
"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
|
4227 |
- 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
|
4228 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4229 |
(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
|
4230 |
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
|
4231 |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
4232 |
^ self class named:(self directoryName) |
1049
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 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4235 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4236 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4237 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4238 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4239 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4240 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4241 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4242 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4243 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4244 |
"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
|
4245 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4246 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4247 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4248 |
"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
|
4249 |
- 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
|
4250 |
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
|
4251 |
This method does not check if the path is valid. |
2922 | 4252 |
|
4253 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
4254 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
4255 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4256 |
(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
|
4257 |
a string instead of a Filename instance). |
2922 | 4258 |
|
2012 | 4259 |
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
|
4260 |
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
|
4261 |
|
3954 | 4262 |
|index sep sepString p rest| |
2922 | 4263 |
|
4264 |
sep := self separator. |
|
4265 |
sepString := sep asString. |
|
4266 |
(nameString = sepString) ifTrue:[ |
|
6402
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 |
"/ the trivial '/' case |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4269 |
"/ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4270 |
^ nameString |
2922 | 4271 |
]. |
4272 |
||
4273 |
"/ |
|
3893 | 4274 |
"/ strip off multiple trailing slashes |
2922 | 4275 |
"/ |
4276 |
p := nameString. |
|
4277 |
[p endsWith:sepString] whileTrue:[ |
|
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4278 |
(p = sepString) ifTrue:[ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4279 |
^ p |
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 |
p := p copyWithoutLast:1 |
2922 | 4282 |
]. |
4283 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4284 |
"/ strip off trailing components |
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4285 |
|
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4286 |
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
|
4287 |
index == 0 ifTrue:[ |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4288 |
"/ no separator found |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4289 |
p = '.' ifTrue:[ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4290 |
^ '..' |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4291 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4292 |
p = '..' ifTrue:[ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4293 |
^ '../..' |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4294 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4295 |
^ '.' |
2922 | 4296 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4297 |
rest := p copyFrom:(index+1). |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4298 |
(rest = '.') ifTrue:[ |
7519
0cfe202e7e3e
#directoryName returned a Filename
Stefan Vogel <sv@exept.de>
parents:
7473
diff
changeset
|
4299 |
^ p copyTo:index-1. |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4300 |
]. |
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4301 |
(rest = '..') ifTrue:[ |
7343 | 4302 |
^ (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
|
4303 |
]. |
3893 | 4304 |
index == 1 ifTrue:[ |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4305 |
^ '/' |
3893 | 4306 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4307 |
^ p copyTo:(index - 1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4308 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4309 |
" |
3893 | 4310 |
'/home' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4311 |
'/foo/bar/' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4312 |
'/foo/bar/' asFilename directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4313 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4314 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4315 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4316 |
'bitmaps' asFilename directoryPathName |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4317 |
'.' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4318 |
'.' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4319 |
'..' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4320 |
'..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4321 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4322 |
'../..' asFilename directoryPathName |
7343 | 4323 |
'/foo/bar/baz/..' asFilename directoryName |
4324 |
'/foo/bar/baz/.' asFilename directoryName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4325 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4326 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4327 |
"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
|
4328 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 4329 |
"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
|
4330 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4331 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4332 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4333 |
"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
|
4334 |
- 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
|
4335 |
the receiver is contained in. |
2012 | 4336 |
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
|
4337 |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
4338 |
^ (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
|
4339 |
|
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 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4342 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4343 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4344 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4345 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4346 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4347 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4348 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4349 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4350 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4351 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4352 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4353 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4354 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4355 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 4356 |
"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
|
4357 |
! |
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 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4360 |
"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
|
4361 |
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
|
4362 |
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
|
4363 |
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
|
4364 |
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
|
4365 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4366 |
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
|
4367 |
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
|
4368 |
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
|
4369 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4370 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4371 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4372 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4373 |
'mak' asFilename filenameCompletion |
1517 | 4374 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4375 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4376 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4377 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4378 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4379 |
|
1517 | 4380 |
"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
|
4381 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4382 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4383 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4384 |
"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
|
4385 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4386 |
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
|
4387 |
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
|
4388 |
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
|
4389 |
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
|
4390 |
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
|
4391 |
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
|
4392 |
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
|
4393 |
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
|
4394 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4395 |
|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
|
4396 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 4397 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4398 |
caseless := self class isCaseSensitive not. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4399 |
matching := OrderedCollection new. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4400 |
|
3666 | 4401 |
nm := self nameWithSpecialExpansions:nameString. |
6803 | 4402 |
nm := self class canonicalize:nm. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4403 |
|
8243 | 4404 |
sepString := self class separatorString. |
3666 | 4405 |
(nm endsWith:sepString) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4406 |
"/ two exceptions here: |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4407 |
"/ 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
|
4408 |
"/ 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
|
4409 |
self isDirectory ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4410 |
|first longest| |
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 |
first := nil. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4413 |
self directoryContentsDo:[:fileName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4414 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4415 |
matching add:fileName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4416 |
first isNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4417 |
first := longest := fileName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4418 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4419 |
"/ more than one file |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4420 |
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
|
4421 |
longest isEmpty ifTrue:[ |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4422 |
^ #() |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4423 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4424 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4425 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4426 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4427 |
longest notNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4428 |
nameString := (self constructString:longest). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4429 |
^ matching |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4430 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4431 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4432 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4433 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4434 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4435 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4436 |
baseName := self baseName. |
3666 | 4437 |
baseName ~= nm ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4438 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4439 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4440 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4441 |
self isAbsolute ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4442 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4443 |
] ifFalse:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4444 |
aDirectory isNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4445 |
dir := self directory |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4446 |
] ifFalse:[ |
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4447 |
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
|
4448 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4449 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4450 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4451 |
caseless ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4452 |
lcBaseName := baseName asLowercase |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4453 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4454 |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
4455 |
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
|
4456 |
^ #(). |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
4457 |
] do:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4458 |
dir directoryContents do:[:fileName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4459 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4460 |
((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
|
4461 |
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
|
4462 |
matching add:fileName |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4463 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4464 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4465 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4466 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4467 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4468 |
(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
|
4469 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4470 |
find the longest common prefix |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4471 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4472 |
matchLen := baseName size. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4473 |
matchLen > matching first size ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4474 |
try := baseName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4475 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4476 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4477 |
try := matching first copyTo:matchLen. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4478 |
allMatching := true. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4479 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4480 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4481 |
[allMatching] whileTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4482 |
matching do:[:aName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4483 |
((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
|
4484 |
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
|
4485 |
allMatching := false |
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 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4488 |
allMatching ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4489 |
matchLen < matching first size ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4490 |
matchLen := matchLen + 1. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4491 |
try := matching first copyTo:matchLen. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4492 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4493 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4494 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4495 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4496 |
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
|
4497 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4498 |
]. |
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 |
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
|
4501 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4502 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4503 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4504 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4505 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4506 |
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
|
4507 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4508 |
prefix notNil ifTrue:[ |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4509 |
(prefix endsWith:sepString) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4510 |
"/ 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
|
4511 |
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
|
4512 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4513 |
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
|
4514 |
nMatch == 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4515 |
nameString := nm := matching first |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4516 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4517 |
nMatch > 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4518 |
nameString := nm := prefix , sepString , nm |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4519 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4520 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4521 |
] ifFalse:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4522 |
nMatch == 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4523 |
nameString := nm := matching first |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4524 |
] |
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 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4527 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4528 |
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
|
4529 |
(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
|
4530 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4531 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4532 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4533 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4534 |
|
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4535 |
'../' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4536 |
'/' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4537 |
'/usr/' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4538 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4539 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4540 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4541 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4542 |
'/u' asFilename filenameCompletion |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4543 |
'../../libpr' asFilename filenameCompletion |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4544 |
'/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
|
4545 |
|
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4546 |
'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
|
4547 |
'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
|
4548 |
'c:\p' asFilename filenameCompletion |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4549 |
'c:\' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4550 |
'c:' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4551 |
'\' asFilename filenameCompletion -> empty |
1049
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 |
|
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4554 |
"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
|
4555 |
"Modified: / 17-11-2007 / 14:31:08 / cg" |
2903 | 4556 |
! |
4557 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4558 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4559 |
"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
|
4560 |
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
|
4561 |
(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
|
4562 |
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
|
4563 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4564 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4565 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4566 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4567 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4568 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4569 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4570 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4571 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4572 |
"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
|
4573 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4574 |
|
7120 | 4575 |
isAbsolute |
4576 |
"return true, if the receiver represents an absolute pathname |
|
4577 |
(in contrast to one relative to the current directory)." |
|
4578 |
||
4579 |
(nameString startsWith:self class separator) ifTrue:[^ true]. |
|
4580 |
^ self isVolumeAbsolute |
|
4581 |
||
4582 |
" |
|
4583 |
'/foo/bar' asFilename isAbsolute |
|
4584 |
'..' asFilename isAbsolute |
|
4585 |
'..' asAbsoluteFilename isAbsolute |
|
4586 |
'source/SBrowser.st' asFilename isAbsolute |
|
4587 |
" |
|
4588 |
! |
|
4589 |
||
4590 |
isExplicitRelative |
|
4591 |
"return true, if this name is an explicit relative name |
|
4592 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
4593 |
||
4594 |
^ false |
|
4595 |
! |
|
4596 |
||
4597 |
isImplicit |
|
4598 |
"return true, if the receiver represents a builtin file. |
|
4599 |
The definitions of builtin files depends on the OS used; |
|
4600 |
on UNIX, '.' and '..' are builtin names." |
|
4601 |
||
4602 |
^ false |
|
4603 |
||
4604 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
|
4605 |
! |
|
4606 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4607 |
isParentDirectoryOf:aFilenameOrString |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4608 |
"warning: may lead to automounting" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4609 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4610 |
|filenameArg otherName myName| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4611 |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4612 |
filenameArg := aFilenameOrString asFilename. |
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4613 |
filenameArg isDirectory ifFalse:[ |
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4614 |
filenameArg := filenameArg directory. |
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4615 |
]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4616 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4617 |
otherName := filenameArg name. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4618 |
myName := self name. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4619 |
(otherName startsWith:myName ) ifTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4620 |
^ (otherName ~= myName) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4621 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4622 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4623 |
otherName := filenameArg pathName. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4624 |
myName := self pathName. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4625 |
(otherName startsWith:myName ) ifTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4626 |
^ (otherName ~= myName) |
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 |
filenameArg allParentDirectoriesDo:[:parent | |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4630 |
parent pathName = myName ifTrue:[^ true]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4631 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4632 |
^ false. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4633 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4634 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4635 |
'/etc' asFilename isParentDirectoryOf:'/etc/passwd' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4636 |
'/etc' asFilename isParentDirectoryOf:'/etc/' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4637 |
'/etc' asFilename isParentDirectoryOf:'/etc' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4638 |
'/home' asFilename isParentDirectoryOf:Filename currentDirectory |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4639 |
'/' asFilename isParentDirectoryOf:'/phys/qnx' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4640 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4641 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4642 |
|
7120 | 4643 |
isRelative |
4644 |
"return true, if this name is interpreted relative to some |
|
4645 |
directory (opposite of absolute)" |
|
4646 |
||
4647 |
^ self isAbsolute not |
|
4648 |
||
4649 |
" |
|
4650 |
'./foo/bar' asFilename isRelative |
|
4651 |
'../../foo/bar' asFilename isRelative |
|
4652 |
'/foo/bar' asFilename isRelative |
|
4653 |
'bar' asFilename isRelative |
|
4654 |
" |
|
4655 |
||
4656 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
4657 |
! |
|
4658 |
||
4659 |
isRootDirectory |
|
4660 |
"return true, if I represent the root directory |
|
4661 |
(i.e. I have no parentDir)" |
|
4662 |
||
4663 |
"/ mhmh - should we use: |
|
4664 |
"/ |
|
4665 |
"/ parentDir := self construct:'..'. |
|
4666 |
"/ (parentDir exists |
|
4667 |
"/ and:[parentDir isDirectory |
|
4668 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
|
4669 |
"/ ^ false |
|
4670 |
"/ ]. |
|
4671 |
"/ ^ true |
|
4672 |
"/ |
|
4673 |
||
4674 |
^ self pathName = Filename rootDirectory pathName |
|
4675 |
||
4676 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
4677 |
! |
|
4678 |
||
4679 |
isVolumeAbsolute |
|
4680 |
"return true, if the receiver represents an absolute pathname |
|
4681 |
on some disk volume (MSDOS only)" |
|
4682 |
||
4683 |
^ false |
|
4684 |
||
4685 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
4686 |
! |
|
4687 |
||
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4688 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4689 |
"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
|
4690 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4691 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4692 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4693 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4694 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4695 |
|
615 | 4696 |
name |
4697 |
"return the name of the file represented by the receiver as a string. |
|
883 | 4698 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 4699 |
See also: pathName" |
174 | 4700 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4701 |
"/ self isAbsolute ifTrue:[^ self pathName]. |
615 | 4702 |
^ nameString |
174 | 4703 |
|
4704 |
" |
|
615 | 4705 |
'/foo/bar' asFilename name |
4706 |
'/foo/bar' asFilename pathName |
|
4707 |
'.' asFilename name |
|
4708 |
'.' asFilename pathName |
|
4709 |
'../..' asFilename name |
|
883 | 4710 |
'../..' asFilename pathName |
615 | 4711 |
'bitmaps' asFilename name |
4712 |
'bitmaps' asFilename pathName |
|
4713 |
'/tmp/../usr' asFilename name |
|
883 | 4714 |
'/tmp/../usr' asFilename pathName |
4715 |
'source/..' asFilename name |
|
4716 |
'source/..' asFilename pathName |
|
4717 |
'/tmp/..' asFilename name |
|
4718 |
'/tmp/..' asFilename pathName |
|
92 | 4719 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4720 |
|
883 | 4721 |
"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
|
4722 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4723 |
|
7308 | 4724 |
nameString |
4725 |
"raw access to nameString - req'd for xml-store/reload" |
|
4726 |
||
4727 |
^ nameString |
|
4728 |
! |
|
4729 |
||
4730 |
nameString:aString |
|
4731 |
"raw access to nameString - req'd for xml-store/reload" |
|
4732 |
||
4733 |
nameString := aString |
|
4734 |
! |
|
4735 |
||
615 | 4736 |
pathName |
4737 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 4738 |
as a string. This will not include ..'s. |
4739 |
If the path represented by the receiver does NOT represent a valid path, |
|
4740 |
no compression will be done (for now; this may change). |
|
4741 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4742 |
|
1317 | 4743 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4744 |
|
1317 | 4745 |
"/ sep := self class separator. |
4746 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
4747 |
"/ parentName := self class parentDirectoryName. |
|
4748 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
4749 |
"/ ^ nameString |
|
4750 |
"/ ] |
|
4751 |
"/ ]. |
|
4752 |
p := OperatingSystem pathNameOf:nameString. |
|
4753 |
^ p |
|
2 | 4754 |
|
92 | 4755 |
" |
1317 | 4756 |
'/foo/bar' asFilename pathName |
4757 |
'.' asFilename pathName |
|
4758 |
'../..' asFilename pathName |
|
4759 |
'../..' asFilename name |
|
4760 |
'/tmp/../usr' asFilename pathName |
|
4761 |
'/././usr' asFilename pathName |
|
92 | 4762 |
" |
159 | 4763 |
|
1317 | 4764 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 4765 |
! |
4766 |
||
11658 | 4767 |
physicalFilename |
4768 |
"return the fileName representing the physical file as represented by the receiver, |
|
4769 |
If the receiver represents a symbolic link, thats the fileName of the |
|
4770 |
final target. Otherwise, its the receivers pathName itself. |
|
4771 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
|
4772 |
nil is returned." |
|
4773 |
||
4774 |
|pathOrNil| |
|
4775 |
||
4776 |
pathOrNil := self physicalPathName. |
|
4777 |
pathOrNil isNil ifTrue:[ |
|
4778 |
^ nil |
|
4779 |
]. |
|
4780 |
^ pathOrNil asFilename |
|
4781 |
||
4782 |
" |
|
4783 |
'/foo/bar' asFilename physicalFileName |
|
4784 |
" |
|
4785 |
! |
|
4786 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4787 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4788 |
"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
|
4789 |
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
|
4790 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4791 |
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
|
4792 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4793 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4794 |
|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
|
4795 |
|
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4796 |
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
|
4797 |
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
|
4798 |
" 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
|
4799 |
^ nil. |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4800 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4801 |
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
|
4802 |
^ 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
|
4803 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4804 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4805 |
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
|
4806 |
[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4807 |
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
|
4808 |
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
|
4809 |
"/ 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
|
4810 |
^ nil |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4811 |
]. |
11657 | 4812 |
path asFilename isAbsolute ifTrue:[ |
4813 |
t := path asFilename |
|
4814 |
] ifFalse:[ |
|
4815 |
t := (self class named:t directoryName) construct:path. |
|
4816 |
]. |
|
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 |
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
|
4818 |
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
|
4819 |
"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
|
4820 |
^ nil |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4821 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4822 |
] 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
|
4823 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4824 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4825 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4826 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4827 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4828 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4829 |
'../..' 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
|
4830 |
'/usr/tmp' asFilename physicalPathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4831 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4832 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4833 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4834 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4835 |
|
615 | 4836 |
tail |
4837 |
"the files name without directory prefix as a string. |
|
4838 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 4839 |
|
615 | 4840 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4841 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4842 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4843 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4844 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4845 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4846 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4847 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4848 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 4849 |
! |
4850 |
||
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4851 |
tail:nComponents |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4852 |
"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
|
4853 |
- 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
|
4854 |
(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
|
4855 |
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
|
4856 |
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
|
4857 |
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
|
4858 |
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
|
4859 |
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
|
4860 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4861 |
|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
|
4862 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4863 |
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
|
4864 |
components := self components. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4865 |
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
|
4866 |
start < 1 ifTrue:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4867 |
start := 1. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4868 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4869 |
start = 1 ifTrue:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4870 |
tail := '' |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4871 |
] ifFalse:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4872 |
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
|
4873 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4874 |
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
|
4875 |
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
|
4876 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4877 |
^ tail. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4878 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4879 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4880 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4881 |
'/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
|
4882 |
'/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
|
4883 |
'/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
|
4884 |
'/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
|
4885 |
'.' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4886 |
'..' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4887 |
'../..' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4888 |
'../../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
|
4889 |
'../../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
|
4890 |
'../../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
|
4891 |
'../../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
|
4892 |
'/' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4893 |
'\' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4894 |
'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
|
4895 |
'\\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
|
4896 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4897 |
! |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4898 |
|
2629 | 4899 |
volume |
4900 |
"return the disc volume part of the name or an empty string. |
|
2906 | 4901 |
This is only used with MSDOS and VMS filenames |
4902 |
- by default (and on unix), an empty string is returned" |
|
4903 |
||
2629 | 4904 |
^ '' |
2906 | 4905 |
|
4906 |
"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
|
4907 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4908 |
|
7120 | 4909 |
!Filename methodsFor:'queries-type'! |
4910 |
||
4911 |
isDirectory |
|
4912 |
"return true, if the receiver represents an existing, |
|
4913 |
readable directories pathname." |
|
4914 |
||
4915 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
|
4916 |
||
4917 |
" |
|
4918 |
'/foo/bar' asFilename isDirectory |
|
4919 |
'/tmp' asFilename isDirectory |
|
4920 |
'Makefile' asFilename isDirectory |
|
4921 |
'c:\' asFilename isDirectory |
|
4922 |
'd:\' asFilename isDirectory |
|
4923 |
" |
|
4924 |
||
4925 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
4926 |
! |
|
4927 |
||
4928 |
isNonEmptyDirectory |
|
4929 |
"return true, if the receiver represents an existing, |
|
4930 |
readable directories pathname, and the directory is not empty." |
|
4931 |
||
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4932 |
FileStream openErrorSignal |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4933 |
handle:[:ex ] |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4934 |
do:[ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4935 |
self directoryContentsDo:[:pathString|^ true]. |
7120 | 4936 |
]. |
4937 |
^ false. |
|
4938 |
||
4939 |
" |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4940 |
'/foo/bar' asFilename isNonEmptyDirectory |
7120 | 4941 |
'/tmp' asFilename isNonEmptyDirectory |
4942 |
'/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory. |
|
4943 |
'/tmp/empty' asFilename removeDirectory. |
|
4944 |
'Makefile' asFilename isNonEmptyDirectory |
|
4945 |
'c:\' asFilename isNonEmptyDirectory |
|
4946 |
'd:\' asFilename isNonEmptyDirectory |
|
4947 |
" |
|
4948 |
||
4949 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
4950 |
! |
|
4951 |
||
8836 | 4952 |
isRegularFile |
4953 |
"return true, if the receiver represents a plain, regular file" |
|
4954 |
||
4955 |
^ self type == #regular |
|
4956 |
||
4957 |
" |
|
4958 |
'/foo/bar' asFilename isRegularFile |
|
4959 |
'/tmp' asFilename isRegularFile |
|
4960 |
'Makefile' asFilename isRegularFile |
|
4961 |
'c:\' asFilename isRegularFile |
|
4962 |
'd:\' asFilename isRegularFile |
|
4963 |
'/dev/null' asFilename isRegularFile |
|
4964 |
" |
|
4965 |
! |
|
4966 |
||
7120 | 4967 |
isSpecialFile |
4968 |
"return true, if the receiver represents a socket, named pipe, fifo |
|
4969 |
or device special file (i.e. anything non regular and non-directory)" |
|
4970 |
||
4971 |
|t| |
|
4972 |
||
4973 |
t := self type. |
|
4974 |
^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]]) |
|
4975 |
||
4976 |
" |
|
4977 |
'/foo/bar' asFilename isSpecialFile |
|
4978 |
'/tmp' asFilename isSpecialFile |
|
4979 |
'Makefile' asFilename isSpecialFile |
|
4980 |
'c:\' asFilename isSpecialFile |
|
4981 |
'd:\' asFilename isSpecialFile |
|
4982 |
'/dev/null' asFilename isSpecialFile |
|
4983 |
" |
|
4984 |
! |
|
4985 |
||
4986 |
isSymbolicLink |
|
4987 |
"return true, if the file represented by the receiver is a symbolic |
|
4988 |
link. Notice that not all OS's support symbolic links; those that do |
|
4989 |
not will always return false." |
|
4990 |
||
4991 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
|
4992 |
||
4993 |
" |
|
4994 |
'Make.proto' asFilename isSymbolicLink |
|
4995 |
'Makefile' asFilename isSymbolicLink |
|
4996 |
" |
|
4997 |
! ! |
|
4998 |
||
6529 | 4999 |
!Filename methodsFor:'reading-directories'! |
5000 |
||
5001 |
directoryContents |
|
5002 |
"return the contents of the directory as a collection of strings. |
|
5003 |
This excludes any entries for '.' or '..'. |
|
5004 |
Returns nil for non-existing directories; however, this behavior |
|
5005 |
may be changed in the near future, to raise an exception instead. |
|
5006 |
So users of this method better test for existing directory before. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5007 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5008 |
this returns the file-names as strings; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5009 |
see also #directoryContentsAsFilenames, which returns fileName instances." |
6529 | 5010 |
|
5011 |
|s contents| |
|
5012 |
||
5013 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
|
5014 |
s isNil ifTrue:[^nil]. |
|
5015 |
||
5016 |
[ |
|
5017 |
contents := s contents. |
|
5018 |
] ensure:[ |
|
5019 |
s close |
|
5020 |
]. |
|
5021 |
||
5022 |
contents remove:'.' ifAbsent:nil. |
|
5023 |
contents remove:'..' ifAbsent:nil. |
|
5024 |
^ contents. |
|
5025 |
||
5026 |
" |
|
5027 |
'.' asFilename directoryContents |
|
5028 |
'/XXXdoesNotExist' asFilename directoryContents |
|
5029 |
" |
|
5030 |
||
5031 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
5032 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
|
5033 |
! |
|
5034 |
||
5035 |
directoryContentsAsFilenames |
|
5036 |
"return the contents of the directory as a collection of filenames. |
|
5037 |
This excludes any entries for '.' or '..'. |
|
5038 |
Returns nil for non-existing directories; however, this behavior |
|
5039 |
may be changed in the near future, to raise an exception instead. |
|
5040 |
So users of this method better test for existing directory before. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5041 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5042 |
this returns the file-names as fileName instances; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5043 |
see also #directoryContents, which returns strings." |
6529 | 5044 |
|
5045 |
|names| |
|
5046 |
||
5047 |
names := self directoryContents. |
|
5048 |
names isNil ifTrue:[^ nil]. |
|
5049 |
^ names asOrderedCollection collect:[:entry | self construct:entry]. |
|
5050 |
||
5051 |
" |
|
5052 |
'.' asFilename directoryContentsAsFilenames |
|
5053 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
|
5054 |
" |
|
5055 |
! |
|
5056 |
||
5057 |
fullDirectoryContents |
|
5058 |
"return the full contents of the directory as a collection of strings. |
|
5059 |
This is much like #directoryContents, but includes an entry for the |
|
5060 |
parent directory, if there is one. |
|
5061 |
Returns nil for non-existing directories; however, this behavior |
|
5062 |
may be changed in the near future, to raise an exception instead. |
|
5063 |
So users of this method better test for existing directory before." |
|
5064 |
||
5065 |
|files| |
|
5066 |
||
5067 |
files := self directoryContents. |
|
5068 |
files isNil ifTrue:[ |
|
9453 | 5069 |
"/ mhmh - that one does not exist |
5070 |
^ files |
|
6529 | 5071 |
]. |
5072 |
||
5073 |
"/ add/remove parentDirectory if there is one/none |
|
5074 |
||
5075 |
files remove:'.' ifAbsent:nil. |
|
5076 |
self isRootDirectory ifTrue:[ |
|
9453 | 5077 |
files remove:'..' ifAbsent:nil. |
6529 | 5078 |
] ifFalse:[ |
9453 | 5079 |
(files includes:'..') ifFalse:[ |
5080 |
files addFirst:'..'. |
|
5081 |
] |
|
6529 | 5082 |
]. |
5083 |
^ files |
|
5084 |
||
5085 |
" |
|
5086 |
'.' asFilename fullDirectoryContents |
|
5087 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
5088 |
'd:\FET' asFilename fullDirectoryContents |
|
5089 |
" |
|
5090 |
||
5091 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
|
5092 |
! |
|
5093 |
||
5094 |
recursiveDirectoryContents |
|
5095 |
"return the contents of the directory and all subdirectories |
|
5096 |
as a collection of strings. |
|
5097 |
This excludes any entries for '.' or '..'. |
|
5098 |
Subdirectory files are included with a relative pathname. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5099 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5100 |
this returns the file-names as strings; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5101 |
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5102 |
|
6529 | 5103 |
Warning: this may take a long time to execute." |
5104 |
||
5105 |
|fileNames dirNames| |
|
5106 |
||
5107 |
fileNames := OrderedCollection new. |
|
5108 |
dirNames := OrderedCollection new. |
|
5109 |
self directoryContents do:[:f | |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5110 |
(self construct:f) isDirectory ifTrue:[ |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5111 |
dirNames add:f |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5112 |
] ifFalse:[ |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5113 |
fileNames add:f |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5114 |
] |
6529 | 5115 |
]. |
5116 |
||
5117 |
dirNames do:[:dN | |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5118 |
|dd subFiles| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5119 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5120 |
dd := dN asFilename. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5121 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5122 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
6529 | 5123 |
]. |
5124 |
^ fileNames. |
|
5125 |
||
5126 |
" |
|
5127 |
'.' asFilename recursiveDirectoryContents |
|
5128 |
'../../clients' asFilename recursiveDirectoryContents |
|
5129 |
" |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5130 |
! |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5131 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5132 |
recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5133 |
"return the contents of the directory and all subdirectories |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5134 |
as a collection of filenames. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5135 |
This excludes any entries for '.' or '..'. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5136 |
Returns nil for non-existing directories; however, this behavior |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5137 |
may be changed in the near future, to raise an exception instead. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5138 |
So users of this method better test for existing directory before. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5139 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5140 |
this returns the file-names as fileName instances; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5141 |
see also #recursiveDirectoryContents, which returns strings. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5142 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5143 |
Warning: this may take a long time to execute." |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5144 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5145 |
|names| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5146 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5147 |
names := self recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5148 |
names isNil ifTrue:[^ nil]. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5149 |
^ names asOrderedCollection collect:[:entry | self construct:entry]. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5150 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5151 |
" |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5152 |
'.' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5153 |
'/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5154 |
" |
6529 | 5155 |
! ! |
5156 |
||
5157 |
!Filename methodsFor:'reading-files'! |
|
5158 |
||
5159 |
binaryContentsOfEntireFile |
|
5160 |
"return the binary contents of the file (as a byteArray); |
|
7680 | 5161 |
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
|
5162 |
|
7680 | 5163 |
^ self |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5164 |
readingFileDo:[:s | |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5165 |
|nBytes bytes 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 |
s binary. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5168 |
nBytes := self fileSize. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5169 |
(nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5170 |
bytes := ByteArray uninitializedNew:nBytes. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5171 |
n := s |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5172 |
nextBytes:nBytes |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5173 |
into:bytes |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5174 |
startingAt:1. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5175 |
n == nBytes ifTrue:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5176 |
bytes |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5177 |
] ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5178 |
bytes copyTo:n |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5179 |
] |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5180 |
] ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5181 |
s contentsOfEntireFile |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5182 |
] |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5183 |
] |
6529 | 5184 |
|
5185 |
" |
|
5186 |
'Makefile' asFilename binaryContentsOfEntireFile |
|
5187 |
'foobar' asFilename binaryContentsOfEntireFile |
|
5188 |
" |
|
5189 |
! |
|
5190 |
||
5191 |
contents |
|
5192 |
"return the contents of the file as a collection of lines; |
|
7680 | 5193 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 5194 |
See also #contentsOfEntireFile, which returns a string for textFiles. |
5195 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
5196 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5197 |
^ self readingFileDo:[:s | s contents]. |
6529 | 5198 |
|
5199 |
" |
|
5200 |
'Makefile' asFilename contents |
|
5201 |
'foobar' asFilename contents |
|
5202 |
" |
|
5203 |
||
5204 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
5205 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
5206 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
5207 |
! |
|
5208 |
||
10780 | 5209 |
contentsAsString |
5210 |
"to compensate for the bad naming, use this to make things explicit. |
|
5211 |
See also #contents, which returns the lines as stringCollection for textFiles." |
|
5212 |
||
11397
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5213 |
^ self contentsOfEntireFile |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5214 |
|
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5215 |
" |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5216 |
'Makefile' asFilename contentsAsString |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5217 |
'foobar' asFilename contentsAsString |
10780 | 5218 |
" |
5219 |
||
5220 |
"Modified: / 02-07-1996 / 12:49:45 / stefan" |
|
5221 |
"Created: / 08-11-2007 / 13:29:59 / cg" |
|
5222 |
! |
|
5223 |
||
6529 | 5224 |
contentsOfEntireFile |
5225 |
"return the contents of the file as a string; |
|
7680 | 5226 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 5227 |
See also #contents, which returns the lines as stringCollection for textFiles. |
5228 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
5229 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5230 |
^ self readingFileDo:[:s | s contentsOfEntireFile]. |
6529 | 5231 |
|
5232 |
" |
|
5233 |
'Makefile' asFilename contentsOfEntireFile |
|
5234 |
'foobar' asFilename contentsOfEntireFile |
|
5235 |
" |
|
5236 |
||
5237 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
5238 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
5239 |
! |
|
5240 |
||
5241 |
readingFileDo:aBlock |
|
5242 |
"create a read-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
5243 |
and return the blocks value. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5244 |
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
|
5245 |
(old behavior, will vanish:)the block is evaluated with a nil argument. |
6529 | 5246 |
Ensures that the stream is closed." |
5247 |
||
5248 |
|stream result| |
|
5249 |
||
5250 |
stream := self readStream. |
|
5251 |
[ |
|
5252 |
result := aBlock value:stream |
|
5253 |
] ensure:[ |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5254 |
stream close |
6529 | 5255 |
]. |
5256 |
^ result |
|
5257 |
||
5258 |
" |
|
5259 |
read the first line from some file: |
|
5260 |
||
5261 |
|rslt| |
|
5262 |
||
5263 |
rslt := |
|
5264 |
'/etc/passwd' asFilename |
|
5265 |
readingFileDo:[:s | |
|
5266 |
s nextLine |
|
5267 |
]. |
|
5268 |
Transcript showCR:rslt. |
|
5269 |
" |
|
5270 |
||
5271 |
" |
|
5272 |
find all used shells in /etc/passwd and count their usage: |
|
5273 |
||
5274 |
|rslt| |
|
5275 |
||
5276 |
rslt := |
|
5277 |
'/etc/passwd' asFilename |
|
5278 |
readingFileDo: |
|
5279 |
[:s | |
|
5280 |
|shells| |
|
5281 |
||
5282 |
shells := Bag new. |
|
5283 |
s linesDo: |
|
5284 |
[:line | |
|
5285 |
|parts| |
|
5286 |
||
5287 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
5288 |
shells add:(parts seventh). |
|
5289 |
]. |
|
5290 |
shells contents |
|
5291 |
]. |
|
5292 |
Transcript showCR:rslt. |
|
5293 |
" |
|
6771 | 5294 |
! |
5295 |
||
5296 |
readingLinesDo:aBlock |
|
5297 |
"create a read-stream on the receiver file, |
|
5298 |
evaluate aBlock for each line read from the stream. |
|
5299 |
If the file cannot be opened, an error is raised. |
|
5300 |
Ensures that the stream is closed." |
|
5301 |
||
5302 |
self readingFileDo:[:stream | |
|
5303 |
stream linesDo:aBlock |
|
5304 |
]. |
|
5305 |
||
5306 |
" |
|
5307 |
'/etc/passwd' asFilename |
|
5308 |
readingLinesDo:[:eachLine | |
|
5309 |
Transcript showCR:eachLine. |
|
5310 |
]. |
|
5311 |
" |
|
5312 |
||
5313 |
" |
|
5314 |
'/etc/xxxxx' asFilename |
|
5315 |
readingLinesDo:[:eachLine | |
|
5316 |
Transcript showCR:eachLine. |
|
5317 |
]. |
|
5318 |
" |
|
6529 | 5319 |
! ! |
5320 |
||
2922 | 5321 |
!Filename methodsFor:'special accessing'! |
5322 |
||
5323 |
osName |
|
5324 |
"special - return the OS's name for the receiver." |
|
5325 |
||
5326 |
self isDirectory ifTrue:[ |
|
9453 | 5327 |
^ self osNameForDirectory |
2922 | 5328 |
]. |
5329 |
^ self osNameForFile |
|
5330 |
! |
|
5331 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5332 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5333 |
"internal - return the OS's name for the receiver to |
3665 | 5334 |
access its fileInfo. |
5335 |
This may be redefined for systems, where a special suffix must be |
|
5336 |
added in order to access directories (or others) as a file. |
|
5337 |
(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
|
5338 |
|
7064 | 5339 |
^ self osNameForFile |
3665 | 5340 |
|
5341 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5342 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5343 |
|
2922 | 5344 |
osNameForDirectory |
3753 | 5345 |
"internal - return the OS's name for the receiver to |
2922 | 5346 |
access it as a directory." |
5347 |
||
5348 |
^ nameString |
|
3753 | 5349 |
|
5350 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 5351 |
! |
5352 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5353 |
osNameForDirectoryContents |
3753 | 5354 |
"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
|
5355 |
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
|
5356 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5357 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5358 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5359 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 5360 |
"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
|
5361 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5362 |
|
2922 | 5363 |
osNameForFile |
5364 |
"internal - return the OS's name for the receiver to |
|
5365 |
access it as a file." |
|
5366 |
||
5367 |
^ nameString |
|
5368 |
! ! |
|
5369 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5370 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5371 |
|
11748 | 5372 |
addSuffix:aSuffix |
5373 |
"return a new filename for the receivers name with a different suffix. |
|
5374 |
If the name already has a suffix, the new suffix replaces it; |
|
5375 |
otherwise, the new suffix is simply appended to the name." |
|
5376 |
||
5377 |
|prefixName| |
|
5378 |
||
5379 |
prefixName := self name. |
|
5380 |
aSuffix isEmptyOrNil ifTrue:[ |
|
5381 |
^ self class named:prefixName |
|
5382 |
]. |
|
5383 |
||
5384 |
^ self class named: |
|
5385 |
(prefixName |
|
5386 |
, self class suffixSeparator asString |
|
5387 |
, aSuffix asString) |
|
5388 |
||
5389 |
" |
|
5390 |
'abc.st' asFilename addSuffix:nil |
|
5391 |
'a.b.c' asFilename addSuffix:nil |
|
5392 |
'.b.c.' asFilename addSuffix:nil |
|
5393 |
'.b.c' asFilename addSuffix:nil |
|
5394 |
'.c.' asFilename addSuffix:nil |
|
5395 |
'.c' asFilename addSuffix:nil |
|
5396 |
'c.' asFilename addSuffix:nil |
|
5397 |
'.' asFilename addSuffix:nil |
|
5398 |
||
5399 |
'abc.st' asFilename addSuffix:'o' |
|
5400 |
'abc' asFilename addSuffix:'o' |
|
5401 |
'a.b.c' asFilename addSuffix:'o' |
|
5402 |
'a.b.c.' asFilename addSuffix:'o' |
|
5403 |
'.b.c.' asFilename addSuffix:'o' |
|
5404 |
'.c.' asFilename addSuffix:'o' |
|
5405 |
'.c' asFilename addSuffix:'o' |
|
5406 |
'c.' asFilename addSuffix:'o' |
|
5407 |
'.' asFilename addSuffix:'o' |
|
5408 |
'/foo/bar/baz.st' asFilename addSuffix:'c' |
|
5409 |
'/foo/bar/baz.c' asFilename addSuffix:'st' |
|
5410 |
'/foo/bar.c/baz.c' asFilename addSuffix:'st' |
|
5411 |
'/foo/bar.c/baz' asFilename addSuffix:'st' |
|
5412 |
" |
|
5413 |
! |
|
5414 |
||
2906 | 5415 |
hasSuffix:aSuffixString |
5416 |
"return true if my suffix is the same as aString. |
|
5417 |
This cares for systems, where case is ignored in filenames" |
|
5418 |
||
5419 |
|mySuffix| |
|
5420 |
||
5421 |
mySuffix := self suffix. |
|
5422 |
self class isCaseSensitive ifTrue:[ |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5423 |
^ mySuffix = aSuffixString |
2906 | 5424 |
]. |
5425 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
5426 |
||
5427 |
" |
|
5428 |
'abc.st' asFilename hasSuffix:'st' |
|
5429 |
'abc.ST' asFilename hasSuffix:'st' |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5430 |
'.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
|
5431 |
'.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
|
5432 |
'.foorc.sav' asFilename hasSuffix:'sav' |
2906 | 5433 |
" |
5434 |
||
5435 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
5436 |
! |
|
5437 |
||
10155 | 5438 |
nameWithoutSuffix |
5439 |
"return the receivers name without the suffix. |
|
5440 |
If the name has no suffix, the original name is returned." |
|
5441 |
||
5442 |
|nm idx idxFromEnd| |
|
5443 |
||
5444 |
nm := self baseName. |
|
5445 |
idx := nm lastIndexOf:(self class suffixSeparator). |
|
5446 |
(idx == 0) ifTrue:[^ nameString]. |
|
5447 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
|
5448 |
"/ the suffix is considered empty. |
|
5449 |
(idx == 1) ifTrue:[^ nameString]. |
|
5450 |
||
5451 |
idxFromEnd := nm size - idx. |
|
5452 |
idx := nameString size - idxFromEnd. |
|
5453 |
||
5454 |
^ nameString copyTo:(idx - 1) |
|
5455 |
||
5456 |
" |
|
5457 |
'abc.st' asFilename nameWithoutSuffix |
|
5458 |
'abc' asFilename nameWithoutSuffix |
|
5459 |
'/abc' asFilename nameWithoutSuffix |
|
5460 |
'/abc.d' asFilename nameWithoutSuffix |
|
5461 |
'./abc' asFilename nameWithoutSuffix |
|
5462 |
'./abc.d' asFilename nameWithoutSuffix |
|
5463 |
'./.abc' asFilename nameWithoutSuffix |
|
5464 |
'a.b.c' asFilename nameWithoutSuffix |
|
5465 |
'a.b.' asFilename nameWithoutSuffix |
|
5466 |
'.b.c' asFilename nameWithoutSuffix |
|
5467 |
'.b.' asFilename nameWithoutSuffix |
|
5468 |
'.b' asFilename nameWithoutSuffix |
|
5469 |
'/foo/bar/baz.c' asFilename nameWithoutSuffix |
|
5470 |
'/foo/bar.x/baz.c' asFilename nameWithoutSuffix |
|
5471 |
'/foo/bar.x/baz' asFilename nameWithoutSuffix |
|
5472 |
'/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix |
|
5473 |
'/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix |
|
5474 |
" |
|
5475 |
||
5476 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
|
5477 |
"Created: / 07-11-2006 / 13:55:18 / cg" |
|
5478 |
! |
|
5479 |
||
9453 | 5480 |
prefix |
5481 |
"return my prefix. |
|
5482 |
The suffix is the namepart after the final period character, |
|
5483 |
or the empty string, if the name does not contain a period." |
|
5484 |
||
5485 |
^ self prefixAndSuffix at:1 |
|
5486 |
||
5487 |
" |
|
5488 |
'abc.st' asFilename prefix |
|
5489 |
'abc' asFilename prefix |
|
5490 |
'a.b.c' asFilename prefix |
|
5491 |
'a.b.c' asFilename prefix |
|
5492 |
'a.' asFilename prefix |
|
5493 |
'.a' asFilename prefix |
|
5494 |
" |
|
5495 |
||
5496 |
"Modified: / 07-09-1995 / 11:09:03 / claus" |
|
5497 |
"Created: / 13-07-2006 / 10:27:19 / fm" |
|
5498 |
! |
|
5499 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5500 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5501 |
"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
|
5502 |
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
|
5503 |
the prefix everything before, except for the period. |
1517 | 5504 |
The directory name part is stripped off (i.e. the returned prefix |
5505 |
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
|
5506 |
(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
|
5507 |
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
|
5508 |
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
|
5509 |
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
|
5510 |
'.foorc'. |
1517 | 5511 |
See also: #withoutSuffix and #withSuffix |
5512 |
Notice: |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5513 |
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
|
5514 |
the period character as suffixCharacter." |
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 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5517 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5518 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5519 |
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
|
5520 |
"/ 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
|
5521 |
"/ the suffix is considered empty. |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5522 |
((idx == 1) or:[ idx == 0 ]) ifTrue:[ |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5523 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5524 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5525 |
^ Array |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5526 |
with:(nm copyTo:idx-1) |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5527 |
with:(nm copyFrom:idx+1) |
1049
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 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5530 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5531 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5532 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 5533 |
'/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
|
5534 |
'a.' asFilename prefixAndSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5535 |
'.a' asFilename prefixAndSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5536 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5537 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5538 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 5539 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5540 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5541 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5542 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 5543 |
"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
|
5544 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5545 |
|
2906 | 5546 |
suffix |
5547 |
"return my suffix. |
|
5548 |
The suffix is the namepart after the final period character, |
|
5549 |
or the empty string, if the name does not contain a period." |
|
5550 |
||
5551 |
^ self prefixAndSuffix at:2 |
|
5552 |
||
5553 |
" |
|
5554 |
'abc.st' asFilename suffix |
|
5555 |
'abc' asFilename suffix |
|
5556 |
'a.b.c' asFilename suffix |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5557 |
'a.b.c' asFilename suffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5558 |
'a.' asFilename suffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5559 |
'.a' asFilename suffix |
2906 | 5560 |
" |
5561 |
||
5562 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
5563 |
! |
|
5564 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5565 |
withSuffix:aSuffix |
2922 | 5566 |
"return a new filename for the receivers name with a different suffix. |
6256 | 5567 |
If the name already has a suffix, the new suffix replaces it; |
1993 | 5568 |
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
|
5569 |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5570 |
|prefixName| |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5571 |
|
10155 | 5572 |
prefixName := self nameWithoutSuffix. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5573 |
aSuffix isEmptyOrNil ifTrue:[ |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5574 |
^ self class named:prefixName |
6262 | 5575 |
]. |
5576 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5577 |
^ self class named: |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5578 |
(prefixName |
6256 | 5579 |
, self class suffixSeparator asString |
5580 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5581 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5582 |
" |
6262 | 5583 |
'abc.st' asFilename withSuffix:nil |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5584 |
'a.b.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5585 |
'.b.c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5586 |
'.b.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5587 |
'.c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5588 |
'.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5589 |
'c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5590 |
'.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5591 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5592 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5593 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5594 |
'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
|
5595 |
'a.b.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5596 |
'.b.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5597 |
'.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5598 |
'.c' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5599 |
'c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5600 |
'.' asFilename withSuffix:'o' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5601 |
'/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
|
5602 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 5603 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 5604 |
'/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
|
5605 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5606 |
|
10155 | 5607 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
5608 |
"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
|
5609 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5610 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5611 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5612 |
"return a new filename for the receivers name without the suffix. |
10155 | 5613 |
If the name has no suffix, a filename representing the same file as the receiver is returned." |
5614 |
||
5615 |
|n| |
|
5616 |
||
5617 |
n := self nameWithoutSuffix. |
|
5618 |
n = nameString ifTrue:[^ self]. |
|
5619 |
^ self class named:n |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5620 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5621 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5622 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5623 |
'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
|
5624 |
'/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
|
5625 |
'/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
|
5626 |
'./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
|
5627 |
'./abc.d' asFilename withoutSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5628 |
'./.abc' asFilename withoutSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5629 |
'a.b.c' asFilename withoutSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5630 |
'a.b.' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5631 |
'.b.c' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5632 |
'.b.' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5633 |
'.b' asFilename withoutSuffix |
1516 | 5634 |
'/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
|
5635 |
'/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
|
5636 |
'/foo/bar.x/baz' asFilename withoutSuffix |
1516 | 5637 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
5638 |
'/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
|
5639 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5640 |
|
10155 | 5641 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
5642 |
"Modified: / 07-11-2006 / 13:57:45 / cg" |
|
174 | 5643 |
! ! |
5644 |
||
5597 | 5645 |
!Filename methodsFor:'testing'! |
5646 |
||
5647 |
isFilename |
|
5648 |
"return true, if the receiver is some kind of filename; |
|
5649 |
false is returned here - the method is redefined from Object." |
|
5650 |
||
5651 |
^true |
|
5652 |
||
5653 |
||
5654 |
! ! |
|
5655 |
||
10271 | 5656 |
!Filename methodsFor:'writing-files'! |
5657 |
||
10779 | 5658 |
contents:aStringOrCollectionOfLines |
10271 | 5659 |
"create (or overwrite) a file given its contents as a collection of lines. |
5660 |
Raises an error, if the file is unwritable." |
|
5661 |
||
10779 | 5662 |
^ self |
5663 |
writingFileDo:[:s | |
|
11748 | 5664 |
aStringOrCollectionOfLines isNonByteCollection ifTrue:[ |
5665 |
"a StringCollection or a collection of lines" |
|
5666 |
aStringOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')] |
|
5667 |
] ifFalse:[ |
|
5668 |
"something string-like" |
|
10779 | 5669 |
s nextPutAll:aStringOrCollectionOfLines |
5670 |
] |
|
5671 |
]. |
|
5672 |
||
5673 |
" |
|
5674 |
'foo1' asFilename contents:#('one' 'two' 'three') |
|
5675 |
'foo2' asFilename contents:'Hello world' |
|
10271 | 5676 |
" |
5677 |
||
5678 |
"Created: / 11-12-2006 / 14:11:21 / cg" |
|
10779 | 5679 |
"Modified: / 08-11-2007 / 13:28:41 / cg" |
10271 | 5680 |
! |
5681 |
||
5682 |
writingFileDo:aBlock |
|
5683 |
"create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
5684 |
and return the blocks value. |
|
5685 |
If the file cannot be opened, an exception is raised. |
|
5686 |
Ensures that the stream is closed." |
|
5687 |
||
5688 |
|stream result| |
|
5689 |
||
5690 |
stream := self writeStream. |
|
5691 |
[ |
|
5692 |
result := aBlock value:stream |
|
5693 |
] ensure:[ |
|
5694 |
stream close |
|
5695 |
]. |
|
5696 |
^ result |
|
5697 |
||
5698 |
" |
|
5699 |
'ttt' asFilename writingFileDo:[:s | |
|
5700 |
s nextPutLine:'hello'. |
|
5701 |
s nextPutLine:'world'. |
|
5702 |
] |
|
5703 |
" |
|
5704 |
||
5705 |
"Created: / 11-12-2006 / 14:09:39 / cg" |
|
5706 |
! ! |
|
5707 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
5708 |
!Filename class methodsFor:'documentation'! |
630 | 5709 |
|
5710 |
version |
|
11784 | 5711 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.342 2009-06-22 21:56:50 stefan Exp $' |
630 | 5712 |
! ! |
6771 | 5713 |
|
2906 | 5714 |
Filename initialize! |