author | Claus Gittinger <cg@exept.de> |
Mon, 08 Jan 2001 17:36:43 +0100 | |
changeset 5777 | 69a22679b0af |
parent 5729 | 63af78505f23 |
child 6550 | adb966d9afc9 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
172 | 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 |
||
5556 | 13 |
"{ Package: 'stx:libbasic' }" |
14 |
||
1 | 15 |
Collection subclass:#FileDirectory |
1290 | 16 |
instanceVariableNames:'pathName lazy' |
17 |
classVariableNames:'PathOfCurrentDirectory' |
|
18 |
poolDictionaries:'' |
|
3203
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
19 |
category:'Obsolete' |
1 | 20 |
! |
21 |
||
88 | 22 |
!FileDirectory class methodsFor:'documentation'! |
23 |
||
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
172 | 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 |
! |
|
1 | 37 |
|
88 | 38 |
documentation |
39 |
" |
|
3203
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
40 |
Notice: |
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
41 |
This class is obsolete and does work only under UNIX. |
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
42 |
Use Filename instead. |
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
43 |
|
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
44 |
This class is not available in other ST-systems; |
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
45 |
in contrast, ST-80 provides a Filename class. |
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
46 |
Therefore, Filename has taken over the functionality. |
09a9b6bde8af
Moved into category 'Obsolete'.
Stefan Vogel <sv@exept.de>
parents:
3201
diff
changeset
|
47 |
|
88 | 48 |
FileDirectories represent directories in the underlying host system. |
49 |
They provide various methods to create/delete and query for files and/or |
|
202 | 50 |
directories. Also, since FileDirectory inherits from Collection, it |
51 |
provides all enumeration and testing protocol. For example, you can |
|
52 |
loop over the filenames in a directory using 'aFileDirectory do:[:nm | ...]'. |
|
53 |
||
1290 | 54 |
[author:] |
55 |
Claus Gittinger |
|
56 |
||
57 |
[see also:] |
|
58 |
Filename |
|
59 |
FileStream DirectoryStream OperatingSystem |
|
88 | 60 |
" |
61 |
! ! |
|
1 | 62 |
|
2 | 63 |
!FileDirectory class methodsFor:'initialization'! |
64 |
||
65 |
initialize |
|
276 | 66 |
"/ |
67 |
"/ want to know about image restart |
|
68 |
"/ |
|
2 | 69 |
ObjectMemory addDependent:self |
70 |
! |
|
71 |
||
1469 | 72 |
update:something with:aParameter from:changedObject |
276 | 73 |
"/ |
74 |
"/ currentDirectory may be different when restarted |
|
75 |
"/ |
|
3941
574defdaaa40
flush cached current-dir-path earlier.
Claus Gittinger <cg@exept.de>
parents:
3203
diff
changeset
|
76 |
something == #earlySystemInstallation ifTrue:[ |
1469 | 77 |
PathOfCurrentDirectory := nil |
2 | 78 |
] |
1469 | 79 |
|
3941
574defdaaa40
flush cached current-dir-path earlier.
Claus Gittinger <cg@exept.de>
parents:
3203
diff
changeset
|
80 |
"Created: / 15.6.1996 / 15:20:21 / cg" |
574defdaaa40
flush cached current-dir-path earlier.
Claus Gittinger <cg@exept.de>
parents:
3203
diff
changeset
|
81 |
"Modified: / 11.12.1998 / 16:28:40 / cg" |
2 | 82 |
! ! |
83 |
||
1 | 84 |
!FileDirectory class methodsFor:'instance creation'! |
85 |
||
86 |
currentDirectory |
|
87 |
"create and return a new FileDirectory for the current directory" |
|
88 |
||
2951 | 89 |
"/ self obsoleteMethodWarning:'use Filename'. |
2921 | 90 |
^ (self basicNew) pathName:(Filename currentDirectory name) |
88 | 91 |
|
92 |
" |
|
93 |
FileDirectory currentDirectory contents |
|
94 |
FileDirectory currentDirectory files |
|
95 |
FileDirectory currentDirectory isReadable |
|
96 |
FileDirectory currentDirectory pathName |
|
97 |
" |
|
1 | 98 |
! |
99 |
||
605 | 100 |
directoryNamed:name |
101 |
"create and return a new FileDirectory for the directory |
|
102 |
with given pathname" |
|
103 |
||
2951 | 104 |
"/ self obsoleteMethodWarning:'use Filename'. |
2921 | 105 |
name asString = '.' ifTrue:[ |
106 |
Filename currentDirectory name ~= '.' ifTrue:[ |
|
107 |
^ self currentDirectory |
|
108 |
] |
|
109 |
]. |
|
110 |
^ (self basicNew) pathName:(name asFilename constructString:'') |
|
605 | 111 |
|
112 |
" |
|
113 |
(FileDirectory directoryNamed:'..') pathName |
|
114 |
(FileDirectory directoryNamed:'../..') files |
|
115 |
" |
|
116 |
! |
|
117 |
||
1 | 118 |
directoryNamed:name in:aFileDirectory |
119 |
"create and return a new FileDirectory for the directory with given name |
|
120 |
in another FileDirectory" |
|
121 |
||
2961 | 122 |
|baseName| |
1 | 123 |
|
2951 | 124 |
"/ self obsoleteMethodWarning:'use Filename'. |
2921 | 125 |
|
126 |
name asFilename isAbsolute ifTrue:[ |
|
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
127 |
^ self directoryNamed:name |
1 | 128 |
]. |
2921 | 129 |
|
1 | 130 |
(aFileDirectory isKindOf:FileDirectory) ifTrue:[ |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
131 |
baseName := aFileDirectory pathName |
1 | 132 |
] ifFalse:[ |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
133 |
baseName := aFileDirectory |
1 | 134 |
]. |
2921 | 135 |
^ (self basicNew) pathName:((Filename named:baseName) constructString:name) |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
136 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
137 |
"Modified: 28.4.1997 / 23:23:51 / cg" |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
138 |
"Modified: 28.4.1997 / 22:34:47 / dq" |
605 | 139 |
! |
140 |
||
141 |
rootDirectory |
|
142 |
"create and return a new FileDirectory for the root directory" |
|
143 |
||
2951 | 144 |
"/ self obsoleteMethodWarning:'use Filename'. |
2921 | 145 |
^ (self basicNew) pathName:(Filename rootDirectory name) |
605 | 146 |
|
147 |
" |
|
148 |
FileDirectory rootDirectory contents |
|
149 |
FileDirectory rootDirectory files |
|
150 |
FileDirectory rootDirectory isReadable |
|
151 |
" |
|
276 | 152 |
! ! |
153 |
||
5729 | 154 |
!FileDirectory class methodsFor:'Compatibility - Squeak'! |
155 |
||
5777 | 156 |
localNameFor:aFileNameString |
157 |
^ aFileNameString asFilename baseName |
|
158 |
! |
|
159 |
||
5729 | 160 |
pathNameDelimiter |
161 |
^ Filename separator |
|
162 |
! ! |
|
163 |
||
276 | 164 |
!FileDirectory class methodsFor:'private'! |
165 |
||
166 |
fullPathNameOf:name in:path |
|
167 |
|sep| |
|
168 |
||
169 |
sep := OperatingSystem fileSeparator asString. |
|
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
170 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
171 |
"/ is it an absolute path ? |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
172 |
|
276 | 173 |
(name startsWith:sep) ifTrue:[ |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
174 |
^ name |
276 | 175 |
]. |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
176 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
177 |
"/ temporary kludge; this and the previous should |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
178 |
"/ go into OS isAbsolutePath .. |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
179 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
180 |
OperatingSystem isMSDOSlike ifTrue:[ |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
181 |
('[a-zA-Z]:*' match:name) ifTrue:[ |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
182 |
"/ drive spec ... |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
183 |
^ name |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
184 |
] |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
185 |
]. |
276 | 186 |
^ path , sep , name |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
187 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
188 |
"Modified: 28.4.1997 / 22:06:17 / cg" |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
189 |
"Modified: 28.4.1997 / 22:34:18 / dq" |
1 | 190 |
! ! |
191 |
||
192 |
!FileDirectory methodsFor:'accessing'! |
|
193 |
||
194 |
baseName |
|
195 |
"return my baseName |
|
196 |
- thats the directory name without leading parent-dirs" |
|
197 |
||
198 |
lazy ifTrue:[self getFullPathName]. |
|
2921 | 199 |
^ pathName asFilename baseName |
1 | 200 |
! |
201 |
||
202 |
contents |
|
2708
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
203 |
"return a collection with all files and subdirectories in the receiver. |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
204 |
Skips any '.' or '..' entries (UNIX)" |
1 | 205 |
|
206 |
|coll| |
|
207 |
||
208 |
coll := OrderedCollection new. |
|
209 |
self do:[:name | |
|
2708
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
210 |
name ~= '.' ifTrue:[ |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
211 |
name ~= '..' ifTrue:[ |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
212 |
coll add:name |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
213 |
] |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
214 |
] |
1 | 215 |
]. |
276 | 216 |
coll sort. |
1 | 217 |
^ coll |
2708
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
218 |
|
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
219 |
"Modified: 20.6.1997 / 17:05:43 / cg" |
1 | 220 |
! |
221 |
||
222 |
directories |
|
223 |
"return a collection with all subdirectories in the receiver directory" |
|
224 |
||
225 |
|coll| |
|
226 |
||
227 |
coll := OrderedCollection new. |
|
228 |
self directoriesDo:[:name | |
|
172 | 229 |
coll add:name |
1 | 230 |
]. |
276 | 231 |
coll sort. |
1 | 232 |
^ coll |
233 |
! |
|
234 |
||
605 | 235 |
directoryName |
236 |
"return my directoryName |
|
237 |
- thats the directory name where I'm in" |
|
238 |
||
239 |
lazy ifTrue:[self getFullPathName]. |
|
2921 | 240 |
^ pathName asFilename directoryName |
605 | 241 |
! |
242 |
||
1 | 243 |
files |
244 |
"return a collection with all plain files in the receiver directory" |
|
245 |
||
246 |
|coll| |
|
247 |
||
248 |
coll := OrderedCollection new. |
|
249 |
self filesDo:[:name | |
|
172 | 250 |
coll add:name |
1 | 251 |
]. |
276 | 252 |
coll sort. |
253 |
^ coll |
|
605 | 254 |
! |
255 |
||
256 |
pathName |
|
257 |
"return my full pathname" |
|
258 |
||
259 |
lazy ifTrue:[self getFullPathName]. |
|
260 |
^ pathName |
|
261 |
! |
|
262 |
||
263 |
pathName:dirName |
|
264 |
"set my pathname; return nil if not a valid path; self otherwise" |
|
265 |
||
266 |
pathName := dirName. |
|
267 |
(dirName startsWith:OperatingSystem fileSeparator) ifFalse:[ |
|
268 |
lazy := true |
|
269 |
] ifTrue:[ |
|
270 |
(dirName startsWith:'./') ifFalse:[ |
|
271 |
"/ (dirName includes:$.) ifTrue:[ |
|
272 |
lazy := true |
|
273 |
] |
|
274 |
]. |
|
275 |
^ self |
|
276 |
! ! |
|
277 |
||
278 |
!FileDirectory methodsFor:'basic'! |
|
279 |
||
280 |
createDirectory:newName |
|
281 |
"create a new filedirectory as a subdirectory of myself; |
|
282 |
return true if successful" |
|
283 |
||
284 |
|realName| |
|
285 |
||
286 |
(newName notNil and:[newName notEmpty]) ifTrue:[ |
|
287 |
(newName ~= '.' and:[newName ~= '..']) ifTrue:[ |
|
288 |
((newName at:1) == OperatingSystem fileSeparator) ifTrue:[ |
|
289 |
realName := newName copyFrom:2 |
|
290 |
] ifFalse:[ |
|
291 |
realName := newName |
|
292 |
]. |
|
2921 | 293 |
^ (self filenameFor:realName) makeDirectory |
605 | 294 |
] |
295 |
]. |
|
296 |
^ false |
|
297 |
! |
|
298 |
||
299 |
link:oldFileName to:newFileName |
|
300 |
"link oldFileName to newFileName in myself, return true if successful" |
|
301 |
||
302 |
|path1 path2| |
|
303 |
||
304 |
path1 := self pathNameOf:oldFileName. |
|
305 |
path2 := self pathNameOf:newFileName. |
|
306 |
^ OperatingSystem linkFile:path1 to:path2 |
|
307 |
! |
|
308 |
||
309 |
remove:aFileOrDirectoryName |
|
310 |
"remove the file or directory from myself; return true if successful" |
|
311 |
||
2921 | 312 |
^ (self filenameFor:aFileOrDirectoryName) remove |
605 | 313 |
! |
314 |
||
315 |
removeDirectory:dirName |
|
316 |
"remove the directory 'dirName' from myself; return true if successful. |
|
317 |
If the directory is not empty, the containing files/directories are also |
|
318 |
removed." |
|
319 |
||
2921 | 320 |
^ (self filenameFor:dirName) recursiveRemove |
605 | 321 |
! |
322 |
||
323 |
removeFile:fileName |
|
324 |
"remove the file 'fileName' from myself; return true if successful" |
|
325 |
||
2921 | 326 |
^ (self filenameFor:fileName) remove |
605 | 327 |
! |
328 |
||
329 |
renameFile:oldFileName newName:newFileName |
|
330 |
"rename the file; return true if successful" |
|
331 |
||
2921 | 332 |
|f1 f2| |
605 | 333 |
|
2921 | 334 |
f1 := self filenameFor:oldFileName. |
335 |
f2 := self filenameFor:newFileName. |
|
336 |
^ f1 renameTo:f2 |
|
1 | 337 |
! ! |
338 |
||
172 | 339 |
!FileDirectory methodsFor:'converting'! |
340 |
||
341 |
asFilename |
|
342 |
"return myself as a filename" |
|
343 |
||
344 |
^ self pathName asFilename |
|
345 |
! |
|
346 |
||
347 |
asFilename:someFile |
|
348 |
"return a filename for a file named someFile in myself" |
|
349 |
||
276 | 350 |
^ self asFilename construct:someFile |
172 | 351 |
! ! |
352 |
||
605 | 353 |
!FileDirectory methodsFor:'enumerating'! |
354 |
||
355 |
allDirectoriesDo:aBlock |
|
356 |
"evaluate the argument, aBlock for every directory name |
|
357 |
in the directory and in all subdirectories" |
|
358 |
||
359 |
|aStream command line| |
|
360 |
||
361 |
lazy ifTrue:[self getFullPathName]. |
|
362 |
command := 'cd ' , pathName , '; find . -type d -print'. |
|
363 |
aStream := PipeStream readingFrom:command. |
|
364 |
aStream isNil ifTrue:[^ nil]. |
|
365 |
[aStream atEnd] whileFalse:[ |
|
366 |
line := aStream nextLine. |
|
367 |
line notNil ifTrue:[ |
|
368 |
(line = '.') ifFalse:[ |
|
369 |
"cut off initial ./" |
|
370 |
line := line copyFrom:3 |
|
371 |
]. |
|
372 |
aBlock value:line |
|
373 |
] |
|
374 |
]. |
|
375 |
aStream close |
|
376 |
! |
|
377 |
||
378 |
allFilesDo:aBlock |
|
379 |
"evaluate the argument, aBlock for every file name in the directory and in all |
|
380 |
subdirectories" |
|
381 |
||
382 |
|aStream command line| |
|
383 |
||
384 |
lazy ifTrue:[self getFullPathName]. |
|
385 |
command := 'cd ' , pathName , '; find . -print'. |
|
386 |
aStream := PipeStream readingFrom:command. |
|
387 |
aStream isNil ifTrue:[^ nil]. |
|
388 |
[aStream atEnd] whileFalse:[ |
|
389 |
line := aStream nextLine. |
|
390 |
line notNil ifTrue:[ |
|
391 |
(line = '.') ifFalse:[ |
|
392 |
"cut off initial ./" |
|
393 |
line := line copyFrom:3 |
|
394 |
]. |
|
395 |
aBlock value:line |
|
396 |
] |
|
397 |
]. |
|
398 |
aStream close |
|
399 |
! |
|
400 |
||
401 |
directoriesDo:aBlock |
|
402 |
"evaluate the argument, aBlock for every subdirectory name in the directory" |
|
403 |
||
404 |
self where:[:name | (self isDirectory:name) ifTrue:[ |
|
405 |
((name ~= '.') and:[name ~= '..']) |
|
406 |
] ifFalse:[ |
|
407 |
false |
|
408 |
] |
|
409 |
] do:aBlock |
|
410 |
! |
|
411 |
||
412 |
do:aBlock |
|
413 |
"evaluate the argument, aBlock for every name in the directory" |
|
414 |
||
415 |
self where:[:name | true] do:aBlock |
|
416 |
! |
|
417 |
||
418 |
filesDo:aBlock |
|
419 |
"evaluate the argument, aBlock for every plain file name in the directory" |
|
420 |
||
421 |
self where:[:name | (self isDirectory:name) not] do:aBlock |
|
422 |
! |
|
423 |
||
424 |
namesDo:aBlock |
|
425 |
"evaluate the argument, aBlock for every name in the directory. |
|
426 |
for ST-80 compatibility" |
|
427 |
||
428 |
self do:aBlock |
|
429 |
! |
|
430 |
||
431 |
where:testBlock do:aBlock |
|
432 |
"evaluate the argument, aBlock for every object in the directory |
|
433 |
for which testBlock evaluates to true." |
|
434 |
||
435 |
|aStream name| |
|
436 |
||
437 |
aStream := DirectoryStream directoryNamed:pathName. |
|
438 |
aStream isNil ifTrue:[^ nil]. |
|
439 |
[aStream atEnd] whileFalse:[ |
|
440 |
name := aStream nextLine. |
|
441 |
name notNil ifTrue:[ |
|
442 |
(testBlock value:name) ifTrue:[ |
|
443 |
aBlock value:name |
|
444 |
] |
|
445 |
] |
|
446 |
]. |
|
447 |
aStream close |
|
448 |
! ! |
|
449 |
||
450 |
!FileDirectory methodsFor:'more instance creation'! |
|
451 |
||
452 |
directoryNamed:aName |
|
2961 | 453 |
"create & return a new fileDirectory for a subdirectory in myself" |
454 |
||
605 | 455 |
^ self class directoryNamed:aName in:self pathName |
456 |
! ! |
|
457 |
||
458 |
!FileDirectory methodsFor:'printing & storing'! |
|
459 |
||
460 |
printOn:aStream |
|
4392 | 461 |
"append a user printed representation of the receiver to aStream. |
462 |
The format is suitable for a human - not meant to be read back." |
|
605 | 463 |
|
464 |
lazy ifTrue:[self getFullPathName]. |
|
465 |
aStream nextPutAll:'(a FileDirectory pathName:'; |
|
4392 | 466 |
nextPutAll:pathName; |
467 |
nextPutAll:')' |
|
605 | 468 |
! |
469 |
||
470 |
storeOn:aStream |
|
471 |
"append a printed representation of the receiver to aStream, |
|
472 |
which allows reconstructing it via readFrom:" |
|
473 |
||
474 |
lazy ifTrue:[self getFullPathName]. |
|
475 |
aStream nextPutAll:'(FileDirectory directoryNamed:'. |
|
476 |
aStream nextPutAll:pathName. |
|
477 |
aStream nextPut:$) |
|
478 |
! ! |
|
479 |
||
1 | 480 |
!FileDirectory methodsFor:'private'! |
481 |
||
3201
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
482 |
filenameFor:fileName |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
483 |
"create & return a fileName object for an entry in myself" |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
484 |
|
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
485 |
|f| |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
486 |
|
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
487 |
f := fileName asFilename. |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
488 |
f isAbsolute ifTrue:[^ f]. |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
489 |
^ (pathName asFilename construct:fileName) |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
490 |
! |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
491 |
|
1 | 492 |
getFullPathName |
493 |
"make my pathname be a full pathname - i.e. starting at root" |
|
494 |
||
308 | 495 |
|shortPathName| |
1 | 496 |
|
2921 | 497 |
|
159 | 498 |
(pathName = OperatingSystem fileSeparator asString) ifTrue:[ |
172 | 499 |
lazy := false. |
500 |
^ self |
|
1 | 501 |
]. |
502 |
||
503 |
"since currentDirectory is used very often, cache its path here" |
|
504 |
||
505 |
(pathName = '.') ifTrue:[ |
|
172 | 506 |
PathOfCurrentDirectory notNil ifTrue:[ |
507 |
pathName := PathOfCurrentDirectory. |
|
508 |
lazy := false. |
|
509 |
^ self |
|
510 |
] |
|
1 | 511 |
]. |
512 |
||
513 |
shortPathName := pathName. |
|
514 |
||
308 | 515 |
pathName := OperatingSystem pathNameOf:pathName. |
516 |
lazy := false. |
|
1 | 517 |
|
308 | 518 |
" |
519 |
if it was the current dir, keep name for next query |
|
520 |
" |
|
1 | 521 |
(shortPathName = '.') ifTrue:[ |
308 | 522 |
PathOfCurrentDirectory := pathName |
1 | 523 |
] |
276 | 524 |
! |
525 |
||
526 |
pathNameOf:fileName |
|
2961 | 527 |
"return the pathname for an entry in myself" |
528 |
||
2921 | 529 |
^ (pathName asFilename construct:fileName) osName |
1 | 530 |
! ! |
531 |
||
605 | 532 |
!FileDirectory methodsFor:'queries'! |
1 | 533 |
|
605 | 534 |
accessModeOf:name |
535 |
"return the access-mode bits (rwxrwxrwx) of a file in myself" |
|
1 | 536 |
|
605 | 537 |
^ OperatingSystem accessModeOf:(self pathNameOf:name) |
1 | 538 |
! |
539 |
||
605 | 540 |
changeAccessModeOf:name to:modeBits |
541 |
"set the access-mode bits (rwxrwxrwx) of a file in myself" |
|
1 | 542 |
|
605 | 543 |
^ OperatingSystem changeAccessModeOf:(self pathNameOf:name) to:modeBits |
1 | 544 |
! |
545 |
||
546 |
exists |
|
547 |
"return true if this directory exists" |
|
548 |
||
2921 | 549 |
^ (Filename named:pathName) isDirectory |
159 | 550 |
|
551 |
" |
|
552 |
(FileDirectory directoryNamed:'fooBar') exists |
|
553 |
(FileDirectory directoryNamed:'/tmp') exists |
|
554 |
" |
|
1 | 555 |
! |
556 |
||
605 | 557 |
exists:name |
558 |
"return true, if the given name exists in myself" |
|
559 |
||
2921 | 560 |
^ (self filenameFor:name) exists |
605 | 561 |
! |
562 |
||
563 |
id |
|
564 |
"return the directories file-id (inode number)" |
|
565 |
||
2921 | 566 |
^ (Filename named:pathName) id |
605 | 567 |
! |
568 |
||
569 |
infoOf:name |
|
570 |
"return an array filled with file info for the file 'aFileName'; |
|
571 |
return nil if such a file does not exist" |
|
572 |
||
2921 | 573 |
^ (self filenameFor:name) info |
605 | 574 |
! |
575 |
||
576 |
isDirectory:name |
|
577 |
"return true, if the given name is that of a directory in myself" |
|
578 |
||
2921 | 579 |
^ (self filenameFor:name) isDirectory |
605 | 580 |
! |
581 |
||
582 |
isExecutable:name |
|
583 |
"return true, if the given file is executable" |
|
1 | 584 |
|
2921 | 585 |
^ (self filenameFor:name) isExecutable |
1 | 586 |
! |
587 |
||
588 |
isReadable:name |
|
589 |
"return true, if the given file is readable" |
|
590 |
||
2921 | 591 |
^ (self filenameFor:name) isReadable |
1 | 592 |
! |
593 |
||
594 |
isWritable:name |
|
595 |
"return true, if the given file is readable" |
|
596 |
||
2921 | 597 |
^ (self filenameFor:name) isWritable |
1 | 598 |
! |
599 |
||
605 | 600 |
species |
601 |
^ OrderedCollection |
|
1 | 602 |
! |
603 |
||
605 | 604 |
timeOfLastChange |
605 |
"return the timeStamp of myself" |
|
1 | 606 |
|
2921 | 607 |
^ (Filename named:pathName) modificationTime |
1 | 608 |
! |
609 |
||
605 | 610 |
timeOfLastChange:name |
611 |
"return the timeStamp of a file in myself" |
|
1 | 612 |
|
2921 | 613 |
^ (self filenameFor:name) modificationTime |
1 | 614 |
! |
615 |
||
605 | 616 |
typeOf:name |
617 |
"return the symbolic type of a file in myself" |
|
1 | 618 |
|
2921 | 619 |
^ (self filenameFor:name) type |
605 | 620 |
! ! |
1 | 621 |
|
5556 | 622 |
!FileDirectory methodsFor:'testing'! |
623 |
||
624 |
isEmpty |
|
625 |
"return true, if the directory is empty; |
|
626 |
redefined since '.' and '..' do not count as entries here." |
|
627 |
||
628 |
self do:[:fName | |
|
629 |
((fName ~= '.') and:[fName ~= '..']) ifTrue:[^ false]. |
|
630 |
]. |
|
631 |
^ true |
|
632 |
! ! |
|
633 |
||
629 | 634 |
!FileDirectory class methodsFor:'documentation'! |
635 |
||
636 |
version |
|
5777 | 637 |
^ '$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.41 2001-01-08 16:36:43 cg Exp $' |
629 | 638 |
! ! |
605 | 639 |
FileDirectory initialize! |