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