author | Claus Gittinger <cg@exept.de> |
Tue, 29 Aug 2000 17:12:09 +0200 | |
changeset 5565 | a815d6b86ace |
parent 5556 | 1056cc5d6ce0 |
child 5729 | 63af78505f23 |
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 |
||
154 |
!FileDirectory class methodsFor:'private'! |
|
155 |
||
156 |
fullPathNameOf:name in:path |
|
157 |
|sep| |
|
158 |
||
159 |
sep := OperatingSystem fileSeparator asString. |
|
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
160 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
161 |
"/ is it an absolute path ? |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
162 |
|
276 | 163 |
(name startsWith:sep) ifTrue:[ |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
164 |
^ name |
276 | 165 |
]. |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
166 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
167 |
"/ 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
|
168 |
"/ go into OS isAbsolutePath .. |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
169 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
170 |
OperatingSystem isMSDOSlike ifTrue:[ |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
171 |
('[a-zA-Z]:*' match:name) ifTrue:[ |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
172 |
"/ drive spec ... |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
173 |
^ name |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
174 |
] |
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
175 |
]. |
276 | 176 |
^ path , sep , name |
2590
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
177 |
|
6855cfa1e628
temporary kludge for drive specifiers in MSDOS fileNames.
Claus Gittinger <cg@exept.de>
parents:
1469
diff
changeset
|
178 |
"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
|
179 |
"Modified: 28.4.1997 / 22:34:18 / dq" |
1 | 180 |
! ! |
181 |
||
182 |
!FileDirectory methodsFor:'accessing'! |
|
183 |
||
184 |
baseName |
|
185 |
"return my baseName |
|
186 |
- thats the directory name without leading parent-dirs" |
|
187 |
||
188 |
lazy ifTrue:[self getFullPathName]. |
|
2921 | 189 |
^ pathName asFilename baseName |
1 | 190 |
! |
191 |
||
192 |
contents |
|
2708
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
193 |
"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
|
194 |
Skips any '.' or '..' entries (UNIX)" |
1 | 195 |
|
196 |
|coll| |
|
197 |
||
198 |
coll := OrderedCollection new. |
|
199 |
self do:[:name | |
|
2708
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
200 |
name ~= '.' ifTrue:[ |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
201 |
name ~= '..' ifTrue:[ |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
202 |
coll add:name |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
203 |
] |
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
204 |
] |
1 | 205 |
]. |
276 | 206 |
coll sort. |
1 | 207 |
^ coll |
2708
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
208 |
|
6c4a4f30d540
skip '.' and '..' in #contents
Claus Gittinger <cg@exept.de>
parents:
2590
diff
changeset
|
209 |
"Modified: 20.6.1997 / 17:05:43 / cg" |
1 | 210 |
! |
211 |
||
212 |
directories |
|
213 |
"return a collection with all subdirectories in the receiver directory" |
|
214 |
||
215 |
|coll| |
|
216 |
||
217 |
coll := OrderedCollection new. |
|
218 |
self directoriesDo:[:name | |
|
172 | 219 |
coll add:name |
1 | 220 |
]. |
276 | 221 |
coll sort. |
1 | 222 |
^ coll |
223 |
! |
|
224 |
||
605 | 225 |
directoryName |
226 |
"return my directoryName |
|
227 |
- thats the directory name where I'm in" |
|
228 |
||
229 |
lazy ifTrue:[self getFullPathName]. |
|
2921 | 230 |
^ pathName asFilename directoryName |
605 | 231 |
! |
232 |
||
1 | 233 |
files |
234 |
"return a collection with all plain files in the receiver directory" |
|
235 |
||
236 |
|coll| |
|
237 |
||
238 |
coll := OrderedCollection new. |
|
239 |
self filesDo:[:name | |
|
172 | 240 |
coll add:name |
1 | 241 |
]. |
276 | 242 |
coll sort. |
243 |
^ coll |
|
605 | 244 |
! |
245 |
||
246 |
pathName |
|
247 |
"return my full pathname" |
|
248 |
||
249 |
lazy ifTrue:[self getFullPathName]. |
|
250 |
^ pathName |
|
251 |
! |
|
252 |
||
253 |
pathName:dirName |
|
254 |
"set my pathname; return nil if not a valid path; self otherwise" |
|
255 |
||
256 |
pathName := dirName. |
|
257 |
(dirName startsWith:OperatingSystem fileSeparator) ifFalse:[ |
|
258 |
lazy := true |
|
259 |
] ifTrue:[ |
|
260 |
(dirName startsWith:'./') ifFalse:[ |
|
261 |
"/ (dirName includes:$.) ifTrue:[ |
|
262 |
lazy := true |
|
263 |
] |
|
264 |
]. |
|
265 |
^ self |
|
266 |
! ! |
|
267 |
||
268 |
!FileDirectory methodsFor:'basic'! |
|
269 |
||
270 |
createDirectory:newName |
|
271 |
"create a new filedirectory as a subdirectory of myself; |
|
272 |
return true if successful" |
|
273 |
||
274 |
|realName| |
|
275 |
||
276 |
(newName notNil and:[newName notEmpty]) ifTrue:[ |
|
277 |
(newName ~= '.' and:[newName ~= '..']) ifTrue:[ |
|
278 |
((newName at:1) == OperatingSystem fileSeparator) ifTrue:[ |
|
279 |
realName := newName copyFrom:2 |
|
280 |
] ifFalse:[ |
|
281 |
realName := newName |
|
282 |
]. |
|
2921 | 283 |
^ (self filenameFor:realName) makeDirectory |
605 | 284 |
] |
285 |
]. |
|
286 |
^ false |
|
287 |
! |
|
288 |
||
289 |
link:oldFileName to:newFileName |
|
290 |
"link oldFileName to newFileName in myself, return true if successful" |
|
291 |
||
292 |
|path1 path2| |
|
293 |
||
294 |
path1 := self pathNameOf:oldFileName. |
|
295 |
path2 := self pathNameOf:newFileName. |
|
296 |
^ OperatingSystem linkFile:path1 to:path2 |
|
297 |
! |
|
298 |
||
299 |
remove:aFileOrDirectoryName |
|
300 |
"remove the file or directory from myself; return true if successful" |
|
301 |
||
2921 | 302 |
^ (self filenameFor:aFileOrDirectoryName) remove |
605 | 303 |
! |
304 |
||
305 |
removeDirectory:dirName |
|
306 |
"remove the directory 'dirName' from myself; return true if successful. |
|
307 |
If the directory is not empty, the containing files/directories are also |
|
308 |
removed." |
|
309 |
||
2921 | 310 |
^ (self filenameFor:dirName) recursiveRemove |
605 | 311 |
! |
312 |
||
313 |
removeFile:fileName |
|
314 |
"remove the file 'fileName' from myself; return true if successful" |
|
315 |
||
2921 | 316 |
^ (self filenameFor:fileName) remove |
605 | 317 |
! |
318 |
||
319 |
renameFile:oldFileName newName:newFileName |
|
320 |
"rename the file; return true if successful" |
|
321 |
||
2921 | 322 |
|f1 f2| |
605 | 323 |
|
2921 | 324 |
f1 := self filenameFor:oldFileName. |
325 |
f2 := self filenameFor:newFileName. |
|
326 |
^ f1 renameTo:f2 |
|
1 | 327 |
! ! |
328 |
||
172 | 329 |
!FileDirectory methodsFor:'converting'! |
330 |
||
331 |
asFilename |
|
332 |
"return myself as a filename" |
|
333 |
||
334 |
^ self pathName asFilename |
|
335 |
! |
|
336 |
||
337 |
asFilename:someFile |
|
338 |
"return a filename for a file named someFile in myself" |
|
339 |
||
276 | 340 |
^ self asFilename construct:someFile |
172 | 341 |
! ! |
342 |
||
605 | 343 |
!FileDirectory methodsFor:'enumerating'! |
344 |
||
345 |
allDirectoriesDo:aBlock |
|
346 |
"evaluate the argument, aBlock for every directory name |
|
347 |
in the directory and in all subdirectories" |
|
348 |
||
349 |
|aStream command line| |
|
350 |
||
351 |
lazy ifTrue:[self getFullPathName]. |
|
352 |
command := 'cd ' , pathName , '; find . -type d -print'. |
|
353 |
aStream := PipeStream readingFrom:command. |
|
354 |
aStream isNil ifTrue:[^ nil]. |
|
355 |
[aStream atEnd] whileFalse:[ |
|
356 |
line := aStream nextLine. |
|
357 |
line notNil ifTrue:[ |
|
358 |
(line = '.') ifFalse:[ |
|
359 |
"cut off initial ./" |
|
360 |
line := line copyFrom:3 |
|
361 |
]. |
|
362 |
aBlock value:line |
|
363 |
] |
|
364 |
]. |
|
365 |
aStream close |
|
366 |
! |
|
367 |
||
368 |
allFilesDo:aBlock |
|
369 |
"evaluate the argument, aBlock for every file name in the directory and in all |
|
370 |
subdirectories" |
|
371 |
||
372 |
|aStream command line| |
|
373 |
||
374 |
lazy ifTrue:[self getFullPathName]. |
|
375 |
command := 'cd ' , pathName , '; find . -print'. |
|
376 |
aStream := PipeStream readingFrom:command. |
|
377 |
aStream isNil ifTrue:[^ nil]. |
|
378 |
[aStream atEnd] whileFalse:[ |
|
379 |
line := aStream nextLine. |
|
380 |
line notNil ifTrue:[ |
|
381 |
(line = '.') ifFalse:[ |
|
382 |
"cut off initial ./" |
|
383 |
line := line copyFrom:3 |
|
384 |
]. |
|
385 |
aBlock value:line |
|
386 |
] |
|
387 |
]. |
|
388 |
aStream close |
|
389 |
! |
|
390 |
||
391 |
directoriesDo:aBlock |
|
392 |
"evaluate the argument, aBlock for every subdirectory name in the directory" |
|
393 |
||
394 |
self where:[:name | (self isDirectory:name) ifTrue:[ |
|
395 |
((name ~= '.') and:[name ~= '..']) |
|
396 |
] ifFalse:[ |
|
397 |
false |
|
398 |
] |
|
399 |
] do:aBlock |
|
400 |
! |
|
401 |
||
402 |
do:aBlock |
|
403 |
"evaluate the argument, aBlock for every name in the directory" |
|
404 |
||
405 |
self where:[:name | true] do:aBlock |
|
406 |
! |
|
407 |
||
408 |
filesDo:aBlock |
|
409 |
"evaluate the argument, aBlock for every plain file name in the directory" |
|
410 |
||
411 |
self where:[:name | (self isDirectory:name) not] do:aBlock |
|
412 |
! |
|
413 |
||
414 |
namesDo:aBlock |
|
415 |
"evaluate the argument, aBlock for every name in the directory. |
|
416 |
for ST-80 compatibility" |
|
417 |
||
418 |
self do:aBlock |
|
419 |
! |
|
420 |
||
421 |
where:testBlock do:aBlock |
|
422 |
"evaluate the argument, aBlock for every object in the directory |
|
423 |
for which testBlock evaluates to true." |
|
424 |
||
425 |
|aStream name| |
|
426 |
||
427 |
aStream := DirectoryStream directoryNamed:pathName. |
|
428 |
aStream isNil ifTrue:[^ nil]. |
|
429 |
[aStream atEnd] whileFalse:[ |
|
430 |
name := aStream nextLine. |
|
431 |
name notNil ifTrue:[ |
|
432 |
(testBlock value:name) ifTrue:[ |
|
433 |
aBlock value:name |
|
434 |
] |
|
435 |
] |
|
436 |
]. |
|
437 |
aStream close |
|
438 |
! ! |
|
439 |
||
440 |
!FileDirectory methodsFor:'more instance creation'! |
|
441 |
||
442 |
directoryNamed:aName |
|
2961 | 443 |
"create & return a new fileDirectory for a subdirectory in myself" |
444 |
||
605 | 445 |
^ self class directoryNamed:aName in:self pathName |
446 |
! ! |
|
447 |
||
448 |
!FileDirectory methodsFor:'printing & storing'! |
|
449 |
||
450 |
printOn:aStream |
|
4392 | 451 |
"append a user printed representation of the receiver to aStream. |
452 |
The format is suitable for a human - not meant to be read back." |
|
605 | 453 |
|
454 |
lazy ifTrue:[self getFullPathName]. |
|
455 |
aStream nextPutAll:'(a FileDirectory pathName:'; |
|
4392 | 456 |
nextPutAll:pathName; |
457 |
nextPutAll:')' |
|
605 | 458 |
! |
459 |
||
460 |
storeOn:aStream |
|
461 |
"append a printed representation of the receiver to aStream, |
|
462 |
which allows reconstructing it via readFrom:" |
|
463 |
||
464 |
lazy ifTrue:[self getFullPathName]. |
|
465 |
aStream nextPutAll:'(FileDirectory directoryNamed:'. |
|
466 |
aStream nextPutAll:pathName. |
|
467 |
aStream nextPut:$) |
|
468 |
! ! |
|
469 |
||
1 | 470 |
!FileDirectory methodsFor:'private'! |
471 |
||
3201
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
472 |
filenameFor:fileName |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
473 |
"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
|
474 |
|
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
475 |
|f| |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
476 |
|
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
477 |
f := fileName asFilename. |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
478 |
f isAbsolute ifTrue:[^ f]. |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
479 |
^ (pathName asFilename construct:fileName) |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
480 |
! |
4e72e420fdc3
Documentation: FileDirectory is obsolete and works only under Unix.
Stefan Vogel <sv@exept.de>
parents:
2961
diff
changeset
|
481 |
|
1 | 482 |
getFullPathName |
483 |
"make my pathname be a full pathname - i.e. starting at root" |
|
484 |
||
308 | 485 |
|shortPathName| |
1 | 486 |
|
2921 | 487 |
|
159 | 488 |
(pathName = OperatingSystem fileSeparator asString) ifTrue:[ |
172 | 489 |
lazy := false. |
490 |
^ self |
|
1 | 491 |
]. |
492 |
||
493 |
"since currentDirectory is used very often, cache its path here" |
|
494 |
||
495 |
(pathName = '.') ifTrue:[ |
|
172 | 496 |
PathOfCurrentDirectory notNil ifTrue:[ |
497 |
pathName := PathOfCurrentDirectory. |
|
498 |
lazy := false. |
|
499 |
^ self |
|
500 |
] |
|
1 | 501 |
]. |
502 |
||
503 |
shortPathName := pathName. |
|
504 |
||
308 | 505 |
pathName := OperatingSystem pathNameOf:pathName. |
506 |
lazy := false. |
|
1 | 507 |
|
308 | 508 |
" |
509 |
if it was the current dir, keep name for next query |
|
510 |
" |
|
1 | 511 |
(shortPathName = '.') ifTrue:[ |
308 | 512 |
PathOfCurrentDirectory := pathName |
1 | 513 |
] |
276 | 514 |
! |
515 |
||
516 |
pathNameOf:fileName |
|
2961 | 517 |
"return the pathname for an entry in myself" |
518 |
||
2921 | 519 |
^ (pathName asFilename construct:fileName) osName |
1 | 520 |
! ! |
521 |
||
605 | 522 |
!FileDirectory methodsFor:'queries'! |
1 | 523 |
|
605 | 524 |
accessModeOf:name |
525 |
"return the access-mode bits (rwxrwxrwx) of a file in myself" |
|
1 | 526 |
|
605 | 527 |
^ OperatingSystem accessModeOf:(self pathNameOf:name) |
1 | 528 |
! |
529 |
||
605 | 530 |
changeAccessModeOf:name to:modeBits |
531 |
"set the access-mode bits (rwxrwxrwx) of a file in myself" |
|
1 | 532 |
|
605 | 533 |
^ OperatingSystem changeAccessModeOf:(self pathNameOf:name) to:modeBits |
1 | 534 |
! |
535 |
||
536 |
exists |
|
537 |
"return true if this directory exists" |
|
538 |
||
2921 | 539 |
^ (Filename named:pathName) isDirectory |
159 | 540 |
|
541 |
" |
|
542 |
(FileDirectory directoryNamed:'fooBar') exists |
|
543 |
(FileDirectory directoryNamed:'/tmp') exists |
|
544 |
" |
|
1 | 545 |
! |
546 |
||
605 | 547 |
exists:name |
548 |
"return true, if the given name exists in myself" |
|
549 |
||
2921 | 550 |
^ (self filenameFor:name) exists |
605 | 551 |
! |
552 |
||
553 |
id |
|
554 |
"return the directories file-id (inode number)" |
|
555 |
||
2921 | 556 |
^ (Filename named:pathName) id |
605 | 557 |
! |
558 |
||
559 |
infoOf:name |
|
560 |
"return an array filled with file info for the file 'aFileName'; |
|
561 |
return nil if such a file does not exist" |
|
562 |
||
2921 | 563 |
^ (self filenameFor:name) info |
605 | 564 |
! |
565 |
||
566 |
isDirectory:name |
|
567 |
"return true, if the given name is that of a directory in myself" |
|
568 |
||
2921 | 569 |
^ (self filenameFor:name) isDirectory |
605 | 570 |
! |
571 |
||
572 |
isExecutable:name |
|
573 |
"return true, if the given file is executable" |
|
1 | 574 |
|
2921 | 575 |
^ (self filenameFor:name) isExecutable |
1 | 576 |
! |
577 |
||
578 |
isReadable:name |
|
579 |
"return true, if the given file is readable" |
|
580 |
||
2921 | 581 |
^ (self filenameFor:name) isReadable |
1 | 582 |
! |
583 |
||
584 |
isWritable:name |
|
585 |
"return true, if the given file is readable" |
|
586 |
||
2921 | 587 |
^ (self filenameFor:name) isWritable |
1 | 588 |
! |
589 |
||
605 | 590 |
species |
591 |
^ OrderedCollection |
|
1 | 592 |
! |
593 |
||
605 | 594 |
timeOfLastChange |
595 |
"return the timeStamp of myself" |
|
1 | 596 |
|
2921 | 597 |
^ (Filename named:pathName) modificationTime |
1 | 598 |
! |
599 |
||
605 | 600 |
timeOfLastChange:name |
601 |
"return the timeStamp of a file in myself" |
|
1 | 602 |
|
2921 | 603 |
^ (self filenameFor:name) modificationTime |
1 | 604 |
! |
605 |
||
605 | 606 |
typeOf:name |
607 |
"return the symbolic type of a file in myself" |
|
1 | 608 |
|
2921 | 609 |
^ (self filenameFor:name) type |
605 | 610 |
! ! |
1 | 611 |
|
5556 | 612 |
!FileDirectory methodsFor:'testing'! |
613 |
||
614 |
isEmpty |
|
615 |
"return true, if the directory is empty; |
|
616 |
redefined since '.' and '..' do not count as entries here." |
|
617 |
||
618 |
self do:[:fName | |
|
619 |
((fName ~= '.') and:[fName ~= '..']) ifTrue:[^ false]. |
|
620 |
]. |
|
621 |
^ true |
|
622 |
! ! |
|
623 |
||
629 | 624 |
!FileDirectory class methodsFor:'documentation'! |
625 |
||
626 |
version |
|
5556 | 627 |
^ '$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.39 2000-08-22 13:47:44 cg Exp $' |
629 | 628 |
! ! |
605 | 629 |
FileDirectory initialize! |