1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
Collection subclass:#FileDirectory
|
|
14 |
instanceVariableNames:'pathName lazy'
|
31
|
15 |
classVariableNames:'PathOfCurrentDirectory'
|
1
|
16 |
poolDictionaries:''
|
|
17 |
category:'Collections-Files'
|
|
18 |
!
|
|
19 |
|
|
20 |
FileDirectory comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
1
|
22 |
All Rights Reserved
|
92
|
23 |
|
|
24 |
$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.11 1994-08-05 00:54:45 claus Exp $
|
88
|
25 |
'!
|
1
|
26 |
|
88
|
27 |
!FileDirectory class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
1
|
33 |
|
88
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
1
|
42 |
|
88
|
43 |
version
|
|
44 |
"
|
92
|
45 |
$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.11 1994-08-05 00:54:45 claus Exp $
|
88
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
FileDirectories represent directories in the underlying host system.
|
|
52 |
They provide various methods to create/delete and query for files and/or
|
|
53 |
directories.
|
|
54 |
"
|
|
55 |
! !
|
1
|
56 |
|
2
|
57 |
!FileDirectory class methodsFor:'initialization'!
|
|
58 |
|
|
59 |
initialize
|
|
60 |
super initialize.
|
|
61 |
ObjectMemory addDependent:self
|
|
62 |
!
|
|
63 |
|
|
64 |
update:something
|
|
65 |
something == #restarted ifTrue:[
|
31
|
66 |
PathOfCurrentDirectory := nil
|
2
|
67 |
]
|
|
68 |
! !
|
|
69 |
|
1
|
70 |
!FileDirectory class methodsFor:'instance creation'!
|
|
71 |
|
|
72 |
rootDirectory
|
|
73 |
"create and return a new FileDirectory for the root directory"
|
|
74 |
|
|
75 |
^ (self basicNew) pathName:'/'
|
88
|
76 |
|
|
77 |
"
|
|
78 |
FileDirectory rootDirectory contents
|
|
79 |
FileDirectory rootDirectory files
|
|
80 |
FileDirectory rootDirectory isReadable
|
|
81 |
"
|
1
|
82 |
!
|
|
83 |
|
|
84 |
currentDirectory
|
|
85 |
"create and return a new FileDirectory for the current directory"
|
|
86 |
|
|
87 |
^ (self basicNew) pathName:'.'
|
88
|
88 |
|
|
89 |
"
|
|
90 |
FileDirectory currentDirectory contents
|
|
91 |
FileDirectory currentDirectory files
|
|
92 |
FileDirectory currentDirectory isReadable
|
|
93 |
FileDirectory currentDirectory pathName
|
|
94 |
"
|
1
|
95 |
!
|
|
96 |
|
|
97 |
directoryNamed:name
|
|
98 |
"create and return a new FileDirectory for the directory
|
|
99 |
with given pathname"
|
|
100 |
|
|
101 |
^ (self basicNew) pathName:name
|
88
|
102 |
|
|
103 |
"
|
|
104 |
(FileDirectory directoryNamed:'..') pathName
|
|
105 |
(FileDirectory directoryNamed:'../..') files
|
|
106 |
"
|
1
|
107 |
!
|
|
108 |
|
|
109 |
directoryNamed:name in:aFileDirectory
|
|
110 |
"create and return a new FileDirectory for the directory with given name
|
|
111 |
in another FileDirectory"
|
|
112 |
|
|
113 |
|baseName|
|
|
114 |
|
|
115 |
((name at:1) == $/) ifTrue:[
|
|
116 |
^ self directoryNamed:name
|
|
117 |
].
|
|
118 |
(aFileDirectory isKindOf:FileDirectory) ifTrue:[
|
|
119 |
baseName := aFileDirectory pathName
|
|
120 |
] ifFalse:[
|
|
121 |
baseName := aFileDirectory
|
|
122 |
].
|
|
123 |
"
|
|
124 |
(name = '..') ifTrue:[
|
|
125 |
^ (self basicNew) pathName:(OperatingSystem directoryNameOf:baseName)
|
|
126 |
].
|
|
127 |
"
|
|
128 |
(name = '.') ifTrue:[^ aFileDirectory].
|
|
129 |
|
|
130 |
(baseName = '/') ifFalse:[
|
|
131 |
(baseName endsWith:'/') ifFalse:[
|
|
132 |
baseName := baseName , '/'
|
|
133 |
]
|
|
134 |
].
|
|
135 |
^ (self basicNew) pathName:(baseName , name)
|
|
136 |
! !
|
|
137 |
|
|
138 |
!FileDirectory methodsFor:'accessing'!
|
|
139 |
|
|
140 |
baseName
|
|
141 |
"return my baseName
|
|
142 |
- thats the directory name without leading parent-dirs"
|
|
143 |
|
|
144 |
lazy ifTrue:[self getFullPathName].
|
|
145 |
^ OperatingSystem baseNameOf:pathName
|
|
146 |
!
|
|
147 |
|
|
148 |
directoryName
|
|
149 |
"return my directoryName
|
|
150 |
- thats the directory name where I'm in"
|
|
151 |
|
|
152 |
lazy ifTrue:[self getFullPathName].
|
|
153 |
^ OperatingSystem directoryNameOf:pathName
|
|
154 |
!
|
|
155 |
|
|
156 |
pathName
|
|
157 |
"return my full pathname"
|
|
158 |
|
|
159 |
lazy ifTrue:[self getFullPathName].
|
|
160 |
^ pathName
|
|
161 |
!
|
|
162 |
|
|
163 |
pathName:dirName
|
|
164 |
"set my pathname; return nil if not a valid path; self otherwise"
|
|
165 |
|
|
166 |
pathName := dirName.
|
|
167 |
(dirName startsWith:'/') ifFalse:[
|
|
168 |
lazy := true
|
|
169 |
] ifTrue:[
|
|
170 |
(dirName includes:$.) ifTrue:[
|
|
171 |
lazy := true
|
|
172 |
]
|
|
173 |
].
|
|
174 |
^ self
|
|
175 |
"
|
|
176 |
(OperatingSystem isDirectory:pathName) ifFalse:[^ nil]
|
|
177 |
"
|
|
178 |
!
|
|
179 |
|
|
180 |
contents
|
|
181 |
"return a collection with all files and subdirectories in the receiver"
|
|
182 |
|
|
183 |
|coll|
|
|
184 |
|
|
185 |
coll := OrderedCollection new.
|
|
186 |
self do:[:name |
|
|
187 |
coll add:name
|
|
188 |
].
|
|
189 |
(coll size ~~ 0) ifTrue:[
|
|
190 |
coll sort
|
|
191 |
].
|
|
192 |
^ coll
|
|
193 |
!
|
|
194 |
|
|
195 |
directories
|
|
196 |
"return a collection with all subdirectories in the receiver directory"
|
|
197 |
|
|
198 |
|coll|
|
|
199 |
|
|
200 |
coll := OrderedCollection new.
|
|
201 |
self directoriesDo:[:name |
|
|
202 |
coll add:name
|
|
203 |
].
|
|
204 |
(coll size ~~ 0) ifTrue:[
|
|
205 |
coll sort
|
|
206 |
].
|
|
207 |
^ coll
|
|
208 |
!
|
|
209 |
|
|
210 |
files
|
|
211 |
"return a collection with all plain files in the receiver directory"
|
|
212 |
|
|
213 |
|coll|
|
|
214 |
|
|
215 |
coll := OrderedCollection new.
|
|
216 |
self filesDo:[:name |
|
|
217 |
coll add:name
|
|
218 |
].
|
|
219 |
^ coll sort
|
|
220 |
! !
|
|
221 |
|
|
222 |
!FileDirectory methodsFor:'private'!
|
|
223 |
|
|
224 |
getFullPathName
|
|
225 |
"make my pathname be a full pathname - i.e. starting at root"
|
|
226 |
|
|
227 |
|aStream command shortPathName fullPathName|
|
|
228 |
|
|
229 |
(pathName = '/') ifTrue:[
|
|
230 |
lazy := false.
|
|
231 |
^ self
|
|
232 |
].
|
|
233 |
|
|
234 |
"since currentDirectory is used very often, cache its path here"
|
|
235 |
|
|
236 |
(pathName = '.') ifTrue:[
|
31
|
237 |
PathOfCurrentDirectory notNil ifTrue:[
|
|
238 |
pathName := PathOfCurrentDirectory.
|
1
|
239 |
lazy := false.
|
|
240 |
^ self
|
|
241 |
]
|
|
242 |
].
|
|
243 |
|
|
244 |
shortPathName := pathName.
|
|
245 |
|
13
|
246 |
"some have a convenient function for this ..."
|
|
247 |
%{ /* STACK: 16000 */
|
|
248 |
#ifdef HAS_REALPATH
|
1
|
249 |
# include <stdlib.h>
|
|
250 |
# include <sys/param.h>
|
|
251 |
|
|
252 |
char nameBuffer[MAXPATHLEN + 1];
|
|
253 |
|
|
254 |
if (realpath(_stringVal(_INST(pathName)), nameBuffer)) {
|
3
|
255 |
fullPathName = _MKSTRING(nameBuffer COMMA_CON);
|
1
|
256 |
}
|
|
257 |
#endif
|
|
258 |
%}
|
|
259 |
.
|
|
260 |
fullPathName notNil ifTrue:[
|
3
|
261 |
pathName := fullPathName.
|
|
262 |
lazy := false
|
1
|
263 |
] ifFalse:[
|
|
264 |
"since there might be symbolic links and other stuff involved,
|
|
265 |
better trust pwd than removing '..' by ourself
|
|
266 |
- although this is very slow"
|
|
267 |
|
|
268 |
command := 'cd ' , pathName , '; pwd'.
|
|
269 |
aStream := PipeStream readingFrom:command.
|
|
270 |
aStream isNil ifFalse:[
|
|
271 |
(aStream atEnd) ifFalse:[
|
|
272 |
fullPathName := aStream nextLine
|
|
273 |
].
|
|
274 |
aStream close.
|
|
275 |
fullPathName notNil ifTrue:[
|
|
276 |
pathName := fullPathName.
|
|
277 |
lazy := false
|
|
278 |
]
|
|
279 |
] ifTrue:[
|
|
280 |
self error:('PipeStream for <' , command , '> failed').
|
|
281 |
"by clearing lazy, we avoid triggering the error again"
|
|
282 |
lazy := false
|
|
283 |
]
|
|
284 |
].
|
|
285 |
|
|
286 |
"if it was the current dir, keep name for next query"
|
|
287 |
(shortPathName = '.') ifTrue:[
|
31
|
288 |
PathOfCurrentDirectory := fullPathName
|
1
|
289 |
]
|
|
290 |
! !
|
|
291 |
|
|
292 |
!FileDirectory methodsFor:'basic'!
|
|
293 |
|
|
294 |
createDirectory:newName
|
|
295 |
"create a new filedirectory as a subdirectory of myself;
|
|
296 |
return true if successful"
|
|
297 |
|
|
298 |
|realName|
|
|
299 |
|
|
300 |
(newName = '.') ifFalse:[
|
|
301 |
(newName = '..') ifFalse:[
|
|
302 |
((newName at:1) == $/) ifTrue:[
|
|
303 |
realName := newName copyFrom:2
|
|
304 |
] ifFalse:[
|
|
305 |
realName := newName
|
|
306 |
].
|
|
307 |
(realName startsWith:'/') ifTrue:[
|
|
308 |
^ OperatingSystem createDirectory:realName
|
|
309 |
] ifFalse:[
|
|
310 |
^ OperatingSystem createDirectory:(pathName , '/' , realName)
|
|
311 |
]
|
|
312 |
]
|
|
313 |
].
|
|
314 |
^ false
|
|
315 |
!
|
|
316 |
|
|
317 |
removeFile:fileName
|
|
318 |
"remove the file 'fileName' from myself; return true if successful"
|
|
319 |
|
|
320 |
(fileName startsWith:'/') ifTrue:[
|
|
321 |
^ OperatingSystem removeFile:fileName
|
|
322 |
].
|
|
323 |
^ OperatingSystem removeFile:(pathName , '/' , fileName)
|
|
324 |
!
|
|
325 |
|
|
326 |
removeDirectory:dirName
|
19
|
327 |
"remove the directory 'dirName' from myself; return true if successful.
|
20
|
328 |
If the directory is not empty, the containing files/directories are also
|
19
|
329 |
removed."
|
|
330 |
|
|
331 |
|absPath|
|
1
|
332 |
|
|
333 |
(dirName startsWith:'/') ifTrue:[
|
19
|
334 |
absPath := dirName
|
|
335 |
] ifFalse:[
|
|
336 |
absPath := pathName , '/' , dirName
|
1
|
337 |
].
|
19
|
338 |
(OperatingSystem removeDirectory:absPath) ifTrue:[^ true].
|
|
339 |
^ OperatingSystem recursiveRemoveDirectory:absPath
|
1
|
340 |
!
|
|
341 |
|
|
342 |
remove:aFileOrDirectoryName
|
|
343 |
"remove the file or directory from myself; return true if successful"
|
|
344 |
|
|
345 |
|path|
|
|
346 |
|
|
347 |
(aFileOrDirectoryName startsWith:'/') ifTrue:[
|
|
348 |
path := aFileOrDirectoryName
|
|
349 |
] ifFalse:[
|
|
350 |
path := (pathName , '/' , aFileOrDirectoryName)
|
|
351 |
].
|
|
352 |
(OperatingSystem isDirectory:path) ifTrue:[
|
|
353 |
^ OperatingSystem removeDirectory:path
|
|
354 |
].
|
|
355 |
^ OperatingSystem removeFile:path
|
|
356 |
!
|
|
357 |
|
|
358 |
link:oldFileName to:newFileName
|
|
359 |
"link oldFileName to newFileName in myself, return true if successful"
|
|
360 |
|
|
361 |
|path1 path2|
|
|
362 |
|
|
363 |
(oldFileName startsWith:'/') ifTrue:[
|
|
364 |
path1 := oldFileName
|
|
365 |
] ifFalse:[
|
|
366 |
path1 := (pathName , '/' , oldFileName)
|
|
367 |
].
|
|
368 |
(newFileName startsWith:'/') ifTrue:[
|
|
369 |
path2 := newFileName
|
|
370 |
] ifFalse:[
|
|
371 |
path2 := (pathName , '/' , newFileName)
|
|
372 |
].
|
54
|
373 |
^ OperatingSystem linkFile:path1 to:path2
|
1
|
374 |
!
|
|
375 |
|
|
376 |
renameFile:oldFileName newName:newFileName
|
|
377 |
"rename the file; return true if successful"
|
|
378 |
|
|
379 |
|path1 path2|
|
|
380 |
|
|
381 |
(oldFileName startsWith:'/') ifTrue:[
|
|
382 |
path1 := oldFileName
|
|
383 |
] ifFalse:[
|
|
384 |
path1 := (pathName , '/' , oldFileName)
|
|
385 |
].
|
|
386 |
(newFileName startsWith:'/') ifTrue:[
|
|
387 |
path2 := newFileName
|
|
388 |
] ifFalse:[
|
|
389 |
path2 := (pathName , '/' , newFileName)
|
|
390 |
].
|
54
|
391 |
^ OperatingSystem renameFile:path1 to:path2
|
1
|
392 |
! !
|
|
393 |
|
|
394 |
!FileDirectory methodsFor:'queries'!
|
|
395 |
|
|
396 |
id
|
|
397 |
"return the directories file-id (inode number)"
|
|
398 |
|
|
399 |
^ OperatingSystem idOf:pathName
|
|
400 |
!
|
|
401 |
|
|
402 |
exists
|
|
403 |
"return true if this directory exists"
|
|
404 |
|
|
405 |
^ OperatingSystem isDirectory:pathName
|
|
406 |
"(FileDirectory directoryNamed:'fooBar') exists"
|
|
407 |
!
|
|
408 |
|
3
|
409 |
isEmpty
|
|
410 |
"return true, if the directory is empty;
|
|
411 |
redefined since '.' and '..' do not count as entries here."
|
|
412 |
|
|
413 |
self do:[:fName |
|
|
414 |
((fName ~= '.') and:[fName ~= '..']) ifTrue:[^ false].
|
|
415 |
].
|
|
416 |
^ true
|
|
417 |
!
|
|
418 |
|
1
|
419 |
infoOf:name
|
|
420 |
"return an array filled with file info for the file 'aFileName';
|
|
421 |
return nil if such a file does not exist"
|
|
422 |
|
|
423 |
(name startsWith:'/') ifTrue:[
|
|
424 |
^ OperatingSystem infoOf:name
|
|
425 |
].
|
|
426 |
^ OperatingSystem infoOf:(pathName , '/' , name)
|
|
427 |
!
|
|
428 |
|
|
429 |
timeOfLastChange:name
|
|
430 |
"return the timeStamp of a file in myself"
|
|
431 |
|
|
432 |
(name startsWith:'/') ifTrue:[
|
|
433 |
^ OperatingSystem timeOfLastChange:name
|
|
434 |
].
|
|
435 |
^ OperatingSystem timeOfLastChange:(pathName , '/' , name)
|
|
436 |
!
|
|
437 |
|
|
438 |
timeOfLastChange
|
|
439 |
"return the timeStamp of myself"
|
|
440 |
|
|
441 |
^ OperatingSystem timeOfLastChange:pathName
|
|
442 |
!
|
|
443 |
|
|
444 |
accessModeOf:aFileName
|
|
445 |
"return the access-mode bits (rwxrwxrwx) of a file in myself"
|
|
446 |
|
|
447 |
(aFileName startsWith:'/') ifTrue:[
|
|
448 |
^ OperatingSystem accessModeOf:aFileName
|
|
449 |
].
|
|
450 |
^ OperatingSystem accessModeOf:(pathName , '/' , aFileName)
|
|
451 |
!
|
|
452 |
|
|
453 |
changeAccessModeOf:aFileName to:modeBits
|
|
454 |
"set the access-mode bits (rwxrwxrwx) of a file in myself"
|
|
455 |
|
|
456 |
(aFileName startsWith:'/') ifTrue:[
|
|
457 |
^ OperatingSystem changeAccessModeOf:aFileName
|
|
458 |
to:modeBits
|
|
459 |
].
|
|
460 |
^ OperatingSystem changeAccessModeOf:(pathName , '/' , aFileName)
|
|
461 |
to:modeBits
|
|
462 |
!
|
|
463 |
|
|
464 |
typeOf:aFileName
|
|
465 |
"return the symbolic type of a file in myself"
|
|
466 |
|
|
467 |
(aFileName startsWith:'/') ifTrue:[
|
|
468 |
^ OperatingSystem typeOf:aFileName
|
|
469 |
].
|
|
470 |
^ OperatingSystem typeOf:(pathName , '/' , aFileName)
|
|
471 |
!
|
|
472 |
|
92
|
473 |
exists:name
|
|
474 |
"return true, if the given name exists in myself"
|
|
475 |
|
|
476 |
(name startsWith:'/') ifTrue:[
|
|
477 |
^ OperatingSystem isValidPath:name
|
|
478 |
].
|
|
479 |
^ OperatingSystem isValidPath:(pathName , '/' , name)
|
|
480 |
!
|
|
481 |
|
1
|
482 |
isDirectory:name
|
|
483 |
"return true, if the given name is that of a directory in myself"
|
|
484 |
|
|
485 |
(name startsWith:'/') ifTrue:[
|
|
486 |
^ OperatingSystem isDirectory:name
|
|
487 |
].
|
|
488 |
^ OperatingSystem isDirectory:(pathName , '/' , name)
|
|
489 |
!
|
|
490 |
|
|
491 |
isReadable:name
|
|
492 |
"return true, if the given file is readable"
|
|
493 |
|
|
494 |
(name startsWith:'/') ifTrue:[
|
|
495 |
^ OperatingSystem isReadable:name
|
|
496 |
].
|
|
497 |
^ OperatingSystem isReadable:(pathName , '/' , name)
|
|
498 |
!
|
|
499 |
|
|
500 |
isWritable:name
|
|
501 |
"return true, if the given file is readable"
|
|
502 |
|
|
503 |
(name startsWith:'/') ifTrue:[
|
|
504 |
^ OperatingSystem isWritable:name
|
|
505 |
].
|
|
506 |
^ OperatingSystem isWritable:(pathName , '/' , name)
|
|
507 |
!
|
|
508 |
|
|
509 |
isExecutable:name
|
|
510 |
"return true, if the given file is executable"
|
|
511 |
|
|
512 |
(name startsWith:'/') ifTrue:[
|
|
513 |
^ OperatingSystem isExecutable:name
|
|
514 |
].
|
|
515 |
^ OperatingSystem isExecutable:(pathName , '/' , name)
|
|
516 |
! !
|
|
517 |
|
|
518 |
!FileDirectory methodsFor:'printing & storing'!
|
|
519 |
|
|
520 |
printString
|
|
521 |
lazy ifTrue:[self getFullPathName].
|
|
522 |
^ '(a FileDirectory pathName:' , pathName, ')'
|
|
523 |
!
|
|
524 |
|
|
525 |
storeOn:aStream
|
|
526 |
lazy ifTrue:[self getFullPathName].
|
|
527 |
aStream nextPutAll:'(FileDirectory directoryNamed:'.
|
|
528 |
aStream nextPutAll:pathName.
|
|
529 |
aStream nextPut:$)
|
|
530 |
! !
|
|
531 |
|
|
532 |
!FileDirectory methodsFor:'more instance creation'!
|
|
533 |
|
|
534 |
directoryNamed:aName
|
|
535 |
^ self class directoryNamed:aName in:self pathName
|
|
536 |
! !
|
|
537 |
|
|
538 |
!FileDirectory methodsFor:'enumerating'!
|
|
539 |
|
|
540 |
where:testBlock do:aBlock
|
|
541 |
"evaluate the argument, aBlock for every object in the directory
|
|
542 |
for which testBlock evaluates to true."
|
|
543 |
|
|
544 |
|aStream name|
|
|
545 |
|
|
546 |
aStream := DirectoryStream directoryNamed:pathName.
|
|
547 |
aStream isNil ifTrue:[^ nil].
|
|
548 |
[aStream atEnd] whileFalse:[
|
|
549 |
name := aStream nextLine.
|
|
550 |
name notNil ifTrue:[
|
|
551 |
(testBlock value:name) ifTrue:[
|
|
552 |
aBlock value:name
|
|
553 |
]
|
|
554 |
]
|
|
555 |
].
|
|
556 |
aStream close
|
|
557 |
!
|
|
558 |
|
|
559 |
do:aBlock
|
|
560 |
"evaluate the argument, aBlock for every name in the directory"
|
|
561 |
|
|
562 |
self where:[:name | true] do:aBlock
|
|
563 |
!
|
|
564 |
|
|
565 |
namesDo:aBlock
|
|
566 |
"evaluate the argument, aBlock for every name in the directory.
|
|
567 |
for ST-80 compatibility"
|
|
568 |
|
|
569 |
self do:aBlock
|
|
570 |
!
|
|
571 |
|
|
572 |
filesDo:aBlock
|
|
573 |
"evaluate the argument, aBlock for every plain file name in the directory"
|
|
574 |
|
|
575 |
self where:[:name | (self isDirectory:name) not] do:aBlock
|
|
576 |
!
|
|
577 |
|
|
578 |
directoriesDo:aBlock
|
|
579 |
"evaluate the argument, aBlock for every subdirectory name in the directory"
|
|
580 |
|
|
581 |
self where:[:name | (self isDirectory:name) ifTrue:[
|
|
582 |
((name ~= '.') and:[name ~= '..'])
|
|
583 |
] ifFalse:[
|
|
584 |
false
|
|
585 |
]
|
|
586 |
] do:aBlock
|
|
587 |
!
|
|
588 |
|
|
589 |
allFilesDo:aBlock
|
|
590 |
"evaluate the argument, aBlock for every file name in the directory and in all
|
|
591 |
subdirectories"
|
|
592 |
|
|
593 |
|aStream command line|
|
|
594 |
|
|
595 |
lazy ifTrue:[self getFullPathName].
|
|
596 |
command := 'cd ' , pathName , '; find . -print'.
|
|
597 |
aStream := PipeStream readingFrom:command.
|
|
598 |
aStream isNil ifTrue:[^ nil].
|
|
599 |
[aStream atEnd] whileFalse:[
|
|
600 |
line := aStream nextLine.
|
|
601 |
line notNil ifTrue:[
|
|
602 |
(line = '.') ifFalse:[
|
|
603 |
"cut off initial ./"
|
54
|
604 |
line := line copyFrom:3
|
1
|
605 |
].
|
|
606 |
aBlock value:line
|
|
607 |
]
|
|
608 |
].
|
|
609 |
aStream close
|
|
610 |
!
|
|
611 |
|
|
612 |
allDirectoriesDo:aBlock
|
|
613 |
"evaluate the argument, aBlock for every directory name
|
|
614 |
in the directory and in all subdirectories"
|
|
615 |
|
|
616 |
|aStream command line|
|
|
617 |
|
|
618 |
lazy ifTrue:[self getFullPathName].
|
|
619 |
command := 'cd ' , pathName , '; find . -type d -print'.
|
|
620 |
aStream := PipeStream readingFrom:command.
|
|
621 |
aStream isNil ifTrue:[^ nil].
|
|
622 |
[aStream atEnd] whileFalse:[
|
|
623 |
line := aStream nextLine.
|
|
624 |
line notNil ifTrue:[
|
|
625 |
(line = '.') ifFalse:[
|
|
626 |
"cut off initial ./"
|
54
|
627 |
line := line copyFrom:3
|
1
|
628 |
].
|
|
629 |
aBlock value:line
|
|
630 |
]
|
|
631 |
].
|
|
632 |
aStream close
|
|
633 |
! !
|