author | Claus Gittinger <cg@exept.de> |
Mon, 05 Oct 1998 10:38:06 +0200 | |
changeset 3869 | 6d7dca488a41 |
parent 3868 | 24acb1228e12 |
child 3871 | 745482fed59a |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 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 |
Object subclass:#Filename |
|
844 | 14 |
instanceVariableNames:'nameString' |
2906 | 15 |
classVariableNames:'NextTempFilenameIndex ConcreteClass' |
844 | 16 |
poolDictionaries:'' |
17 |
category:'System-Support' |
|
615 | 18 |
! |
1 | 19 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
20 |
!Filename class methodsFor:'documentation'! |
88 | 21 |
|
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 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 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
Filenames; originally added for ST-80 compatibility, is |
|
39 |
taking over functionality from other classes (FileDirectory). |
|
92 | 40 |
|
41 |
Instances of Filename do not nescessarily represent valid or existing |
|
42 |
files - i.e. it is possible (and useful) to have instances for non-existing |
|
43 |
files around. In other words: the name-string is not checked automatically |
|
44 |
for being correct or existing. |
|
45 |
Thus, it is possible to do queries such as: |
|
46 |
||
2911 | 47 |
'/fee/foo/foe' asFilename exists |
48 |
'/not_existing' asFilename isDirectory |
|
49 |
'/foo/bar' asFilename isReadable |
|
92 | 50 |
|
195 | 51 |
(all of the above examples will probably return false on your machine ;-). |
276 | 52 |
|
53 |
examples: |
|
54 |
||
2911 | 55 |
'Makefile' asFilename readStream |
56 |
||
57 |
'newFile' asFilename writeStream |
|
58 |
||
59 |
Filename newTemporary writeStream |
|
276 | 60 |
|
1318 | 61 |
Beside lots of protocol to query for a files attributes, the class |
62 |
protocol offers methods for filename completion, to construct pathes |
|
63 |
(in an OS-independent way) and to create temporary files. |
|
2911 | 64 |
Especially the path-construction methods (i.e. #construct:) are highly |
1318 | 65 |
recommended in order to avoid having OS details (like directory separators |
66 |
being slash or backslash) spreaded in your application. |
|
67 |
||
1286 | 68 |
[author:] |
2911 | 69 |
Claus Gittinger |
276 | 70 |
|
1286 | 71 |
[see also:] |
2911 | 72 |
String |
73 |
FileStream DirectoryStream PipeStream Socket |
|
74 |
OperatingSystem |
|
75 |
Date Time |
|
88 | 76 |
" |
360 | 77 |
! |
78 |
||
79 |
examples |
|
80 |
" |
|
81 |
does a file/directory exist ?: |
|
82 |
||
2911 | 83 |
|f| |
84 |
||
85 |
f := 'foobar' asFilename. |
|
86 |
^ f exists |
|
360 | 87 |
|
88 |
||
89 |
is it a directory ?: |
|
90 |
||
2911 | 91 |
|f| |
92 |
||
93 |
f := '/tmp' asFilename. |
|
94 |
^ f isDirectory. |
|
360 | 95 |
|
96 |
||
97 |
get the working directory: |
|
98 |
||
2911 | 99 |
^ Filename defaultDirectory |
360 | 100 |
|
101 |
||
102 |
get a files full pathname |
|
103 |
(caring for relative names or symbolic links): |
|
104 |
||
2911 | 105 |
|f| |
106 |
||
107 |
f := '..' asFilename. |
|
108 |
^ f pathName |
|
360 | 109 |
|
110 |
||
111 |
get a directories directory: |
|
112 |
||
2911 | 113 |
|f| |
114 |
||
115 |
f := Filename defaultDirectory. |
|
116 |
^ f directory |
|
360 | 117 |
|
118 |
||
119 |
get a files directory: |
|
120 |
||
2911 | 121 |
|f| |
122 |
||
123 |
f := './smalltalk' asFilename. |
|
124 |
^ f directory |
|
360 | 125 |
|
126 |
||
127 |
getting access & modification times: |
|
128 |
||
129 |
||
2911 | 130 |
|f| |
131 |
||
132 |
f := '/tmp' asFilename. |
|
133 |
^ f dates |
|
360 | 134 |
|
135 |
access time only: |
|
136 |
||
2911 | 137 |
|f| |
138 |
||
139 |
f := '/tmp' asFilename. |
|
140 |
^ f dates at:#accessed |
|
360 | 141 |
|
142 |
||
143 |
getting all information on a file/directory: |
|
144 |
||
145 |
||
2911 | 146 |
|f| |
147 |
||
148 |
f := '/tmp' asFilename. |
|
149 |
^ f info |
|
360 | 150 |
|
151 |
||
152 |
getting a temporary file (unique name): |
|
153 |
||
2911 | 154 |
|f| |
155 |
||
156 |
f := Filename newTemporary. |
|
157 |
^ f |
|
360 | 158 |
|
159 |
||
160 |
creating, writing, reading and removing a temporary file: |
|
2911 | 161 |
[exBegin] |
162 |
|f writeStream readStream| |
|
163 |
||
164 |
f := Filename newTemporary. |
|
165 |
writeStream := f writeStream. |
|
166 |
writeStream nextPutAll:'hello world'. |
|
167 |
writeStream cr. |
|
168 |
writeStream close. |
|
169 |
||
170 |
'contents (as seen by unix''s cat command:' printNL. |
|
171 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
172 |
||
173 |
readStream := f readStream. |
|
174 |
Transcript showCR:'contents as seen by smalltalk:'. |
|
175 |
Transcript showCR:(readStream upToEnd). |
|
176 |
readStream close. |
|
177 |
||
178 |
f delete. |
|
179 |
[exEnd] |
|
360 | 180 |
|
181 |
||
182 |
getting a directories contents: |
|
2911 | 183 |
[exBegin] |
184 |
|f files| |
|
185 |
||
186 |
f := Filename currentDirectory. |
|
187 |
files := f directoryContents. |
|
188 |
Transcript showCR:'the files are:'. |
|
189 |
Transcript showCR:(files printString). |
|
190 |
[exEnd] |
|
360 | 191 |
|
192 |
||
193 |
editing a file: |
|
2911 | 194 |
[exBegin] |
195 |
|f| |
|
196 |
||
197 |
f := Filename newTemporary. |
|
198 |
(f writeStream) nextPutAll:'hello world'; close. |
|
199 |
||
200 |
f edit |
|
201 |
[exEnd] |
|
360 | 202 |
" |
88 | 203 |
! ! |
1 | 204 |
|
2906 | 205 |
!Filename class methodsFor:'initialization'! |
206 |
||
207 |
initialize |
|
208 |
"initialize for the OS we are running on" |
|
209 |
||
210 |
self initializeConcreteClass |
|
211 |
||
212 |
" |
|
213 |
self initialize |
|
214 |
" |
|
215 |
||
216 |
"Created: 7.9.1997 / 23:32:55 / cg" |
|
217 |
! |
|
218 |
||
219 |
initializeConcreteClass |
|
220 |
"initialize for the OS we are running on" |
|
221 |
||
222 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
223 |
ConcreteClass := PCFilename |
|
224 |
] ifFalse:[ |
|
225 |
OperatingSystem isVMSlike ifTrue:[ |
|
226 |
ConcreteClass := OpenVMSFilename |
|
227 |
] ifFalse:[ |
|
228 |
OperatingSystem isUNIXlike ifTrue:[ |
|
229 |
ConcreteClass := UnixFilename |
|
230 |
] ifFalse:[ |
|
231 |
ConcreteClass := nil |
|
232 |
] |
|
233 |
] |
|
234 |
] |
|
235 |
||
236 |
" |
|
237 |
self initialize |
|
238 |
" |
|
239 |
||
240 |
"Modified: 7.9.1997 / 23:32:37 / cg" |
|
241 |
! |
|
242 |
||
243 |
reinitialize |
|
244 |
"initialize for the OS we are running on" |
|
245 |
||
246 |
self initializeConcreteClass |
|
247 |
||
248 |
" |
|
249 |
self initialize |
|
250 |
" |
|
251 |
||
252 |
"Created: 7.9.1997 / 23:33:02 / cg" |
|
253 |
! ! |
|
254 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
255 |
!Filename class methodsFor:'instance creation'! |
1 | 256 |
|
276 | 257 |
currentDirectory |
258 |
"return a filename for the current directory" |
|
259 |
||
2906 | 260 |
(self ~~ ConcreteClass) ifTrue:[ |
261 |
^ ConcreteClass currentDirectory |
|
262 |
]. |
|
263 |
||
264 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
265 |
||
2922 | 266 |
^ self named:'.' |
267 |
"/ ^ self named:('.' asFilename pathName) |
|
276 | 268 |
|
269 |
" |
|
270 |
Filename currentDirectory |
|
271 |
" |
|
2550 | 272 |
|
2906 | 273 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
276 | 274 |
! |
275 |
||
328 | 276 |
defaultDirectory |
277 |
"ST80 compatibility: same as currentDirectory" |
|
278 |
||
279 |
^ self currentDirectory |
|
280 |
||
281 |
" |
|
282 |
Filename defaultDirectory |
|
283 |
" |
|
284 |
! |
|
285 |
||
542 | 286 |
defaultDirectoryName |
287 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
|
288 |
||
289 |
^ self defaultDirectory name |
|
290 |
||
291 |
" |
|
292 |
Filename defaultDirectoryName |
|
293 |
" |
|
294 |
! |
|
295 |
||
2906 | 296 |
defaultTempDirectoryName |
297 |
"return the default temp directory as a filename. |
|
298 |
This is used, if no special preferences were defined in |
|
299 |
any of the TEMP-environment variables (see tempDirectory)." |
|
300 |
||
301 |
(self ~~ ConcreteClass) ifTrue:[ |
|
302 |
^ ConcreteClass defaultTempDirectoryName |
|
303 |
]. |
|
304 |
||
305 |
^ '/tmp' |
|
306 |
||
307 |
" |
|
308 |
Filename defaultTempDirectoryName |
|
309 |
" |
|
310 |
||
311 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
312 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
313 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
314 |
! |
|
315 |
||
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
316 |
findDefaultDirectory |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
317 |
"same as #defaultDirectory for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
318 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
319 |
^ self defaultDirectory |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
320 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
321 |
"Created: 20.6.1997 / 17:00:29 / cg" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
322 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
323 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
324 |
fromComponents:aCollectionOfDirectoryNames |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
325 |
"create & return a new filename from components given in |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
326 |
aCollectionOfDirectoryNames. If the first component is the name of the |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
327 |
root directory (i.e. '/') an absolute path-filename is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
328 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
329 |
|sep s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
330 |
|
2906 | 331 |
(self ~~ ConcreteClass) ifTrue:[ |
332 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
|
333 |
]. |
|
334 |
||
335 |
"/ fallBack - works on Unix & MSDOS |
|
336 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
337 |
sep := self separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
338 |
s := ''. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
339 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
2906 | 340 |
index == 1 ifTrue:[ |
341 |
(component ~= sep |
|
342 |
or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ |
|
343 |
s := s , component |
|
344 |
] |
|
345 |
] ifFalse:[ |
|
346 |
s := s , sep , component |
|
347 |
]. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
348 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
349 |
^ self named:s |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
350 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
351 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
352 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
353 |
Filename fromComponents:#('foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
354 |
Filename fromComponents:#('/') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
355 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
356 |
Filename fromComponents: |
2906 | 357 |
(Filename components:('.' asFilename pathName)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
358 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
359 |
Filename fromComponents: |
2906 | 360 |
(Filename components:('.' asFilename name)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
361 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
362 |
|
2906 | 363 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
364 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
365 |
|
615 | 366 |
fromUser |
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
367 |
"show a box to enter a filename. |
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
368 |
Return a filename instance or nil (if cancel was pressed)." |
615 | 369 |
|
370 |
|name| |
|
371 |
||
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
372 |
name := Dialog requestFileName:'filename:' ifFail:nil. |
615 | 373 |
name notNil ifTrue:[^ self named:name]. |
374 |
^ nil |
|
375 |
||
376 |
" |
|
377 |
Filename fromUser |
|
378 |
" |
|
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
379 |
|
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
380 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
615 | 381 |
! |
382 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
383 |
homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
384 |
"return your homeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
385 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
386 |
(which is the currentDirectory) is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
387 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
388 |
|s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
389 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
390 |
s := OperatingSystem getHomeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
391 |
s isNil ifTrue:[ |
2906 | 392 |
^ self defaultDirectory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
393 |
]. |
2906 | 394 |
^ self named:s |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
395 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
396 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
397 |
Filename homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
398 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
399 |
|
2906 | 400 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
401 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
402 |
|
615 | 403 |
named:aString |
404 |
"return a filename for a directory named aString. |
|
405 |
This is the same as 'aString asFilename'." |
|
406 |
||
2908 | 407 |
|cls| |
408 |
||
409 |
cls := self. |
|
410 |
cls == Filename ifTrue:[ |
|
411 |
cls := self concreteClass |
|
412 |
]. |
|
413 |
^ (cls basicNew) setName:aString |
|
615 | 414 |
|
415 |
" |
|
416 |
Filename named:'/tmp/fooBar' |
|
417 |
" |
|
2906 | 418 |
|
419 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
615 | 420 |
! |
421 |
||
276 | 422 |
newTemporary |
325 | 423 |
"return a new unique filename - use this for temporary files. |
424 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
425 |
unix process id, and nn is a unique number, incremented with every |
|
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
426 |
call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
427 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
428 |
its value defines the temp directory." |
276 | 429 |
|
2947 | 430 |
^ self newTemporaryIn:(self tempDirectory) pathName |
276 | 431 |
|
432 |
" |
|
422 | 433 |
Filename newTemporary |
1080 | 434 |
Filename newTemporary |
276 | 435 |
" |
422 | 436 |
|
437 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
438 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
439 |
! |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
440 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
441 |
newTemporaryIn:aDirectoryPrefix |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
442 |
"return a new unique filename - use this for temporary files. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
443 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
444 |
where xx is our unix process id, and nn is a unique number, incremented |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
445 |
with every call to this method. |
2906 | 446 |
Notice: only a unique filename object is created and returned - no physical |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
447 |
file is created by this method (i.e. you have to send #writeStream or |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
448 |
whatever to it in order to really create something). |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
449 |
See also: #newTemporary which looks for a good temp directory." |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
450 |
|
3059
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
451 |
|pid nameString fn| |
2906 | 452 |
|
453 |
(self ~~ ConcreteClass) ifTrue:[ |
|
454 |
^ ConcreteClass newTemporaryIn:aDirectoryPrefix |
|
455 |
]. |
|
456 |
||
3059
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
457 |
"/ care for existing leftOver tempFiles |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
458 |
"/ from a previous boot of the OS |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
459 |
"/ (i.e. my pid could be the same as when executed |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
460 |
"/ the last time before system reboot ...) |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
461 |
|
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
462 |
[fn isNil or:[fn exists]] whileTrue:[ |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
463 |
"/ although the above allows things to be redefined in concrete classes, |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
464 |
"/ the following should work on all systems ... |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
465 |
|
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
466 |
NextTempFilenameIndex isNil ifTrue:[ |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
467 |
NextTempFilenameIndex := 1. |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
468 |
]. |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
469 |
|
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
470 |
pid := OperatingSystem getProcessId printString. |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
471 |
nameString := (self tempFileNameTemplate) bindWith:pid with:(NextTempFilenameIndex printString). |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
472 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
473 |
|
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
474 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
475 |
fn := aDirectoryPrefix asFilename construct:nameString |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
476 |
] ifTrue:[ |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
477 |
fn := self named:nameString |
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
478 |
] |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
479 |
]. |
3059
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
480 |
^ fn |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
481 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
482 |
"temp files in '/tmp': |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
483 |
|
1080 | 484 |
Filename newTemporary |
485 |
" |
|
486 |
||
487 |
"temp files somewhere |
|
488 |
(not recommended - use above since it can be controlled via shell variables): |
|
489 |
||
3752 | 490 |
UnixFilename newTemporaryIn:'/tmp' |
491 |
UnixFilename newTemporaryIn:'/tmp' |
|
492 |
UnixFilename newTemporaryIn:'/usr/tmp' |
|
493 |
UnixFilename newTemporaryIn:'/' |
|
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
494 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
495 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
496 |
"a local temp file: |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
497 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
498 |
Filename newTemporaryIn:'' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
499 |
Filename newTemporaryIn:nil |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
500 |
Filename newTemporaryIn:'.' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
501 |
Filename newTemporaryIn:('source' asFilename) |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
502 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
503 |
|
3059
3eb5132d391a
care for duplicate tempFile name.
Claus Gittinger <cg@exept.de>
parents:
3046
diff
changeset
|
504 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
3752 | 505 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
1080 | 506 |
! |
507 |
||
2922 | 508 |
rootDirectory |
509 |
"return a filename for the root directory" |
|
510 |
||
511 |
(self ~~ ConcreteClass) ifTrue:[ |
|
512 |
^ ConcreteClass rootDirectory |
|
513 |
]. |
|
514 |
||
515 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
516 |
||
517 |
^ self named:(self separator asString) |
|
518 |
||
519 |
" |
|
520 |
Filename rootDirectory |
|
521 |
" |
|
522 |
||
523 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
524 |
! |
|
525 |
||
3847
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
526 |
rootDirectoryOnVolume:aVolumeName |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
527 |
"return a filename for the root directory on some volume" |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
528 |
|
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
529 |
(self ~~ ConcreteClass) ifTrue:[ |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
530 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
531 |
]. |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
532 |
|
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
533 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
534 |
|
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
535 |
^ self named:aVolumeName |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
536 |
|
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
537 |
" |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
538 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
3852 | 539 |
Filename rootDirectoryOnVolume:'d:' |
3847
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
540 |
" |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
541 |
|
3852 | 542 |
"Modified: / 24.9.1998 / 19:06:32 / cg" |
3847
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
543 |
! |
91cd6bfb0296
added #rootDirectoryOnVolume:
Claus Gittinger <cg@exept.de>
parents:
3843
diff
changeset
|
544 |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
545 |
tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
546 |
"return the temp directory as a filename. |
1968 | 547 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
548 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
549 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
550 |
|
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
551 |
Notice: do not hardcode '/tmp' into your programs - things may be |
2906 | 552 |
different on other OS's. Also, the user may want to set the |
553 |
TMPDIR environment variable to have her temp files somewhere else. |
|
554 |
(especially on SUNOS, the root partition is ALWAYS too small ..." |
|
1080 | 555 |
|
556 |
|tempDir| |
|
557 |
||
1969 | 558 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
2906 | 559 |
tempDir isNil ifTrue:[ |
560 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
561 |
]. |
|
1968 | 562 |
]. |
1080 | 563 |
tempDir isNil ifTrue:[ |
2906 | 564 |
tempDir := self defaultTempDirectoryName |
1080 | 565 |
]. |
566 |
^ self named:tempDir |
|
567 |
||
568 |
" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
569 |
Filename tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
570 |
Filename tempDirectory pathName |
1080 | 571 |
" |
572 |
||
573 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
574 |
"Created: 7.3.1996 / 14:51:18 / cg" |
2906 | 575 |
"Modified: 8.9.1997 / 00:08:11 / cg" |
1 | 576 |
! ! |
577 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
578 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
579 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
580 |
concreteClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
581 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
582 |
in ST-80, different subclasses of Filename are used for different |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
583 |
OperatingSystems; concreteClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
584 |
Since in ST/X, there is (currently) only one Filename class, return it here." |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
585 |
|
2906 | 586 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
587 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
588 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 589 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
590 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
591 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
592 |
defaultClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
593 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
594 |
in ST-80, different subclasses of Filename are used for different |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
595 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
596 |
Since in ST/X, there is (currently) only one Filename class, return it here." |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
597 |
|
2906 | 598 |
^ ConcreteClass |
599 |
||
600 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
601 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
602 |
|
2922 | 603 |
!Filename class methodsFor:'misc'! |
604 |
||
605 |
canonicalize:aPathString |
|
3077 | 606 |
"convert the argument, aPathString to a good format. |
607 |
This should eliminate useless directory components (i.e. '././') |
|
608 |
and useless tree walks (i.e. '../foo/..')." |
|
609 |
||
2922 | 610 |
^ aPathString |
611 |
||
3077 | 612 |
"Created: / 13.9.1997 / 10:50:01 / cg" |
613 |
"Modified: / 1.11.1997 / 12:44:57 / cg" |
|
614 |
! |
|
615 |
||
616 |
filterSeps:aFilenameString |
|
617 |
"ST80 compatibility: |
|
618 |
filter out (invalid) separators in aFilenameString. |
|
619 |
We recommend using #makeLegalFilename" |
|
620 |
||
3658 | 621 |
^ aFilenameString copyReplaceAll:(Character space) with:$_. |
3077 | 622 |
|
623 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 624 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 625 |
! |
626 |
||
627 |
suggest:aFilenameString |
|
628 |
"return a fileNamestring based on the argument, |
|
629 |
which is legal on the current platform." |
|
630 |
||
631 |
^ self canonicalize:aFilenameString |
|
632 |
||
633 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 634 |
! ! |
635 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
636 |
!Filename class methodsFor:'queries'! |
2 | 637 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
638 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
639 |
"separate the pathName given by aString into |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
640 |
a collection containing the directory components and the files name as |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
641 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
642 |
If the argument names an absolute path, the first component will be the |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
643 |
name of the root directory (i.e. '/')." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
644 |
|
3852 | 645 |
|sep f vol rest components| |
2503 | 646 |
|
2906 | 647 |
(self ~~ ConcreteClass) ifTrue:[ |
648 |
^ ConcreteClass components:aString |
|
649 |
]. |
|
650 |
||
651 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
3852 | 652 |
"/ However, MSDOS drive-letters and network drives are |
653 |
"/ not correctly handled here. |
|
2906 | 654 |
|
2503 | 655 |
sep := self separator. |
3852 | 656 |
f := aString asFilename. |
657 |
vol := f volume. |
|
658 |
vol size ~~ 0 ifTrue:[ |
|
659 |
rest := f localPathName. |
|
660 |
] ifFalse:[ |
|
661 |
rest := aString |
|
662 |
]. |
|
663 |
||
664 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
665 |
components first isEmpty ifTrue:[ |
2906 | 666 |
components at:1 put:(sep asString) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
667 |
]. |
3852 | 668 |
|
669 |
"/ prepend volume to first component (the root directory) |
|
670 |
vol size ~~ 0 ifTrue:[ |
|
671 |
components at:1 put:(vol , (components at:1)). |
|
672 |
]. |
|
3373 | 673 |
components last isEmpty ifTrue:[ |
674 |
^ components copyWithoutLast:1 |
|
675 |
]. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
676 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
677 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
678 |
" |
3373 | 679 |
Filename components:'/foo/bar/baz' |
3852 | 680 |
Filename components:'/' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
681 |
Filename components:'foo/bar/baz' |
2503 | 682 |
Filename components:'foo/bar' |
683 |
Filename components:'foo' |
|
3852 | 684 |
Filename components:'/foo' |
685 |
||
686 |
Filename components:'\' |
|
687 |
Filename components:'\foo' |
|
688 |
Filename components:'\foo\' |
|
689 |
Filename components:'\foo\bar' |
|
690 |
Filename components:'\foo\bar\' |
|
691 |
Filename components:'c:' |
|
692 |
Filename components:'c:\' |
|
693 |
Filename components:'c:\foo' |
|
694 |
Filename components:'c:\foo\' |
|
695 |
Filename components:'c:\foo\bar' |
|
696 |
Filename components:'c:\foo\bar\' |
|
697 |
Filename components:'\\idefix' |
|
698 |
Filename components:'\\idefix\home' |
|
699 |
Filename components:'\\idefix\home\bar' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
700 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
701 |
|
3852 | 702 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
703 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
704 |
|
2963 | 705 |
directorySuffix |
706 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
707 |
The default is nil here, redefined for VMS" |
|
708 |
||
709 |
(self ~~ ConcreteClass) ifTrue:[ |
|
710 |
^ ConcreteClass directorySuffix |
|
711 |
]. |
|
712 |
||
713 |
^ nil |
|
714 |
! |
|
715 |
||
1523 | 716 |
errorReporter |
717 |
"who knows the signals to report errors?" |
|
718 |
||
719 |
^ FileStream |
|
720 |
||
721 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
722 |
! |
|
723 |
||
440 | 724 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
725 |
"perform filename completion on aString in some directory; |
|
726 |
return the longest matching filename prefix as a string. |
|
1318 | 727 |
The boolean directoriesOnly and filesOnly control respectively, |
728 |
if only directories or only regular files are to be considered for completion. |
|
729 |
If multiple files match, the exception block aBlock is evaluated with a |
|
730 |
filename representing the directory (where the match was done) as argument. |
|
440 | 731 |
(this may be different from the inDirectory argument, if aString is absolute |
732 |
or starts with ../)" |
|
733 |
||
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
734 |
|s f matchSet nMatch name words dir isAbsolute| |
440 | 735 |
|
2906 | 736 |
(self ~~ ConcreteClass) ifTrue:[ |
737 |
^ ConcreteClass |
|
738 |
filenameCompletionFor:aString |
|
739 |
directory:inDirectory |
|
740 |
directoriesOnly:directoriesOnly |
|
741 |
filesOnly:filesOnly |
|
742 |
ifMultiple:aBlock |
|
743 |
]. |
|
744 |
||
745 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
746 |
||
440 | 747 |
s := aString. |
748 |
" |
|
749 |
find the last word ... |
|
750 |
" |
|
751 |
words := s asCollectionOfWords. |
|
752 |
words size == 0 ifTrue:[ |
|
2906 | 753 |
aBlock value:'.' asFilename. |
754 |
^ '' |
|
440 | 755 |
]. |
756 |
||
757 |
f := words last asFilename. |
|
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
758 |
isAbsolute := f isAbsolute. |
440 | 759 |
|
760 |
matchSet := f filenameCompletionIn:inDirectory. |
|
761 |
||
762 |
dir := f directory. |
|
763 |
||
764 |
directoriesOnly ifTrue:[ |
|
2906 | 765 |
matchSet := matchSet select:[:aFilename | |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
766 |
|f| |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
767 |
|
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
768 |
isAbsolute ifTrue:[ |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
769 |
f := aFilename asFilename |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
770 |
] ifFalse:[ |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
771 |
f := (dir construct:aFilename). |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
772 |
]. |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
773 |
f isDirectory |
2906 | 774 |
]. |
440 | 775 |
] ifFalse:[ |
2906 | 776 |
filesOnly ifTrue:[ |
777 |
matchSet := matchSet select:[:aFilename | |
|
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
778 |
|f| |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
779 |
|
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
780 |
isAbsolute ifTrue:[ |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
781 |
f := aFilename asFilename |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
782 |
] ifFalse:[ |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
783 |
f := (dir construct:aFilename). |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
784 |
]. |
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
785 |
f isDirectory not |
2906 | 786 |
]. |
787 |
] |
|
440 | 788 |
]. |
789 |
||
790 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
2906 | 791 |
" |
792 |
more than one possible completion - |
|
793 |
" |
|
794 |
aBlock value:f |
|
440 | 795 |
]. |
796 |
" |
|
797 |
even with more than one possible completion, |
|
798 |
f's name is now the common prefix |
|
799 |
" |
|
800 |
name := f asString. |
|
801 |
nMatch == 1 ifTrue:[ |
|
2906 | 802 |
" |
803 |
exactly one possible completion - |
|
804 |
" |
|
3752 | 805 |
"/ f := dir construct:matchSet first. |
806 |
false "directoriesOnly" ifFalse:[ |
|
2906 | 807 |
f isDirectory ifTrue:[ |
808 |
(name endsWith:(Filename separator)) ifFalse:[ |
|
3504 | 809 |
name := name , (Filename separator) |
2906 | 810 |
]. |
811 |
]. |
|
812 |
] |
|
440 | 813 |
]. |
814 |
||
815 |
" |
|
816 |
construct new contents, by taking |
|
817 |
last words completion |
|
818 |
" |
|
819 |
s := ''. |
|
820 |
1 to:(words size - 1) do:[:idx | |
|
2906 | 821 |
s := s , (words at:idx) , ' ' |
440 | 822 |
]. |
823 |
s := s , name. |
|
824 |
||
825 |
"/ special: if there was no change, and the string represented |
|
826 |
"/ is a directories name, add a directory separator |
|
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
827 |
((nMatch == 1) or:[s = aString]) ifTrue:[ |
2906 | 828 |
(s endsWith:Filename separator) ifFalse:[ |
829 |
s asFilename isDirectory ifTrue:[ |
|
830 |
^ s , Filename separator asString |
|
831 |
] |
|
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
832 |
]. |
440 | 833 |
]. |
834 |
||
835 |
^ s |
|
1318 | 836 |
|
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
837 |
"Modified: / 24.9.1998 / 22:10:34 / cg" |
615 | 838 |
! |
839 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
840 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
841 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
842 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
843 |
If aPattern contains a directory path, files are tried there; |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
844 |
otherwise, files from the currentDirectory are tried. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
845 |
The returned strings are the expanded names, in the same form |
2550 | 846 |
as given in pattern. |
847 |
The pattern should be a simple pattern." |
|
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
848 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
849 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
850 |
|
2906 | 851 |
(self ~~ ConcreteClass) ifTrue:[ |
852 |
^ ConcreteClass filesMatching:aPattern |
|
853 |
]. |
|
854 |
||
855 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
856 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
857 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
858 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
859 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
860 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
861 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
862 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
863 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
864 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
865 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
866 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
867 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
868 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
869 |
|
2906 | 870 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 871 |
! |
872 |
||
2903 | 873 |
isBadCharacter:aCharacter |
874 |
"return true, if aCharacter is unallowed in a filename." |
|
875 |
||
876 |
|ascii| |
|
877 |
||
2906 | 878 |
(self ~~ ConcreteClass) ifTrue:[ |
879 |
^ ConcreteClass isBadCharacter:aCharacter |
|
880 |
]. |
|
881 |
||
2903 | 882 |
ascii := aCharacter asciiValue. |
883 |
ascii < 32 ifTrue:[ |
|
2906 | 884 |
^ true "/ a control character |
2903 | 885 |
]. |
886 |
ascii == 16rFF ifTrue:[ |
|
2906 | 887 |
^ true "/ delete character |
2903 | 888 |
]. |
889 |
^ false |
|
2906 | 890 |
|
891 |
"Modified: 8.9.1997 / 00:32:59 / cg" |
|
2903 | 892 |
! |
893 |
||
894 |
isCaseSensitive |
|
895 |
"return true, if filenames are case sensitive. |
|
896 |
We ask the OS about this, to be independent here." |
|
897 |
||
2906 | 898 |
(self ~~ ConcreteClass) ifTrue:[ |
899 |
^ ConcreteClass isCaseSensitive |
|
900 |
]. |
|
901 |
||
2903 | 902 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 903 |
|
904 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 905 |
! |
906 |
||
615 | 907 |
localNameStringFrom:aString |
908 |
"ST-80 compatibility. |
|
909 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 910 |
GUESS: |
911 |
does it strip off any volume characters and make a path relative ?" |
|
912 |
||
913 |
|sep| |
|
615 | 914 |
|
2906 | 915 |
(self ~~ ConcreteClass) ifTrue:[ |
916 |
^ ConcreteClass localNameStringFrom:aString |
|
917 |
]. |
|
918 |
||
2922 | 919 |
sep := self separator asString. |
920 |
(aString startsWith:sep) ifTrue:[ |
|
921 |
^ aString copyFrom:sep size + 1 |
|
615 | 922 |
]. |
923 |
^ aString |
|
924 |
||
925 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 926 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 927 |
! |
928 |
||
2908 | 929 |
maxComponentLength |
930 |
"return the maximum number of characters a filename component may |
|
931 |
be in size. This depends on the OperatingSystem." |
|
932 |
||
933 |
(self ~~ ConcreteClass) ifTrue:[ |
|
934 |
^ ConcreteClass maxComponentLength |
|
935 |
]. |
|
936 |
^ OperatingSystem maxFileNameLength |
|
937 |
! |
|
938 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
939 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
940 |
"return the maximum number of characters a filename may be in size. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
941 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
942 |
|
2908 | 943 |
(self ~~ ConcreteClass) ifTrue:[ |
944 |
^ ConcreteClass maxLength |
|
945 |
]. |
|
946 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
947 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
948 |
"Created: 29.2.1996 / 20:57:11 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
949 |
"Modified: 29.2.1996 / 20:57:46 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
950 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
951 |
|
3171 | 952 |
nullFilename |
953 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
954 |
The default is nil here" |
|
955 |
||
956 |
(self ~~ ConcreteClass) ifTrue:[ |
|
957 |
^ ConcreteClass nullFilename |
|
958 |
]. |
|
959 |
||
960 |
^ nil |
|
961 |
||
962 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
963 |
! |
|
964 |
||
615 | 965 |
parentDirectoryName |
966 |
"return the name used for the parent directory. |
|
967 |
This is '..' for unix and dos-like systems. |
|
968 |
(there may be more in the future." |
|
969 |
||
2906 | 970 |
(self ~~ ConcreteClass) ifTrue:[ |
971 |
^ ConcreteClass parentDirectoryName |
|
972 |
]. |
|
973 |
||
974 |
^ OperatingSystem parentDirectoryName |
|
975 |
||
976 |
" |
|
977 |
Filename parentDirectoryName |
|
978 |
" |
|
979 |
||
980 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 981 |
! |
982 |
||
983 |
separator |
|
984 |
"return the file/directory separator. |
|
2906 | 985 |
This is to be redefined in concrete classes; |
986 |
the following default usually leads to a flat view of |
|
987 |
the fileSystem (huh - BS2000 ?)" |
|
988 |
||
989 |
(self ~~ ConcreteClass) ifTrue:[ |
|
990 |
^ ConcreteClass separator |
|
991 |
]. |
|
992 |
^ $_ |
|
615 | 993 |
|
994 |
" |
|
995 |
Filename separator |
|
996 |
" |
|
2906 | 997 |
|
998 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 999 |
! |
1000 |
||
1001 |
suffixSeparator |
|
1002 |
"return the filename suffix separator. |
|
1003 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 1004 |
(there is currently no known system, where this differs)" |
615 | 1005 |
|
1006 |
^ $. |
|
1007 |
||
1008 |
" |
|
1009 |
Filename suffixSeparator |
|
1010 |
" |
|
1011 |
||
1012 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1013 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1014 |
! |
1015 |
||
2906 | 1016 |
tempFileNameTemplate |
1017 |
"return a template for temporary files. |
|
1018 |
This is expanded with the current processID and a sequenceNumber |
|
1019 |
to generate a unique filename." |
|
1020 |
||
1021 |
(self ~~ ConcreteClass) ifTrue:[ |
|
1022 |
^ ConcreteClass tempFileNameTemplate |
|
1023 |
]. |
|
1024 |
||
1025 |
^ 'stxtmp_%1_%2' |
|
1026 |
||
1027 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1028 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1029 |
! |
|
1030 |
||
615 | 1031 |
volumes |
1032 |
"ST-80 compatibility. |
|
2896 | 1033 |
GUESS: does it return the available drives on MSDOS systems ? |
1034 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1035 |
||
2906 | 1036 |
(self ~~ ConcreteClass) ifTrue:[ |
1037 |
^ ConcreteClass volumes |
|
1038 |
]. |
|
1039 |
||
2896 | 1040 |
^ OperatingSystem getDriveList |
615 | 1041 |
|
1042 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
2906 | 1043 |
"Modified: 8.9.1997 / 00:35:19 / cg" |
615 | 1044 |
! ! |
1045 |
||
1046 |
!Filename methodsFor:'comparing'! |
|
1047 |
||
1048 |
= aFilename |
|
1049 |
"return true, if the argument represents the same filename" |
|
1050 |
||
1051 |
|str| |
|
1052 |
||
1053 |
self species == aFilename species ifTrue:[ |
|
1054 |
str := aFilename asString. |
|
1055 |
self class isCaseSensitive ifTrue:[ |
|
1056 |
^ nameString = str |
|
1057 |
]. |
|
1058 |
^ nameString sameAs:str |
|
1059 |
]. |
|
1060 |
^ false |
|
1061 |
! |
|
1062 |
||
1063 |
hash |
|
1064 |
"return an integer useful as a hash-key" |
|
1065 |
||
1066 |
^ nameString hash |
|
3868 | 1067 |
! |
1068 |
||
1069 |
sameContentsAs:aFilename |
|
1070 |
"return true if the file represented by the receiver has the |
|
1071 |
same contents as the file represented by the argument, aFilename. |
|
1072 |
This compares the files actual contents; not the filenames." |
|
1073 |
||
1074 |
|s1 s2 buffer1 buffer2 rslt n| |
|
1075 |
||
1076 |
buffer1 := ByteArray new:8192. |
|
1077 |
buffer2 := ByteArray new:8192. |
|
1078 |
||
1079 |
s1 := self readStream. |
|
1080 |
s1 isNil ifTrue:[ |
|
1081 |
^ self error:('cannot open %1 for reading' bindWith:nameString) |
|
1082 |
]. |
|
1083 |
s2 := aFilename asFilename readStream. |
|
1084 |
s2 isNil ifTrue:[ |
|
1085 |
^ self error:('cannot open %1 for reading' bindWith:aFilename asFilename name) |
|
1086 |
]. |
|
3869
6d7dca488a41
read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents:
3868
diff
changeset
|
1087 |
s1 binary. |
6d7dca488a41
read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents:
3868
diff
changeset
|
1088 |
s2 binary. |
3868 | 1089 |
|
1090 |
[s1 atEnd] whileFalse:[ |
|
1091 |
n := s1 nextBytes:8192 into:buffer1 startingAt:1. |
|
1092 |
n == 0 ifTrue:[ |
|
1093 |
rslt := s2 atEnd. |
|
1094 |
s1 close. s2 close. |
|
1095 |
^ rslt |
|
1096 |
]. |
|
1097 |
(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[ |
|
1098 |
"/ aFilename shorter |
|
1099 |
s1 close. s2 close. |
|
1100 |
^ false |
|
1101 |
]. |
|
1102 |
buffer1 ~= buffer2 ifTrue:[ |
|
1103 |
s1 close. s2 close. |
|
1104 |
^ false |
|
1105 |
] |
|
1106 |
]. |
|
1107 |
rslt := s2 atEnd. |
|
1108 |
s1 close. s2 close. |
|
1109 |
^ rslt |
|
1110 |
||
1111 |
" |
|
1112 |
'Make.proto' asFilename sameContentsAs:'Makefile' |
|
1113 |
" |
|
615 | 1114 |
! ! |
1115 |
||
1116 |
!Filename methodsFor:'converting'! |
|
1117 |
||
1118 |
asAbsoluteFilename |
|
1119 |
"return the receiver converted to a filename with |
|
1120 |
an absolute pathname." |
|
1121 |
||
1122 |
^ self pathName asFilename |
|
1123 |
! |
|
1124 |
||
1125 |
asFilename |
|
1970 | 1126 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 1127 |
|
1128 |
"Thats pretty easy here :-)" |
|
1129 |
^ self |
|
1970 | 1130 |
|
1131 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 1132 |
! |
1133 |
||
1134 |
asString |
|
1135 |
"return the receiver converted to a string" |
|
1136 |
||
1137 |
^ nameString |
|
1138 |
! |
|
1139 |
||
1140 |
makeLegalFilename |
|
1970 | 1141 |
"convert the receivers name to be a legal filename. |
1142 |
This removes/replaces invalid characters and/or compresses |
|
1143 |
the name as required by the OS. |
|
615 | 1144 |
The implementation may change in the future to be more |
1145 |
OS specific." |
|
1146 |
||
1147 |
" |
|
1148 |
actually, in Unix spaces are allowed - but it makes life |
|
1149 |
so hard; therefore, replace them by underscores ... |
|
1150 |
" |
|
3658 | 1151 |
(nameString includes:Character space) ifTrue:[ |
1152 |
nameString := nameString copyReplaceAll:(Character space) with:$_. |
|
1153 |
]. |
|
615 | 1154 |
" |
1155 |
need more - especially on SYS5.3 type systems, |
|
1156 |
we may want to contract the fileName to 14 characters. |
|
1157 |
" |
|
1158 |
^ self |
|
1159 |
||
1160 |
" |
|
1161 |
'hello world' asFilename makeLegalFilename |
|
1162 |
" |
|
1970 | 1163 |
|
3658 | 1164 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1165 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1166 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1167 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1168 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1169 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1170 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1171 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1172 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 1173 |
! ! |
1174 |
||
542 | 1175 |
!Filename methodsFor:'error handling'! |
1176 |
||
615 | 1177 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1178 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1179 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1180 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1181 |
|
615 | 1182 |
^ OperatingSystem accessDeniedErrorSignal |
542 | 1183 |
raiseRequestWith:filename |
615 | 1184 |
errorString:('access denied: ' , filename asString) |
1185 |
! |
|
1186 |
||
1187 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1188 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1189 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1190 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1191 |
|
615 | 1192 |
^ OperatingSystem accessDeniedErrorSignal |
1193 |
raiseRequestWith:filename |
|
1194 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 1195 |
! |
1196 |
||
1197 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1198 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1199 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1200 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1201 |
|
542 | 1202 |
^ OperatingSystem fileNotFoundErrorSignal |
1203 |
raiseRequestWith:filename |
|
1204 |
errorString:('file not found: ' , filename asString) |
|
1205 |
! |
|
1206 |
||
1207 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1208 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1209 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1210 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1211 |
|
542 | 1212 |
^ OperatingSystem accessDeniedErrorSignal |
1213 |
raiseRequestWith:filename |
|
1214 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 1215 |
! |
1216 |
||
1217 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1218 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1219 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1220 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1221 |
|
615 | 1222 |
^ OperatingSystem errorSignal |
1223 |
raiseRequestWith:filename |
|
1224 |
errorString:string |
|
1225 |
! ! |
|
1226 |
||
1227 |
!Filename methodsFor:'file access'! |
|
1228 |
||
3015 | 1229 |
appendStream |
1230 |
"return a stream for appending to the file represented by the receiver. |
|
1231 |
If the file does not already exist, it is created. |
|
1232 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
1233 |
||
1234 |
^ self appendingWriteStream |
|
1235 |
! |
|
1236 |
||
615 | 1237 |
appendingWriteStream |
1238 |
"return a stream for appending to the file represented by the receiver. |
|
1239 |
If the file does not already exist, it is created." |
|
1240 |
||
2947 | 1241 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
615 | 1242 |
! |
1243 |
||
1244 |
newReadWriteStream |
|
1245 |
"return a stream for read/write the file represented by the receiver. |
|
1246 |
If the file does not already exist, it is created." |
|
1247 |
||
2947 | 1248 |
^ FileStream newFileNamed:(self osNameForAccess) |
615 | 1249 |
! |
1250 |
||
1251 |
readStream |
|
1252 |
"return a stream for reading from the file represented by the receiver. |
|
1253 |
If the file does not already exist, nil is returned." |
|
1254 |
||
2947 | 1255 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 1256 |
|
1257 |
" |
|
1258 |
'/tmp/foo' asFilename readStream |
|
1259 |
" |
|
1260 |
! |
|
1261 |
||
1262 |
readWriteStream |
|
1263 |
"return a stream for read/write the file represented by the receiver. |
|
1264 |
If the file does not already exist, nil is returned." |
|
1265 |
||
2947 | 1266 |
^ FileStream oldFileNamed:(self osNameForAccess) |
615 | 1267 |
! |
1268 |
||
1269 |
writeStream |
|
1270 |
"return a stream for writing to the file represented by the receiver. |
|
1271 |
If the file does not already exist, it is created." |
|
1272 |
||
2947 | 1273 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 1274 |
|
1275 |
" |
|
1276 |
'/tmp/foo' asFilename writeStream |
|
1277 |
" |
|
1278 |
! ! |
|
1279 |
||
1280 |
!Filename methodsFor:'file operations'! |
|
1281 |
||
1282 |
addAccessRights:aCollection |
|
1283 |
"add the access rights as specified in aCollection for the file represented |
|
1284 |
by the receiver. The argument must be a collection of symbols, |
|
1285 |
such as #readUser, #writeGroup etc." |
|
1286 |
||
2922 | 1287 |
|access osName| |
1288 |
||
2947 | 1289 |
osName := self osNameForFile. |
2922 | 1290 |
access := OperatingSystem accessModeOf:osName. |
615 | 1291 |
aCollection do:[:accessSymbol | |
1292 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
1293 |
]. |
|
2922 | 1294 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1295 |
^ self accessDeniedError:self |
1296 |
] |
|
1297 |
||
1298 |
" |
|
1299 |
'foo' asFilename writeStream close. |
|
1300 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
1301 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
1302 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
1303 |
" |
|
1304 |
! |
|
1305 |
||
2982 | 1306 |
basicMakeDirectory |
1307 |
"create a directory with the receivers name. |
|
1308 |
Return true if successful, false if not." |
|
1309 |
||
1310 |
^ OperatingSystem createDirectory:(self osNameForDirectory) |
|
1311 |
! |
|
1312 |
||
615 | 1313 |
copyTo:newName |
1314 |
"copy the file - the argument must be convertable to a filename. |
|
671 | 1315 |
Return true if successful, false if not." |
615 | 1316 |
|
1317 |
|inStream outStream buffer bufferSize count newFile| |
|
1318 |
||
1319 |
bufferSize := 8 * 1024. |
|
1320 |
buffer := ByteArray new:bufferSize. |
|
1321 |
inStream := self readStream. |
|
1322 |
inStream isNil ifTrue:[ |
|
1323 |
^ self fileNotFoundError:self |
|
1324 |
]. |
|
1325 |
||
1326 |
outStream := (newFile := newName asFilename) writeStream. |
|
1327 |
outStream isNil ifTrue:[ |
|
1328 |
^ self fileCreationError:newFile |
|
1329 |
]. |
|
1330 |
||
1331 |
[inStream atEnd] whileFalse:[ |
|
1332 |
count := inStream nextBytes:bufferSize into:buffer. |
|
1333 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
|
1334 |
^ self fileCreationError:newFile |
|
1335 |
] |
|
1336 |
]. |
|
1337 |
outStream close. |
|
1338 |
inStream close. |
|
1339 |
||
1340 |
" |
|
1341 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
1342 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
1343 |
" |
|
1344 |
! |
|
1345 |
||
1346 |
delete |
|
1347 |
"remove the file - same as remove, for ST-80 compatibility" |
|
1348 |
||
1349 |
self remove |
|
1350 |
! |
|
1351 |
||
1352 |
makeDirectory |
|
1353 |
"create a directory with the receivers name. |
|
671 | 1354 |
Return true if successful, false if not." |
615 | 1355 |
|
2982 | 1356 |
(self basicMakeDirectory) ifFalse:[ |
1357 |
"/ |
|
1358 |
"/ could have existed before ... |
|
1359 |
"/ |
|
2629 | 1360 |
(self exists and:[self isDirectory]) ifFalse:[ |
2982 | 1361 |
self fileCreationError:self. |
1362 |
^ false |
|
2629 | 1363 |
] |
2982 | 1364 |
]. |
1365 |
^ true |
|
1970 | 1366 |
|
1367 |
"Modified: 12.11.1996 / 12:25:22 / cg" |
|
615 | 1368 |
! |
1369 |
||
844 | 1370 |
makeExecutable |
1371 |
"make the file executable - you must have permission to do so. |
|
1372 |
For directories, execution means: 'allow changing into it'" |
|
1373 |
||
1374 |
^ self addAccessRights:#(executeUser) |
|
1375 |
||
1376 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
1377 |
! |
|
1378 |
||
1379 |
makeExecutableForAll |
|
1380 |
"make the file executable for all - you must have permission to do so. |
|
1381 |
For directories, execution means: 'allow changing into it'" |
|
1382 |
||
1383 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
1384 |
||
1385 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
1386 |
! |
|
1387 |
||
615 | 1388 |
makeReadable |
1389 |
"make the file readable for the owner - you must have permission to do so." |
|
1390 |
||
1391 |
^ self addAccessRights:#(readUser) |
|
1392 |
! |
|
1393 |
||
1394 |
makeReadableForAll |
|
1395 |
"make the file readable for all - you must have permission to do so." |
|
1396 |
||
1397 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
1398 |
! |
|
1399 |
||
1400 |
makeUnwritable |
|
1401 |
"make the file unwritable for all - you must have permission to do so." |
|
1402 |
||
1403 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
1404 |
! |
|
1405 |
||
1406 |
makeWritable |
|
1407 |
"make the file writableable for all - you must have permission to do so." |
|
1408 |
||
1409 |
^ self addAccessRights:#(writeUser) |
|
1410 |
! |
|
1411 |
||
1412 |
makeWritableForAll |
|
1413 |
"make the file writable for all - you must have permission to do so." |
|
1414 |
||
1415 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
1416 |
! |
|
1417 |
||
1418 |
moveTo:newName |
|
1419 |
"copy the file represented by the receiver, then delete it. |
|
1420 |
This is different to renaming in case of cross device moves. |
|
671 | 1421 |
Raise an error if not successful." |
615 | 1422 |
|
1423 |
self copyTo:newName. |
|
1424 |
self remove |
|
1425 |
! |
|
1426 |
||
659 | 1427 |
recursiveMakeDirectory |
1428 |
"create a directory with the receivers name and all required intermediate |
|
1429 |
directories. |
|
671 | 1430 |
Raise an error if not successful." |
659 | 1431 |
|
2922 | 1432 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
671 | 1433 |
^ self fileCreationError:self |
659 | 1434 |
] |
1435 |
||
1436 |
"Created: 27.11.1995 / 23:36:40 / cg" |
|
1437 |
! |
|
1438 |
||
615 | 1439 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1440 |
"if I represent a regular file, remove it. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1441 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
671 | 1442 |
Raise an error if not successful." |
615 | 1443 |
|
1444 |
|ok| |
|
1445 |
||
3302 | 1446 |
"/ typically, an 'rm -rf' is faster and removes better; |
1447 |
"/ however, if the fork fails, fallBack doing a manual |
|
1448 |
"/ directory walk. |
|
1449 |
||
1450 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
1451 |
ok ifFalse:[ |
|
1452 |
self recursiveRemoveWithoutOSCommand |
|
1453 |
]. |
|
1454 |
||
1455 |
" |
|
1456 |
'foo' asFilename makeDirectory. |
|
1457 |
'foo/bar' asFilename writeStream close. |
|
1458 |
('foo' asFilename remove) ifFalse:[ |
|
1459 |
Transcript showCR:'could not remove foo' |
|
1460 |
] |
|
1461 |
" |
|
1462 |
" |
|
1463 |
'foo' asFilename makeDirectory. |
|
1464 |
'foo/bar' asFilename writeStream close. |
|
1465 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
1466 |
Transcript showCR:'could not remove foo' |
|
1467 |
] |
|
1468 |
" |
|
1469 |
||
1470 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
1471 |
"Modified: / 25.2.1998 / 19:51:34 / cg" |
|
1472 |
! |
|
1473 |
||
1474 |
recursiveRemoveWithoutOSCommand |
|
1475 |
"if I represent a regular file, remove it. |
|
1476 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
1477 |
Raise an error if not successful. |
|
1478 |
This one walks down the directory hierarchy, not using any OS |
|
1479 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1480 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1481 |
self isDirectory ifTrue:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1482 |
self directoryContents do:[:aFilenameString | |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1483 |
|f| |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1484 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1485 |
f := self construct:aFilenameString. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1486 |
f isDirectory ifTrue:[ |
3302 | 1487 |
f recursiveRemoveWithoutOSCommand |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1488 |
] ifFalse:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1489 |
f remove |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1490 |
]. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1491 |
] |
615 | 1492 |
]. |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1493 |
self remove |
615 | 1494 |
|
1495 |
" |
|
1496 |
'foo' asFilename makeDirectory. |
|
1497 |
'foo/bar' asFilename writeStream close. |
|
1498 |
('foo' asFilename remove) ifFalse:[ |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1499 |
Transcript showCR:'could not remove foo' |
615 | 1500 |
] |
1501 |
" |
|
1502 |
" |
|
1503 |
'foo' asFilename makeDirectory. |
|
1504 |
'foo/bar' asFilename writeStream close. |
|
1505 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1506 |
Transcript showCR:'could not remove foo' |
615 | 1507 |
] |
1508 |
" |
|
1509 |
||
3302 | 1510 |
"Created: / 25.2.1998 / 19:50:40 / cg" |
1511 |
"Modified: / 25.2.1998 / 19:52:08 / cg" |
|
615 | 1512 |
! |
1513 |
||
1514 |
remove |
|
845 | 1515 |
"remove the file/directory. |
672 | 1516 |
Raise an error if not successful. |
845 | 1517 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 1518 |
|
1519 |
|ok| |
|
1520 |
||
1521 |
self exists ifFalse:[ ^ self]. |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1522 |
(self isSymbolicLink not and:[self isDirectory]) ifTrue:[ |
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1523 |
ok := OperatingSystem removeDirectory:(self osNameForFile) |
615 | 1524 |
] ifFalse:[ |
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1525 |
ok := OperatingSystem removeFile:(self osNameForFile) |
615 | 1526 |
]. |
1527 |
ok ifFalse:[ |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1528 |
self removeError:self |
615 | 1529 |
]. |
1530 |
||
1531 |
" |
|
1532 |
(FileStream newFileNamed:'foo') close. |
|
1533 |
'foo' asFilename remove |
|
1534 |
" |
|
1535 |
||
1536 |
" |
|
1537 |
'foo' asFilename makeDirectory. |
|
1538 |
'foo/bar' asFilename writeStream close. |
|
1539 |
('foo' asFilename remove) ifFalse:[ |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1540 |
Transcript showCR:'could not remove foo' |
615 | 1541 |
] |
1542 |
" |
|
1543 |
||
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1544 |
"Modified: / 10.1.1996 / 18:44:50 / cg" |
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1545 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
615 | 1546 |
! |
1547 |
||
1548 |
removeAccessRights:aCollection |
|
1549 |
"remove the access rights as specified in aCollection for the file represented |
|
1550 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 1551 |
such as #readUser, #writeGroup etc. |
1552 |
Raise an error if not successful." |
|
615 | 1553 |
|
2922 | 1554 |
|access osName| |
1555 |
||
2947 | 1556 |
osName := self osNameForFile. |
2922 | 1557 |
access := OperatingSystem accessModeOf:osName. |
615 | 1558 |
aCollection do:[:accessSymbol | |
1559 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
|
1560 |
]. |
|
2922 | 1561 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1562 |
^ self accessDeniedError:self |
1563 |
]. |
|
1564 |
||
1565 |
" |
|
1566 |
'foo' asFilename writeStream close. |
|
1567 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
1568 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
1569 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
1570 |
" |
|
1571 |
! |
|
1572 |
||
1573 |
renameTo:newName |
|
671 | 1574 |
"rename the file - the argument must be convertable to a String. |
1575 |
Raise an error if not successful." |
|
615 | 1576 |
|
2922 | 1577 |
(OperatingSystem |
1578 |
renameFile:(self osNameForFile) |
|
1579 |
to:(newName asFilename osNameForFile) |
|
1580 |
) ifFalse:[ |
|
615 | 1581 |
self exists ifFalse:[ |
1582 |
^ self fileNotFoundError:self |
|
1583 |
]. |
|
1584 |
^ self accessDeniedError:newName asFilename. |
|
1585 |
]. |
|
1586 |
||
1587 |
" |
|
1588 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1589 |
" |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1590 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1591 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1592 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1593 |
"change the files size. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1594 |
This may not be supported on all operating systems" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1595 |
|
2922 | 1596 |
(OperatingSystem truncateFile:(self osNameForFile) to:newSize) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1597 |
^ self reportError:'unsupported operation' with:self |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1598 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1599 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1600 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1601 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1602 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1603 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1604 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1605 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1606 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1607 |
'test' asFilename truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1608 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1609 |
" |
615 | 1610 |
! ! |
1611 |
||
1612 |
!Filename methodsFor:'file queries'! |
|
1613 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1614 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1615 |
"return a timeStamp containing the files last access time." |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1616 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1617 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1618 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1619 |
(i := self info) isNil ifTrue:[^ nil]. |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1620 |
^ i accessed |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1621 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1622 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1623 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1624 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1625 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1626 |
"Created: / 9.7.1996 / 10:19:15 / cg" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1627 |
"Modified: / 26.9.1997 / 13:05:51 / stefan" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1628 |
"Modified: / 17.8.1998 / 10:23:44 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1629 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1630 |
|
615 | 1631 |
dates |
1632 |
"return the files modification and access times as an object (currently a dictionary) |
|
1633 |
that responds to the at: message with arguments |
|
1634 |
#modified, #accessed or #statusChanged." |
|
1635 |
||
2922 | 1636 |
|info dates osName| |
1637 |
||
2947 | 1638 |
osName := self osNameForAccess. |
2922 | 1639 |
info := OperatingSystem infoOf:osName. |
615 | 1640 |
info isNil ifTrue:[ |
2922 | 1641 |
info := OperatingSystem linkInfoOf:osName. |
2629 | 1642 |
info isNil ifTrue:[ |
1643 |
^ nil |
|
1644 |
] |
|
615 | 1645 |
]. |
1646 |
dates := IdentityDictionary new. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1647 |
dates at:#modified put:(info modified). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1648 |
dates at:#accessed put:(info accessed). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1649 |
dates at:#statusChanged put:(info statusChanged). |
615 | 1650 |
^ dates |
1651 |
||
1652 |
" |
|
1653 |
Filename currentDirectory dates |
|
1654 |
'../regression' asFilename dates |
|
1655 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1656 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1657 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 1658 |
! |
1659 |
||
1660 |
fileSize |
|
1661 |
"return the size of the file in bytes" |
|
1662 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1663 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1664 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1665 |
(i := self info) isNil ifTrue:[^ nil]. |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1666 |
^ i size |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1667 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1668 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 1669 |
! |
1670 |
||
1671 |
fileType |
|
1672 |
"this returns a string describing the type of contents of |
|
1673 |
the file. This is done using the unix 'file' command, |
|
1674 |
(which usually is configurable by /etc/magic). |
|
3665 | 1675 |
On non-unix systems, this may simply return 'file', |
2922 | 1676 |
not knowning about the contents. |
1677 |
Warning: |
|
1678 |
Since the returned string differs among systems (and language settings), |
|
3665 | 1679 |
it is only useful for user-information; |
1680 |
NOT as a tag to be used by a program." |
|
1681 |
||
1682 |
|type buffer s n suffix idx baseNm| |
|
1683 |
||
1684 |
"/ since we cannot depend on a 'file' command being available, |
|
1685 |
"/ do the most obvious ones here. |
|
1686 |
"/ (also useful since the 'file' command takes some time, and the code |
|
1687 |
"/ below is faster for common things like directories) |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1688 |
|
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1689 |
self isSymbolicLink ifTrue:[ |
2906 | 1690 |
^ 'symbolic link to ' , (self linkInfo path) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1691 |
]. |
2573 | 1692 |
self isDirectory ifTrue:[ |
2906 | 1693 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
1694 |
self isExecutable ifFalse:[^ 'directory, locked']. |
|
1695 |
^ 'directory' |
|
2573 | 1696 |
]. |
3665 | 1697 |
(type := self type) == #characterSpecial ifTrue:[ |
1698 |
^ 'character device special file' |
|
1699 |
]. |
|
1700 |
type == #blockSpecial ifTrue:[ |
|
1701 |
^ 'block device special file' |
|
1702 |
]. |
|
1703 |
type == #socket ifTrue:[ |
|
1704 |
^ 'socket' |
|
1705 |
]. |
|
1706 |
||
1602 | 1707 |
self isReadable ifFalse:[^ 'unreadable']. |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1708 |
self fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 1709 |
|
2922 | 1710 |
suffix := self suffix asLowercase. |
1711 |
baseNm := self withoutSuffix baseName asLowercase. |
|
1712 |
||
1713 |
((#('st' 'rc' 'chg' 'htm' 'html' 'ps') includes:suffix) |
|
1714 |
or:[#('makefile') includes:baseNm]) ifTrue:[ |
|
1715 |
||
1716 |
buffer := String new:2024. |
|
1717 |
s := self readStream. |
|
1718 |
s notNil ifTrue:[ |
|
1719 |
n := s nextBytes:buffer size into:buffer. |
|
1720 |
s close. |
|
1721 |
||
1722 |
(suffix = 'st') ifTrue:[ |
|
2906 | 1723 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
1724 |
^ 'smalltalk source' |
|
1725 |
]. |
|
1726 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1727 |
^ 'smalltalk source' |
|
1728 |
]. |
|
1729 |
]. |
|
1730 |
||
1731 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1732 |
^ 'smalltalk changes / method source' |
|
1733 |
]. |
|
1734 |
||
1735 |
(suffix = 'rc') ifTrue:[ |
|
1736 |
(buffer findString:'ST/X startup') ~~ 0 ifTrue:[ |
|
1737 |
^ 'smalltalk startup script' |
|
1738 |
]. |
|
1739 |
]. |
|
2922 | 1740 |
|
2906 | 1741 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
1742 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
|
1743 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
|
1744 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
|
1745 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
|
1746 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
|
1747 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
|
1748 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
|
1749 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
|
1750 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
|
1751 |
ifTrue:[ |
|
1752 |
^ 'HTML document text' |
|
1753 |
] |
|
1754 |
]. |
|
1755 |
]. |
|
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1756 |
|
2906 | 1757 |
(suffix = 'ps') ifTrue:[ |
1758 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
|
1759 |
^ 'PostScript document' |
|
1760 |
]. |
|
1761 |
]. |
|
1762 |
||
1763 |
(baseNm = 'makefile') ifTrue:[ |
|
1764 |
(buffer startsWith:'#') ifTrue:[ |
|
1765 |
^ 'make rules' |
|
1766 |
] |
|
3665 | 1767 |
] |
2906 | 1768 |
] |
1602 | 1769 |
]. |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1770 |
|
2906 | 1771 |
^ 'file' |
615 | 1772 |
|
1773 |
" |
|
1774 |
'Makefile' asFilename fileType |
|
1775 |
'.' asFilename fileType |
|
3665 | 1776 |
'/dev/null' asFilename fileType |
1777 |
'/tmp/.X11-unix/X0' asFilename fileType |
|
615 | 1778 |
'smalltalk.rc' asFilename fileType |
1779 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
1780 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1781 |
|
3665 | 1782 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 1783 |
! |
1784 |
||
2836 | 1785 |
id |
1786 |
"return the files/directories file-id (inode number)" |
|
1787 |
||
2947 | 1788 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 1789 |
|
1790 |
" |
|
1791 |
Filename currentDirectory id |
|
1792 |
" |
|
1793 |
||
1794 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
1795 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
1796 |
! |
|
1797 |
||
615 | 1798 |
info |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1799 |
"return some object filled with the files info; |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1800 |
the info (for which corresponding access methods are understood by |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1801 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1802 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1803 |
type - a symbol giving the files fileType |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1804 |
mode - numeric access mode |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1805 |
uid - owners user id |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1806 |
gid - owners group id |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1807 |
size - files size |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1808 |
id - files number (i.e. inode number) |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1809 |
accessed - last access time (as osTime-stamp) |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1810 |
modified - last modification time (as osTime-stamp) |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1811 |
statusChanged - last staus change (as osTime-stamp) |
615 | 1812 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1813 |
Some of the fields may be returned as nil on systems which do not provide |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1814 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1815 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1816 |
modified |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1817 |
size |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1818 |
type |
615 | 1819 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1820 |
Dont expect things like uid/gid/mode to be non-nil; write your application |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1821 |
to either handle nil values, |
615 | 1822 |
or (better) use one of isXXXX query methods. (Be prepared for DOS ...) |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1823 |
(i.e. instead of: |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1824 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1825 |
use |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1826 |
someFilename isDirectory |
615 | 1827 |
" |
1828 |
||
2947 | 1829 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 1830 |
|
1831 |
" |
|
1832 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1833 |
'/dev/null' asFilename info |
615 | 1834 |
'Make.proto' asFilename info |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1835 |
'source/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1836 |
'source/Point.st' asFilename linkInfo |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1837 |
'../../libbasic/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1838 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1839 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1840 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1841 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1842 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1843 |
'c:\' asFilename info |
615 | 1844 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1845 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
1846 |
"Modified: / 17.8.1998 / 10:24:10 / cg" |
615 | 1847 |
! |
1848 |
||
1849 |
linkInfo |
|
1850 |
"return the files info if its a symbolic link; nil otherwise. |
|
1851 |
On OS's which do not support symbolic links, nil is always returned. |
|
1852 |
The information is the same as returned by #info, except that if the |
|
1853 |
receiver represents a symbolic link, the links information |
|
1854 |
is returned |
|
1855 |
(while in this case, #info returns the info of the target file, |
|
1856 |
which is accessed via the symbolic link). |
|
1857 |
||
1858 |
In addition to the normal entries, Unix returns an additional entry: |
|
2629 | 1859 |
path -> the target files pathname |
615 | 1860 |
|
1861 |
See the comment in #info for more details." |
|
1862 |
||
2947 | 1863 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 1864 |
|
1865 |
" |
|
1866 |
Filename currentDirectory linkInfo |
|
1867 |
'/dev/null' asFilename linkInfo |
|
1868 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1869 |
'Make.proto' asFilename linkInfo path |
615 | 1870 |
'source/Point.st' asFilename linkInfo |
1871 |
'../../libbasic/Point.st' asFilename linkInfo |
|
1872 |
" |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1873 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1874 |
"Modified: 1.11.1996 / 20:49:09 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1875 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1876 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1877 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1878 |
"return a timeStamp containing the files modification time." |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1879 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1880 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1881 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1882 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1883 |
^ i modified |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1884 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1885 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1886 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1887 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1888 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1889 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1890 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1891 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 1892 |
! |
1893 |
||
1894 |
type |
|
1895 |
"return the symbolic type of the file" |
|
1896 |
||
2947 | 1897 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 1898 |
|
1899 |
" |
|
1900 |
Filename currentDirectory type |
|
1901 |
" |
|
1902 |
||
1903 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
1904 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 1905 |
! ! |
1906 |
||
1907 |
!Filename methodsFor:'file utilities'! |
|
1908 |
||
1909 |
edit |
|
1910 |
"start an editView on the file represented by the receiver" |
|
1911 |
||
1912 |
EditTextView openOn:self asString |
|
1913 |
||
1914 |
" |
|
1915 |
'smalltalk.rc' asFilename edit |
|
1916 |
" |
|
1917 |
! |
|
1918 |
||
1919 |
fileIn |
|
1920 |
"load smalltalk code from the file" |
|
1921 |
||
1922 |
^ self readStream fileIn |
|
542 | 1923 |
! ! |
1924 |
||
2 | 1925 |
!Filename methodsFor:'instance creation'! |
1926 |
||
615 | 1927 |
construct:subname |
1928 |
"taking the receiver as a directory name, construct a new |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1929 |
filename for an entry within this directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1930 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 1931 |
The argument may not specify an absolute path name. |
1932 |
Please do not use this to create filenames with suffixes, |
|
1933 |
since some systems require special naming conventions. |
|
1934 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 1935 |
|
2903 | 1936 |
^ self class named:(self constructString:subname) |
615 | 1937 |
|
1938 |
" |
|
1939 |
'/tmp' asFilename construct:'foo' |
|
1940 |
'/' asFilename construct:'foo' |
|
1941 |
'/usr/tmp' asFilename construct:'foo' |
|
1942 |
'/foo/bar' asFilename construct:'baz' |
|
2922 | 1943 |
|
1944 |
Bad example; works on UNIX, but may not on others: |
|
1945 |
'foo/bar.baz' construct:'.suff' |
|
615 | 1946 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1947 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1948 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 1949 |
! |
1950 |
||
2922 | 1951 |
constructDirectory:subname |
1952 |
"same as #construct: on most systems. |
|
1953 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
1954 |
||
1955 |
^ self class named:(self constructDirectoryString:subname) |
|
1956 |
! |
|
1957 |
||
1958 |
constructDirectoryString:subName |
|
1959 |
"same as #constructString: on most systems. |
|
1960 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
1961 |
||
1962 |
^ self constructString:subName |
|
1963 |
! |
|
1964 |
||
1965 |
constructString:subName |
|
2911 | 1966 |
"taking the receiver as a directory name, construct a new |
1967 |
filename-string for an entry within this directory |
|
2922 | 1968 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 1969 |
The argument may not specify an absolute path name. |
1970 |
The code below works for UNIX & MSDOS; |
|
1971 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
1972 |
||
1973 |
|sepString sub| |
|
1974 |
||
1975 |
sub := subName asString. |
|
2911 | 1976 |
sepString := self class separator asString. |
1977 |
nameString = sepString ifTrue:[ |
|
1978 |
"I am the root" |
|
2960 | 1979 |
^ sepString , sub |
2911 | 1980 |
]. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1981 |
(nameString endsWith:sepString) ifTrue:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1982 |
^ nameString , sub |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1983 |
]. |
2960 | 1984 |
^ nameString , sepString , sub |
2911 | 1985 |
|
1986 |
" |
|
1987 |
'/tmp' asFilename constructString:'foo' |
|
1988 |
'/' asFilename constructString:'foo' |
|
1989 |
'/usr/tmp' asFilename constructString:'foo' |
|
1990 |
'/foo/bar' asFilename constructString:'baz' |
|
1991 |
" |
|
1992 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1993 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1994 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1995 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1996 |
"Modified: / 27.7.1998 / 19:47:51 / cg" |
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1997 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1998 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1999 |
filenameFor:fileName |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2000 |
"taking the receiver as a directory name, construct a new |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2001 |
filename for an entry within this directory |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2002 |
(i.e. for a file or a subdirectory in that directory). |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2003 |
If the argument specifies an absolute path name, the argument is returned." |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2004 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2005 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2006 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2007 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2008 |
f isAbsolute ifTrue:[^ f]. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2009 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2010 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2011 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2012 |
'/tmp' asFilename filenameFor:'foo' |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2013 |
'/tmp' asFilename filenameFor:'/foo' |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2014 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2015 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2016 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
2 | 2017 |
! ! |
2018 |
||
195 | 2019 |
!Filename methodsFor:'misc'! |
2020 |
||
2021 |
, aString |
|
2022 |
"this allows filenames to understand how names are concatenated. |
|
308 | 2023 |
Returns a string consisting of the receivers name, concatenated |
195 | 2024 |
by aString. Notice this is NOT the same as construct:, which inserts |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2025 |
a directory delimiter and returns a new fileName instance. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2026 |
See also: #withSuffix: which is new and better." |
195 | 2027 |
|
2906 | 2028 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 2029 |
^ (nameString , aString asString) |
195 | 2030 |
|
2031 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2032 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2033 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2034 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2035 |
'Makefile' asFilename construct:'.bak' |
195 | 2036 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2037 |
|
2906 | 2038 |
"Modified: 7.9.1997 / 23:45:36 / cg" |
195 | 2039 |
! ! |
2040 |
||
615 | 2041 |
!Filename methodsFor:'printing & storing'! |
174 | 2042 |
|
615 | 2043 |
printOn:aStream |
2044 |
"append a printed representation of the receiver to aStream." |
|
174 | 2045 |
|
2906 | 2046 |
aStream nextPutAll:(self class name). |
2047 |
aStream nextPutAll:'('''. |
|
615 | 2048 |
nameString printOn:aStream. |
2049 |
aStream nextPutAll:''')' |
|
2906 | 2050 |
|
2051 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 2052 |
! |
2053 |
||
615 | 2054 |
storeOn:aStream |
2055 |
"append a printed representation of the receiver to aStream, |
|
2056 |
which allows reconstructing it via readFrom:" |
|
328 | 2057 |
|
615 | 2058 |
aStream nextPut:$(. |
2059 |
nameString storeOn:aStream. |
|
2060 |
aStream nextPutAll:' asFilename)' |
|
1 | 2061 |
! ! |
2062 |
||
202 | 2063 |
!Filename methodsFor:'private accessing'! |
1 | 2064 |
|
68 | 2065 |
setName:aString |
38 | 2066 |
"set the filename" |
2067 |
||
3666 | 2068 |
nameString := self nameWithSpecialExpansions:aString. |
2069 |
||
2070 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 2071 |
! ! |
2072 |
||
2 | 2073 |
!Filename methodsFor:'queries'! |
2074 |
||
615 | 2075 |
canBeWritten |
2076 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 2077 |
|
615 | 2078 |
^ self isWritable |
92 | 2079 |
|
328 | 2080 |
" |
615 | 2081 |
'/foo/bar' asFilename canBeWritten |
2082 |
'/tmp' asFilename canBeWritten |
|
2083 |
'Makefile' asFilename canBeWritten |
|
328 | 2084 |
" |
2085 |
! |
|
2086 |
||
68 | 2087 |
exists |
92 | 2088 |
"return true, if such a file exists." |
68 | 2089 |
|
2947 | 2090 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 2091 |
|
85 | 2092 |
" |
92 | 2093 |
'/foo/bar' asFilename exists |
2094 |
'/tmp' asFilename exists |
|
2095 |
'Makefile' asFilename exists |
|
85 | 2096 |
" |
77 | 2097 |
! |
2098 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2099 |
filesMatching:aPattern |
2550 | 2100 |
"given the receiver, representing a directory; |
2101 |
return a collection of files matching a pattern. |
|
2102 |
The pattern may be a simple matchPattern, or a set of |
|
2103 |
multiple patterns separated by semicolons." |
|
2104 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2105 |
|matchers notCaseSensitive| |
2550 | 2106 |
|
2107 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2108 |
notCaseSensitive := self class isCaseSensitive not. |
2550 | 2109 |
^ self directoryContents |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2110 |
select:[:name | |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2111 |
(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0 |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2112 |
] |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2113 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2114 |
" |
2550 | 2115 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2116 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2117 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2118 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2119 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 2120 |
! |
2121 |
||
2122 |
filesMatchingWithoutDotDirs:aPattern |
|
2123 |
"given the receiver, representing a directory; |
|
2124 |
return a collection of files matching a pattern. |
|
2125 |
Exclude '.' and '..' from the returned list. |
|
2126 |
The pattern may be a simple matchPattern, or a set of |
|
2127 |
multiple patterns separated by semicolons." |
|
2128 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2129 |
|matchers notCaseSensitive| |
2550 | 2130 |
|
2131 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2132 |
notCaseSensitive := self class isCaseSensitive not. |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2133 |
|
2550 | 2134 |
^ self directoryContents |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2135 |
select:[:name | |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2136 |
name ~= '.' |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2137 |
and:[name ~= '..' |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2138 |
and:[(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0]] |
2550 | 2139 |
] |
2140 |
||
2141 |
" |
|
2142 |
Filename currentDirectory filesMatching:'M*' |
|
2143 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
2144 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
2145 |
" |
|
2146 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2147 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2148 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2149 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2150 |
|
615 | 2151 |
isAbsolute |
2152 |
"return true, if the receiver represents an absolute pathname |
|
2153 |
(in contrast to one relative to the current directory)." |
|
356 | 2154 |
|
2629 | 2155 |
(nameString startsWith:self class separator) ifTrue:[^ true]. |
2156 |
^ self isVolumeAbsolute |
|
328 | 2157 |
|
2158 |
" |
|
615 | 2159 |
'/foo/bar' asFilename isAbsolute |
2160 |
'..' asFilename isAbsolute |
|
2161 |
'..' asAbsoluteFilename isAbsolute |
|
2162 |
'source/SBrowser.st' asFilename isAbsolute |
|
2163 |
" |
|
2164 |
! |
|
2165 |
||
2166 |
isDirectory |
|
2167 |
"return true, if the receiver represents an existing, |
|
2168 |
readable directories pathname." |
|
2169 |
||
2947 | 2170 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
615 | 2171 |
|
2172 |
" |
|
2173 |
'/foo/bar' asFilename isDirectory |
|
2174 |
'/tmp' asFilename isDirectory |
|
2175 |
'Makefile' asFilename isDirectory |
|
3843 | 2176 |
'c:\' asFilename isDirectory |
2177 |
'd:\' asFilename isDirectory |
|
615 | 2178 |
" |
3843 | 2179 |
|
2180 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
615 | 2181 |
! |
2182 |
||
2183 |
isExecutable |
|
2184 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
2185 |
For directories, true is returned if the directory can be entered. |
|
2186 |
See isExecutableProgram for a related check." |
|
2187 |
||
2947 | 2188 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 2189 |
|
2190 |
" |
|
2191 |
'/foo/bar' asFilename isExecutable |
|
2192 |
'/tmp' asFilename isExecutable |
|
2193 |
'Makefile' asFilename isExecutable |
|
2194 |
'/bin/ls' asFilename isExecutable |
|
356 | 2195 |
" |
2196 |
! |
|
2197 |
||
615 | 2198 |
isExecutableProgram |
2199 |
"return true, if such a file exists and is an executable program. |
|
2200 |
(i.e. for directories, false is returned.)" |
|
356 | 2201 |
|
2922 | 2202 |
|osName| |
2203 |
||
2947 | 2204 |
osName := self osNameForAccess. |
2922 | 2205 |
^ (OperatingSystem isExecutable:osName) |
2206 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 2207 |
|
2208 |
" |
|
615 | 2209 |
'/tmp' asFilename isExecutable |
2210 |
'/bin/ls' asFilename isExecutable |
|
2211 |
'/tmp' asFilename isExecutableProgram |
|
2212 |
'/bin/ls' asFilename isExecutableProgram |
|
2213 |
" |
|
2214 |
! |
|
2215 |
||
2922 | 2216 |
isExplicitRelative |
2217 |
"return true, if this name is an explicit relative name |
|
2218 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
2219 |
||
2220 |
^ false |
|
2221 |
! |
|
2222 |
||
2223 |
isHidden |
|
2224 |
"return true, if the receiver represents a hidden file. |
|
2225 |
The definitions of hidden files depends on the OS used; |
|
2226 |
on UNIX, a name starting with a period is considered hidden; |
|
2227 |
on MSDOS, the files hidden attribute is used. |
|
2228 |
VMS has no concept of hidden files." |
|
2229 |
||
2230 |
^ false |
|
2231 |
! |
|
2232 |
||
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2233 |
isImplicit |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2234 |
"return true, if the receiver represents a builtin file. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2235 |
The definitions of builtin files depends on the OS used; |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2236 |
on UNIX, '.' and '..' are builtin names." |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2237 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2238 |
^ false |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2239 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2240 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2241 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2242 |
|
615 | 2243 |
isReadable |
2244 |
"return true, if such a file exists and is readable." |
|
2245 |
||
2947 | 2246 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 2247 |
|
2248 |
" |
|
2249 |
'/foo/bar' asFilename isReadable |
|
2250 |
'/tmp' asFilename isReadable |
|
2251 |
'Makefile' asFilename isReadable |
|
328 | 2252 |
" |
2253 |
! |
|
2254 |
||
615 | 2255 |
isRelative |
2256 |
"return true, if this name is interpreted relative to some |
|
2257 |
directory (opposite of absolute)" |
|
328 | 2258 |
|
615 | 2259 |
^ self isAbsolute not |
2175 | 2260 |
|
2261 |
" |
|
2262 |
'./foo/bar' asFilename isRelative |
|
2263 |
'../../foo/bar' asFilename isRelative |
|
2264 |
'/foo/bar' asFilename isRelative |
|
2265 |
'bar' asFilename isRelative |
|
2266 |
" |
|
2267 |
||
2268 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
615 | 2269 |
! |
328 | 2270 |
|
3045 | 2271 |
isRootDirectory |
3046 | 2272 |
"return true, if I represent the root directory |
2273 |
(i.e. I have no parentDir)" |
|
2274 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2275 |
"/ mhmh - should we use: |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2276 |
"/ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2277 |
"/ parentDir := self construct:'..'. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2278 |
"/ (parentDir exists |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2279 |
"/ and:[parentDir isDirectory |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2280 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2281 |
"/ ^ false |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2282 |
"/ ]. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2283 |
"/ ^ true |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2284 |
"/ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2285 |
|
3046 | 2286 |
^ self pathName = Filename rootDirectory pathName |
2287 |
||
2288 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
3045 | 2289 |
! |
2290 |
||
615 | 2291 |
isSymbolicLink |
2292 |
"return true, if the file represented by the receiver is a symbolic |
|
2293 |
link. Notice that not all OS's support symbolic links; those that do |
|
2294 |
not will always return false." |
|
2295 |
||
2947 | 2296 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
328 | 2297 |
|
2298 |
" |
|
615 | 2299 |
'Make.proto' asFilename isSymbolicLink |
2300 |
'Makefile' asFilename isSymbolicLink |
|
2301 |
" |
|
2302 |
! |
|
2303 |
||
2629 | 2304 |
isVolumeAbsolute |
2305 |
"return true, if the receiver represents an absolute pathname |
|
2306 |
on some disk volume (MSDOS only)" |
|
2307 |
||
2308 |
^ false |
|
2906 | 2309 |
|
2310 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
2629 | 2311 |
! |
2312 |
||
615 | 2313 |
isWritable |
2314 |
"return true, if such a file exists and is writable." |
|
2315 |
||
2947 | 2316 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 2317 |
|
2318 |
" |
|
2319 |
'/foo/bar' asFilename isWritable |
|
2320 |
'/tmp' asFilename isWritable |
|
2321 |
'Makefile' asFilename isWritable |
|
328 | 2322 |
" |
174 | 2323 |
! |
2324 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2325 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2326 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2327 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2328 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2329 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2330 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2331 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2332 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2333 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2334 |
|
3865 | 2335 |
binaryContentsOfEntireFile |
3864 | 2336 |
"return the binary contents of the file as a byteArray; |
2337 |
or nil, if the file is unreadable." |
|
2338 |
||
2339 |
|s contents| |
|
2340 |
||
2341 |
s := self readStream. |
|
2342 |
s isNil ifTrue:[^ nil]. |
|
2343 |
s binary. |
|
2344 |
[ |
|
2345 |
contents := s contentsOfEntireFile |
|
2346 |
] valueNowOrOnUnwindDo:[s close]. |
|
2347 |
^ contents |
|
2348 |
||
3865 | 2349 |
"Created: / 3.10.1998 / 17:56:39 / cg" |
3864 | 2350 |
! |
2351 |
||
1540 | 2352 |
contents |
2353 |
"return the contents of the file as a collection of lines; |
|
2354 |
or nil, if the file is unreadable." |
|
2355 |
||
2356 |
|s contents| |
|
2357 |
||
2358 |
s := self readStream. |
|
2359 |
s isNil ifTrue:[^ nil]. |
|
2360 |
||
2361 |
[ |
|
2629 | 2362 |
contents := s contents |
1540 | 2363 |
] valueNowOrOnUnwindDo:[s close]. |
2364 |
^ contents |
|
2365 |
||
2366 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
2367 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
|
2368 |
"Created: 11.7.1996 / 14:09:11 / cg" |
|
2369 |
! |
|
2370 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2371 |
contentsOfEntireFile |
1540 | 2372 |
"return the contents of the file as a string; |
2373 |
or nil, if the file is unreadable." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2374 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2375 |
|s contents| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2376 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2377 |
s := self readStream. |
1535 | 2378 |
s isNil ifTrue:[^ nil]. |
2379 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2380 |
[ |
2629 | 2381 |
contents := s contentsOfEntireFile |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2382 |
] valueNowOrOnUnwindDo:[s close]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2383 |
^ contents |
1523 | 2384 |
|
2385 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1540 | 2386 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2387 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2388 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2389 |
directoryContents |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2390 |
"return the contents of the directory as a collection of strings. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2391 |
This excludes any entries for '.' or '..'." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2392 |
|
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2393 |
|s contents| |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2394 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
3713
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2395 |
s isNil ifTrue:[^nil]. |
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2396 |
|
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2397 |
contents := s contents. |
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2398 |
s close. |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2399 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2400 |
contents remove:'.' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2401 |
contents remove:'..' ifAbsent:nil. |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2402 |
^ contents. |
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2403 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2404 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2405 |
'.' asFilename directoryContents |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2406 |
'/XXXdoesNotExist' asFilename directoryContents |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2407 |
" |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2408 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2409 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2410 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
2960 | 2411 |
! |
2412 |
||
2413 |
fullDirectoryContents |
|
2414 |
"return the full contents of the directory as a collection of strings. |
|
2415 |
This is much like #directoryContents, but includes an entry for the |
|
2416 |
parent directory, if there is one." |
|
2417 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2418 |
|files| |
2960 | 2419 |
|
2420 |
files := self directoryContents. |
|
3302 | 2421 |
files isNil ifTrue:[ |
2422 |
"/ mhmh - that one does not exist |
|
2423 |
^ files |
|
2424 |
]. |
|
2960 | 2425 |
|
3843 | 2426 |
"/ add/remove parentDirectory if there is one/none |
2960 | 2427 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2428 |
files remove:'.' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2429 |
self isRootDirectory ifTrue:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2430 |
files remove:'..' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2431 |
] ifFalse:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2432 |
(files includes:'..') ifFalse:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2433 |
files addFirst:'..'. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2434 |
] |
2960 | 2435 |
]. |
2436 |
^ files |
|
3046 | 2437 |
|
2438 |
" |
|
2439 |
'.' asFilename fullDirectoryContents |
|
2440 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
3843 | 2441 |
'd:\FET' asFilename fullDirectoryContents |
3046 | 2442 |
" |
2443 |
||
3843 | 2444 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2445 |
! |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2446 |
|
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2447 |
recursiveDirectoryContents |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2448 |
"return the contents of the directory and all subdirectories |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2449 |
as a collection of strings. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2450 |
This excludes any entries for '.' or '..'. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2451 |
Subdirectory files are included with a relative pathname. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2452 |
Warning: this may take a long time to execute." |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2453 |
|
3868 | 2454 |
|fileNames dirNames| |
2455 |
||
2456 |
fileNames := OrderedCollection new. |
|
2457 |
dirNames := OrderedCollection new. |
|
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2458 |
self directoryContents do:[:f | |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2459 |
(self construct:f) isDirectory ifTrue:[ |
3868 | 2460 |
dirNames add:f |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2461 |
] ifFalse:[ |
3868 | 2462 |
fileNames add:f |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2463 |
] |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2464 |
]. |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2465 |
|
3868 | 2466 |
dirNames do:[:dN | |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2467 |
|dd subFiles| |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2468 |
|
3868 | 2469 |
dd := dN asFilename. |
2470 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
|
2471 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
|
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2472 |
]. |
3868 | 2473 |
^ fileNames. |
3867
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2474 |
|
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2475 |
" |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2476 |
'.' asFilename recursiveDirectoryContents |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2477 |
'../../clients' asFilename recursiveDirectoryContents |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2478 |
" |
91b0773fe260
added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents:
3865
diff
changeset
|
2479 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2480 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2481 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2482 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2483 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2484 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2485 |
"return my baseName as a string. |
2012 | 2486 |
- thats the file/directory name without leading parent-dirs. |
2922 | 2487 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
2488 |
and '/usr/lib' asFilename baseName -> lib). |
|
2489 |
This method does not check if the path is valid |
|
2490 |
||
2911 | 2491 |
See also: #pathName, #directoryName and #directoryPathName. |
2492 |
Compatibility note: use #tail for ST-80 compatibility." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2493 |
|
2922 | 2494 |
|len index sep endIdx| |
2495 |
||
2496 |
sep := self separator. |
|
2497 |
len := nameString size. |
|
2498 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
2499 |
^ nameString |
|
2500 |
]. |
|
2501 |
||
2502 |
endIdx := len. |
|
2503 |
len > 1 ifTrue:[ |
|
2504 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
|
2505 |
]. |
|
2506 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
2507 |
index == 0 ifTrue:[ |
|
2508 |
^ nameString copyTo:endIdx |
|
2509 |
]. |
|
2510 |
^ nameString copyFrom:(index+1) to:endIdx |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2511 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2512 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2513 |
'/foo/bar' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2514 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2515 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2516 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2517 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2518 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2519 |
'../../libbasic/Object.st' asFilename baseName |
3851 | 2520 |
'/' asFilename baseName |
2521 |
'\' asFilename baseName |
|
2522 |
'c:\' asFilename baseName |
|
2523 |
'\\idefix' asFilename baseName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2524 |
" |
2012 | 2525 |
|
3851 | 2526 |
"Modified: / 24.9.1998 / 13:06:23 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2527 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2528 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2529 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2530 |
"return the directory name part of the file/directory as a new filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2531 |
- thats a filename for the directory where the file/dir represented by |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2532 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2533 |
(this is almost equivalent to #directoryName or #head, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2534 |
a Filename instance instead of a string )." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2535 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2536 |
^ self directoryName asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2537 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2538 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2539 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2540 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2541 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2542 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2543 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2544 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2545 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2546 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2547 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2548 |
"Modified: 29.2.1996 / 20:50:14 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2549 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2550 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2551 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2552 |
"return the directory name part of the file/directory as a string. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2553 |
- thats the name of the directory where the file/dir represented by |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2554 |
the receiver is contained in. |
2922 | 2555 |
This method does not check if the path is valid. |
2556 |
||
2557 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
2558 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
2559 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2560 |
(this is almost equivalent to #directory, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2561 |
a string instead of a Filename instance). |
2922 | 2562 |
|
2012 | 2563 |
See also: #pathName, #directoryPathName and #baseName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2564 |
Compatibility note: use #head for ST-80 compatibility." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2565 |
|
2922 | 2566 |
|last index sep sepString p| |
2567 |
||
2568 |
sep := self separator. |
|
2569 |
sepString := sep asString. |
|
2570 |
(nameString = sepString) ifTrue:[ |
|
2571 |
"/ |
|
2572 |
"/ the trivial '/' case |
|
2573 |
"/ |
|
2574 |
^ nameString |
|
2575 |
]. |
|
2576 |
||
2577 |
"/ |
|
2578 |
"/ strip off multiple leading slashes |
|
2579 |
"/ |
|
2580 |
p := nameString. |
|
2581 |
[p endsWith:sepString] whileTrue:[ |
|
2582 |
(p = sepString) ifTrue:[ |
|
2583 |
^ p |
|
2584 |
]. |
|
2585 |
p := p copyWithoutLast:1 |
|
2586 |
]. |
|
2587 |
||
2588 |
last := 1. |
|
2589 |
[true] whileTrue:[ |
|
2590 |
index := p indexOf:sep startingAt:(last + 1). |
|
2591 |
index == 0 ifTrue:[ |
|
2592 |
(last == 1) ifTrue:[ |
|
2593 |
(p startsWith:sepString) ifTrue:[ |
|
2594 |
^ sepString |
|
2595 |
]. |
|
2596 |
^ '.' |
|
2597 |
]. |
|
2598 |
^ p copyTo:(last - 1) |
|
2599 |
]. |
|
2600 |
last := index. |
|
2601 |
]. |
|
2602 |
||
2603 |
"/ notreached |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2604 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2605 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2606 |
'/foo/bar/' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2607 |
'/foo/bar/' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2608 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2609 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2610 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2611 |
'bitmaps' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2612 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2613 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2614 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2615 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2616 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2617 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2618 |
"Modified: 7.9.1995 / 10:42:03 / claus" |
2012 | 2619 |
"Modified: 21.12.1996 / 15:21:48 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2620 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2621 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2622 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2623 |
"return the full directory pathname part of the file/directory as a string. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2624 |
- thats the full pathname of the directory where the file/dir represented by |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2625 |
the receiver is contained in. |
2012 | 2626 |
See also: #pathName, #directoryName, #directory and #baseName" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2627 |
|
2922 | 2628 |
^ self pathName asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2629 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2630 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2631 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2632 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2633 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2634 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2635 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2636 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2637 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2638 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2639 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2640 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2641 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2642 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2643 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2644 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2645 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 2646 |
"Modified: 21.12.1996 / 15:21:57 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2647 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2648 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2649 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2650 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2651 |
This method has both a return value and a side effect on the receiver: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2652 |
it returns a collection of matching filename objects, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2653 |
and leaves changes the receivers filename-string to the longest common |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2654 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2655 |
If none matches, the returned collection is empty and the recevier is unchanged. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2656 |
If there is only one match, the size of the returned collection is exactly 1, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2657 |
containing the fully expanded filename and the receivers name is changed to it." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2658 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2659 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2660 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2661 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2662 |
'mak' asFilename filenameCompletion |
1517 | 2663 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2664 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2665 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2666 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2667 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2668 |
|
1517 | 2669 |
"Modified: 3.7.1996 / 10:53:51 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2670 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2671 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2672 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2673 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2674 |
This method has both a return value and a side effect on the receiver: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2675 |
it returns a collection of matching filename objects, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2676 |
and leaves changes the receivers filename-string to the longest common |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2677 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2678 |
If none matches, the returned collection is empty and the recevier is unchanged. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2679 |
If there is only one match, the size of the returned collection is exactly 1, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2680 |
containing the fully expanded filename and the receivers name is changed to it." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2681 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2682 |
|dir baseName matching matchLen try allMatching |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2683 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 2684 |
|
2685 |
nm := self nameWithSpecialExpansions:nameString. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2686 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2687 |
sepString := self class separator asString. |
3666 | 2688 |
(nm endsWith:sepString) ifTrue:[ |
2906 | 2689 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2690 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2691 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2692 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2693 |
baseName := self baseName. |
3666 | 2694 |
baseName ~= nm ifTrue:[ |
2906 | 2695 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2696 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2697 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2698 |
self isAbsolute ifTrue:[ |
2906 | 2699 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2700 |
] ifFalse:[ |
2906 | 2701 |
aDirectory isNil ifTrue:[ |
2702 |
dir := self directory |
|
2703 |
] ifFalse:[ |
|
3666 | 2704 |
dir := (aDirectory construct:nm) directory |
2906 | 2705 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2706 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2707 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2708 |
caseless := self class isCaseSensitive not. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2709 |
caseless ifTrue:[ |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2710 |
lcBaseName := baseName asLowercase |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2711 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2712 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2713 |
matching := OrderedCollection new. |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2714 |
dir class errorReporter openErrorSignal handle:[:ex| |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2715 |
^ #(). |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2716 |
] do:[ |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2717 |
dir directoryContents do:[:fileName | |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2718 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2719 |
((caseless and:[fileName asLowercase startsWith:lcBaseName]) |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2720 |
or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[ |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2721 |
matching add:fileName |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2722 |
] |
2906 | 2723 |
] |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2724 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2725 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2726 |
(nMatch := matching size) > 1 ifTrue:[ |
2906 | 2727 |
" |
2728 |
find the longest common prefix |
|
2729 |
" |
|
2730 |
matchLen := baseName size. |
|
2731 |
matchLen > matching first size ifTrue:[ |
|
2732 |
try := baseName. |
|
2733 |
allMatching := false |
|
2734 |
] ifFalse:[ |
|
2735 |
try := matching first copyTo:matchLen. |
|
2736 |
allMatching := true. |
|
2737 |
]. |
|
2738 |
||
2739 |
[allMatching] whileTrue:[ |
|
2740 |
matching do:[:aName | |
|
2741 |
(aName startsWith:try) ifFalse:[ |
|
2742 |
allMatching := false |
|
2743 |
] |
|
2744 |
]. |
|
2745 |
allMatching ifTrue:[ |
|
2746 |
matchLen < matching first size ifTrue:[ |
|
2747 |
matchLen := matchLen + 1. |
|
2748 |
try := matching first copyTo:matchLen. |
|
2749 |
] ifFalse:[ |
|
2750 |
allMatching := false |
|
2751 |
] |
|
2752 |
] ifFalse:[ |
|
2753 |
try := matching first copyTo:matchLen - 1. |
|
2754 |
] |
|
2755 |
]. |
|
2756 |
" |
|
2757 |
and set my name to the last full match |
|
2758 |
" |
|
3666 | 2759 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2760 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2761 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2762 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2763 |
if I had a directory-prefix, change names in collection ... |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2764 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2765 |
prefix notNil ifTrue:[ |
2906 | 2766 |
prefix = sepString ifTrue:[ |
2767 |
"/ avoid introducing double slashes |
|
2768 |
prefix := '' |
|
2769 |
]. |
|
2770 |
matching := matching collect:[:n | prefix , sepString , n]. |
|
2771 |
nMatch == 1 ifTrue:[ |
|
3666 | 2772 |
nameString := nm := matching first |
2906 | 2773 |
] ifFalse:[ |
2774 |
nMatch > 1 ifTrue:[ |
|
3666 | 2775 |
nameString := nm := prefix , sepString , nm |
2906 | 2776 |
] |
2777 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2778 |
] ifFalse:[ |
2906 | 2779 |
nMatch == 1 ifTrue:[ |
3666 | 2780 |
nameString := nm := matching first |
2906 | 2781 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2782 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2783 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2784 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2785 |
return the match-set, so caller can decide what to do |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2786 |
(i.e. show the matches, output a warning etc ...) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2787 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2788 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2789 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2790 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2791 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2792 |
'../' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2793 |
'/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2794 |
'/usr/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2795 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2796 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2797 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2798 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2799 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2800 |
'../../libpr' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2801 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2802 |
|
3666 | 2803 |
"Modified: / 22.9.1997 / 18:03:33 / stefan" |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
2804 |
"Modified: / 20.8.1998 / 01:54:14 / cg" |
2903 | 2805 |
! |
2806 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2807 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2808 |
"return the directory name as a string. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2809 |
An alias for directoryName, for ST-80 compatiblity. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2810 |
(this is almost equivalent to #directory, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2811 |
a string instead of a Filename instance)" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2812 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2813 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2814 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2815 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2816 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2817 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2818 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2819 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2820 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2821 |
"Modified: 29.2.1996 / 20:21:25 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2822 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2823 |
|
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2824 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2825 |
"return the full pathname of the file represented by the receiver, |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2826 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2827 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2828 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2829 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2830 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2831 |
|
615 | 2832 |
name |
2833 |
"return the name of the file represented by the receiver as a string. |
|
883 | 2834 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 2835 |
See also: pathName" |
174 | 2836 |
|
615 | 2837 |
self isAbsolute ifTrue:[^ self pathName]. |
2838 |
^ nameString |
|
174 | 2839 |
|
2840 |
" |
|
615 | 2841 |
'/foo/bar' asFilename name |
2842 |
'/foo/bar' asFilename pathName |
|
2843 |
'.' asFilename name |
|
2844 |
'.' asFilename pathName |
|
2845 |
'../..' asFilename name |
|
883 | 2846 |
'../..' asFilename pathName |
615 | 2847 |
'bitmaps' asFilename name |
2848 |
'bitmaps' asFilename pathName |
|
2849 |
'/tmp/../usr' asFilename name |
|
883 | 2850 |
'/tmp/../usr' asFilename pathName |
2851 |
'source/..' asFilename name |
|
2852 |
'source/..' asFilename pathName |
|
2853 |
'/tmp/..' asFilename name |
|
2854 |
'/tmp/..' asFilename pathName |
|
92 | 2855 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2856 |
|
883 | 2857 |
"Modified: 18.1.1996 / 21:36:27 / cg" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2858 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2859 |
|
615 | 2860 |
pathName |
2861 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 2862 |
as a string. This will not include ..'s. |
2863 |
If the path represented by the receiver does NOT represent a valid path, |
|
2864 |
no compression will be done (for now; this may change). |
|
2865 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2866 |
|
1317 | 2867 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2868 |
|
1317 | 2869 |
"/ sep := self class separator. |
2870 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
2871 |
"/ parentName := self class parentDirectoryName. |
|
2872 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
2873 |
"/ ^ nameString |
|
2874 |
"/ ] |
|
2875 |
"/ ]. |
|
2876 |
p := OperatingSystem pathNameOf:nameString. |
|
2877 |
^ p |
|
2 | 2878 |
|
92 | 2879 |
" |
1317 | 2880 |
'/foo/bar' asFilename pathName |
2881 |
'.' asFilename pathName |
|
2882 |
'../..' asFilename pathName |
|
2883 |
'../..' asFilename name |
|
2884 |
'/tmp/../usr' asFilename pathName |
|
2885 |
'/././usr' asFilename pathName |
|
92 | 2886 |
" |
159 | 2887 |
|
1317 | 2888 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 2889 |
! |
2890 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2891 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2892 |
"return the full pathname of the physical file represented by the receiver, |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2893 |
If the receiver represents a symbolic link, thats the fileName of the |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2894 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2895 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2896 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2897 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2898 |
|t target path| |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2899 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2900 |
self isSymbolicLink ifFalse:[ |
2629 | 2901 |
self exists ifFalse:[^ nil]. |
2902 |
^ self pathName |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2903 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2904 |
t := self. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2905 |
[t isSymbolicLink] whileTrue:[ |
2629 | 2906 |
path := t linkInfo path. |
2907 |
path isNil ifTrue:[ |
|
2908 |
"/ cannot happen |
|
2909 |
^ nil |
|
2910 |
]. |
|
2911 |
target := t directoryName asFilename construct:path. |
|
2912 |
target exists ifFalse:[^ nil]. |
|
2913 |
t := target asFilename |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2914 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2915 |
t exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2916 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2917 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2918 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2919 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2920 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2921 |
'../..' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2922 |
'include/abbrev.stc' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2923 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2924 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2925 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2926 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2927 |
|
615 | 2928 |
tail |
2929 |
"the files name without directory prefix as a string. |
|
2930 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 2931 |
|
615 | 2932 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2933 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2934 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2935 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2936 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2937 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2938 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2939 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2940 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 2941 |
! |
2942 |
||
2943 |
volume |
|
2944 |
"return the disc volume part of the name or an empty string. |
|
2906 | 2945 |
This is only used with MSDOS and VMS filenames |
2946 |
- by default (and on unix), an empty string is returned" |
|
2947 |
||
2629 | 2948 |
^ '' |
2906 | 2949 |
|
2950 |
"Modified: 8.9.1997 / 00:37:33 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2951 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2952 |
|
2922 | 2953 |
!Filename methodsFor:'special accessing'! |
2954 |
||
3665 | 2955 |
nameWithSpecialExpansions:aString |
2956 |
"return the nameString, expanding any OS specific |
|
2957 |
macros. This should be redefined for OS's where such macros |
|
2958 |
are common. |
|
2959 |
On unix, a ~/ prefix is expanded to the users home dir (as in csh)" |
|
2960 |
||
2961 |
^ aString |
|
2962 |
||
2963 |
"Modified: / 21.7.1998 / 10:43:20 / cg" |
|
2964 |
"Created: / 21.7.1998 / 10:45:58 / cg" |
|
2965 |
! |
|
2966 |
||
2922 | 2967 |
osName |
2968 |
"special - return the OS's name for the receiver." |
|
2969 |
||
2970 |
self isDirectory ifTrue:[ |
|
2971 |
^ self osNameForDirectory |
|
2972 |
]. |
|
2973 |
^ self osNameForFile |
|
2974 |
! |
|
2975 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2976 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2977 |
"internal - return the OS's name for the receiver to |
3665 | 2978 |
access its fileInfo. |
2979 |
This may be redefined for systems, where a special suffix must be |
|
2980 |
added in order to access directories (or others) as a file. |
|
2981 |
(i.e. under VMS, a '.dir' suffix is added to access directories)" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2982 |
|
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2983 |
^ nameString |
3665 | 2984 |
|
2985 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2986 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2987 |
|
2922 | 2988 |
osNameForDirectory |
3753 | 2989 |
"internal - return the OS's name for the receiver to |
2922 | 2990 |
access it as a directory." |
2991 |
||
2992 |
^ nameString |
|
3753 | 2993 |
|
2994 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 2995 |
! |
2996 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2997 |
osNameForDirectoryContents |
3753 | 2998 |
"internal - return the OS's name for the receiver to |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2999 |
access it as a directory when reading its contents." |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3000 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3001 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3002 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3003 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 3004 |
"Modified: / 12.8.1998 / 14:44:34 / cg" |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3005 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
3006 |
|
2922 | 3007 |
osNameForFile |
3008 |
"internal - return the OS's name for the receiver to |
|
3009 |
access it as a file." |
|
3010 |
||
3011 |
^ nameString |
|
3012 |
! ! |
|
3013 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3014 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3015 |
|
2906 | 3016 |
hasSuffix:aSuffixString |
3017 |
"return true if my suffix is the same as aString. |
|
3018 |
This cares for systems, where case is ignored in filenames" |
|
3019 |
||
3020 |
|mySuffix| |
|
3021 |
||
3022 |
mySuffix := self suffix. |
|
3023 |
self class isCaseSensitive ifTrue:[ |
|
3024 |
^ mySuffix = aSuffixString |
|
3025 |
]. |
|
3026 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
3027 |
||
3028 |
" |
|
3029 |
'abc.st' asFilename hasSuffix:'st' |
|
3030 |
'abc.ST' asFilename hasSuffix:'st' |
|
3031 |
" |
|
3032 |
||
3033 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
3034 |
! |
|
3035 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3036 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3037 |
"return an array consisting of my prefix and suffix. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3038 |
The suffix is the namepart after the final period character, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3039 |
the prefix everything before, except for the period. |
1517 | 3040 |
The directory name part is stripped off (i.e. the returned prefix |
3041 |
will consist of the files basename only.) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3042 |
(on some systems, the suffix-character may be different from a period). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3043 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
1517 | 3044 |
See also: #withoutSuffix and #withSuffix |
3045 |
Notice: |
|
2629 | 3046 |
there is currently no known system which uses other than |
3047 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3048 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3049 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3050 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3051 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3052 |
idx := nm lastIndexOf:(self class suffixSeparator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3053 |
idx == 0 ifTrue:[ |
2629 | 3054 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3055 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3056 |
^ Array |
2629 | 3057 |
with:(nm copyTo:idx-1) |
3058 |
with:(nm copyFrom:idx+1) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3059 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3060 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3061 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3062 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3063 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 3064 |
'/foo/bar.c/baz.c' asFilename prefixAndSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3065 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3066 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3067 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 3068 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3069 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3070 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3071 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 3072 |
"Modified: 3.7.1996 / 10:53:10 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3073 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3074 |
|
2906 | 3075 |
suffix |
3076 |
"return my suffix. |
|
3077 |
The suffix is the namepart after the final period character, |
|
3078 |
or the empty string, if the name does not contain a period." |
|
3079 |
||
3080 |
^ self prefixAndSuffix at:2 |
|
3081 |
||
3082 |
" |
|
3083 |
'abc.st' asFilename suffix |
|
3084 |
'abc' asFilename suffix |
|
3085 |
'a.b.c' asFilename suffix |
|
3086 |
" |
|
3087 |
||
3088 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
3089 |
! |
|
3090 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3091 |
withSuffix:aSuffix |
2922 | 3092 |
"return a new filename for the receivers name with a different suffix. |
1993 | 3093 |
If the name already has a suffix, the new suffix replacaes it; |
3094 |
otherwise, the new suffix is simply appended to the name." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3095 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3096 |
^ self class named: |
2629 | 3097 |
(self withoutSuffix name |
3098 |
, self class suffixSeparator asString |
|
3099 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3100 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3101 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3102 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3103 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3104 |
'a.b.c' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3105 |
'/foo/bar/baz.st' asFilename withSuffix:'c' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3106 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 3107 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 3108 |
'/foo/bar.c/baz' asFilename withSuffix:'st' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3109 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3110 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3111 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1993 | 3112 |
"Modified: 11.12.1996 / 16:01:02 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3113 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3114 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3115 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3116 |
"return a new filename for the receivers name without the suffix. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3117 |
If the name has no suffix, the receiver is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3118 |
|
2922 | 3119 |
|nm idx| |
3120 |
||
3121 |
nm := self baseName. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3122 |
idx := nameString lastIndexOf:(self class suffixSeparator). |
2922 | 3123 |
(idx == 0) ifTrue:[^ self]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3124 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3125 |
^ self class named:(nameString copyTo:(idx - 1)) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3126 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3127 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3128 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3129 |
'abc' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3130 |
'a.b.c' asFilename withoutSuffix |
1516 | 3131 |
'/foo/bar/baz.c' asFilename withoutSuffix |
3132 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
|
3133 |
'/foo/bar/baz/foo.c/bar.c' asFilename withoutSuffix |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3134 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3135 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3136 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1516 | 3137 |
"Modified: 3.7.1996 / 10:49:58 / cg" |
174 | 3138 |
! ! |
3139 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3140 |
!Filename class methodsFor:'documentation'! |
630 | 3141 |
|
3142 |
version |
|
3869
6d7dca488a41
read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents:
3868
diff
changeset
|
3143 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.142 1998-10-05 08:38:06 cg Exp $' |
630 | 3144 |
! ! |
2906 | 3145 |
Filename initialize! |