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