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