author | Claus Gittinger <cg@exept.de> |
Fri, 14 Aug 1998 18:19:03 +0200 | |
changeset 3763 | 31d58d04ac15 |
parent 3753 | 20eb9177749b |
child 3768 | 4801b87c1cd7 |
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 |
||
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
526 |
tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
527 |
"return the temp directory as a filename. |
1968 | 528 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
529 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
530 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
531 |
|
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
532 |
Notice: do not hardcode '/tmp' into your programs - things may be |
2906 | 533 |
different on other OS's. Also, the user may want to set the |
534 |
TMPDIR environment variable to have her temp files somewhere else. |
|
535 |
(especially on SUNOS, the root partition is ALWAYS too small ..." |
|
1080 | 536 |
|
537 |
|tempDir| |
|
538 |
||
1969 | 539 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
2906 | 540 |
tempDir isNil ifTrue:[ |
541 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
542 |
]. |
|
1968 | 543 |
]. |
1080 | 544 |
tempDir isNil ifTrue:[ |
2906 | 545 |
tempDir := self defaultTempDirectoryName |
1080 | 546 |
]. |
547 |
^ self named:tempDir |
|
548 |
||
549 |
" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
550 |
Filename tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
551 |
Filename tempDirectory pathName |
1080 | 552 |
" |
553 |
||
554 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
555 |
"Created: 7.3.1996 / 14:51:18 / cg" |
2906 | 556 |
"Modified: 8.9.1997 / 00:08:11 / cg" |
1 | 557 |
! ! |
558 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
559 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
560 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
561 |
concreteClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
562 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
563 |
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
|
564 |
OperatingSystems; concreteClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
565 |
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
|
566 |
|
2906 | 567 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
568 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
569 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 570 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
571 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
572 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
573 |
defaultClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
574 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
575 |
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
|
576 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
577 |
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
|
578 |
|
2906 | 579 |
^ ConcreteClass |
580 |
||
581 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
582 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
583 |
|
2922 | 584 |
!Filename class methodsFor:'misc'! |
585 |
||
586 |
canonicalize:aPathString |
|
3077 | 587 |
"convert the argument, aPathString to a good format. |
588 |
This should eliminate useless directory components (i.e. '././') |
|
589 |
and useless tree walks (i.e. '../foo/..')." |
|
590 |
||
2922 | 591 |
^ aPathString |
592 |
||
3077 | 593 |
"Created: / 13.9.1997 / 10:50:01 / cg" |
594 |
"Modified: / 1.11.1997 / 12:44:57 / cg" |
|
595 |
! |
|
596 |
||
597 |
filterSeps:aFilenameString |
|
598 |
"ST80 compatibility: |
|
599 |
filter out (invalid) separators in aFilenameString. |
|
600 |
We recommend using #makeLegalFilename" |
|
601 |
||
3658 | 602 |
^ aFilenameString copyReplaceAll:(Character space) with:$_. |
3077 | 603 |
|
604 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 605 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 606 |
! |
607 |
||
608 |
suggest:aFilenameString |
|
609 |
"return a fileNamestring based on the argument, |
|
610 |
which is legal on the current platform." |
|
611 |
||
612 |
^ self canonicalize:aFilenameString |
|
613 |
||
614 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 615 |
! ! |
616 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
617 |
!Filename class methodsFor:'queries'! |
2 | 618 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
619 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
620 |
"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
|
621 |
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
|
622 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
623 |
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
|
624 |
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
|
625 |
|
2503 | 626 |
|sep components| |
627 |
||
2906 | 628 |
(self ~~ ConcreteClass) ifTrue:[ |
629 |
^ ConcreteClass components:aString |
|
630 |
]. |
|
631 |
||
632 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
633 |
||
2503 | 634 |
sep := self separator. |
635 |
components := aString asCollectionOfSubstringsSeparatedBy:sep. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
636 |
components first isEmpty ifTrue:[ |
2906 | 637 |
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
|
638 |
]. |
3373 | 639 |
components last isEmpty ifTrue:[ |
640 |
^ components copyWithoutLast:1 |
|
641 |
]. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
642 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
643 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
644 |
" |
3373 | 645 |
Filename components:'/foo/bar/baz' |
646 |
Filename components:'/' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
647 |
Filename components:'foo/bar/baz' |
2503 | 648 |
Filename components:'foo/bar' |
649 |
Filename components:'foo' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
650 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
651 |
|
2906 | 652 |
"Modified: 8.9.1997 / 00:30:57 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
653 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
654 |
|
2963 | 655 |
directorySuffix |
656 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
657 |
The default is nil here, redefined for VMS" |
|
658 |
||
659 |
(self ~~ ConcreteClass) ifTrue:[ |
|
660 |
^ ConcreteClass directorySuffix |
|
661 |
]. |
|
662 |
||
663 |
^ nil |
|
664 |
! |
|
665 |
||
1523 | 666 |
errorReporter |
667 |
"who knows the signals to report errors?" |
|
668 |
||
669 |
^ FileStream |
|
670 |
||
671 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
672 |
! |
|
673 |
||
440 | 674 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
675 |
"perform filename completion on aString in some directory; |
|
676 |
return the longest matching filename prefix as a string. |
|
1318 | 677 |
The boolean directoriesOnly and filesOnly control respectively, |
678 |
if only directories or only regular files are to be considered for completion. |
|
679 |
If multiple files match, the exception block aBlock is evaluated with a |
|
680 |
filename representing the directory (where the match was done) as argument. |
|
440 | 681 |
(this may be different from the inDirectory argument, if aString is absolute |
682 |
or starts with ../)" |
|
683 |
||
684 |
|s f matchSet nMatch name words dir| |
|
685 |
||
2906 | 686 |
(self ~~ ConcreteClass) ifTrue:[ |
687 |
^ ConcreteClass |
|
688 |
filenameCompletionFor:aString |
|
689 |
directory:inDirectory |
|
690 |
directoriesOnly:directoriesOnly |
|
691 |
filesOnly:filesOnly |
|
692 |
ifMultiple:aBlock |
|
693 |
]. |
|
694 |
||
695 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
696 |
||
440 | 697 |
s := aString. |
698 |
" |
|
699 |
find the last word ... |
|
700 |
" |
|
701 |
words := s asCollectionOfWords. |
|
702 |
words size == 0 ifTrue:[ |
|
2906 | 703 |
aBlock value:'.' asFilename. |
704 |
^ '' |
|
440 | 705 |
]. |
706 |
||
707 |
f := words last asFilename. |
|
708 |
||
709 |
matchSet := f filenameCompletionIn:inDirectory. |
|
710 |
||
711 |
dir := f directory. |
|
712 |
||
713 |
directoriesOnly ifTrue:[ |
|
2906 | 714 |
matchSet := matchSet select:[:aFilename | |
715 |
(dir construct:aFilename) isDirectory |
|
716 |
]. |
|
440 | 717 |
] ifFalse:[ |
2906 | 718 |
filesOnly ifTrue:[ |
719 |
matchSet := matchSet select:[:aFilename | |
|
720 |
(dir construct:aFilename) isDirectory not |
|
721 |
]. |
|
722 |
] |
|
440 | 723 |
]. |
724 |
||
725 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
2906 | 726 |
" |
727 |
more than one possible completion - |
|
728 |
" |
|
729 |
aBlock value:f |
|
440 | 730 |
]. |
731 |
" |
|
732 |
even with more than one possible completion, |
|
733 |
f's name is now the common prefix |
|
734 |
" |
|
735 |
name := f asString. |
|
736 |
nMatch == 1 ifTrue:[ |
|
2906 | 737 |
" |
738 |
exactly one possible completion - |
|
739 |
" |
|
3752 | 740 |
"/ f := dir construct:matchSet first. |
741 |
false "directoriesOnly" ifFalse:[ |
|
2906 | 742 |
f isDirectory ifTrue:[ |
743 |
(name endsWith:(Filename separator)) ifFalse:[ |
|
3504 | 744 |
name := name , (Filename separator) |
2906 | 745 |
]. |
746 |
]. |
|
747 |
] |
|
440 | 748 |
]. |
749 |
||
750 |
" |
|
751 |
construct new contents, by taking |
|
752 |
last words completion |
|
753 |
" |
|
754 |
s := ''. |
|
755 |
1 to:(words size - 1) do:[:idx | |
|
2906 | 756 |
s := s , (words at:idx) , ' ' |
440 | 757 |
]. |
758 |
s := s , name. |
|
759 |
||
760 |
"/ special: if there was no change, and the string represented |
|
761 |
"/ 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
|
762 |
((nMatch == 1) or:[s = aString]) ifTrue:[ |
2906 | 763 |
(s endsWith:Filename separator) ifFalse:[ |
764 |
s asFilename isDirectory ifTrue:[ |
|
765 |
^ s , Filename separator asString |
|
766 |
] |
|
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
767 |
]. |
440 | 768 |
]. |
769 |
||
770 |
^ s |
|
1318 | 771 |
|
3752 | 772 |
"Modified: / 12.8.1998 / 13:01:48 / cg" |
615 | 773 |
! |
774 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
775 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
776 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
777 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
778 |
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
|
779 |
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
|
780 |
The returned strings are the expanded names, in the same form |
2550 | 781 |
as given in pattern. |
782 |
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
|
783 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
784 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
785 |
|
2906 | 786 |
(self ~~ ConcreteClass) ifTrue:[ |
787 |
^ ConcreteClass filesMatching:aPattern |
|
788 |
]. |
|
789 |
||
790 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
791 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
792 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
793 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
794 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
795 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
796 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
797 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
798 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
799 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
800 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
801 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
802 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
803 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
804 |
|
2906 | 805 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 806 |
! |
807 |
||
2903 | 808 |
isBadCharacter:aCharacter |
809 |
"return true, if aCharacter is unallowed in a filename." |
|
810 |
||
811 |
|ascii| |
|
812 |
||
2906 | 813 |
(self ~~ ConcreteClass) ifTrue:[ |
814 |
^ ConcreteClass isBadCharacter:aCharacter |
|
815 |
]. |
|
816 |
||
2903 | 817 |
ascii := aCharacter asciiValue. |
818 |
ascii < 32 ifTrue:[ |
|
2906 | 819 |
^ true "/ a control character |
2903 | 820 |
]. |
821 |
ascii == 16rFF ifTrue:[ |
|
2906 | 822 |
^ true "/ delete character |
2903 | 823 |
]. |
824 |
^ false |
|
2906 | 825 |
|
826 |
"Modified: 8.9.1997 / 00:32:59 / cg" |
|
2903 | 827 |
! |
828 |
||
829 |
isCaseSensitive |
|
830 |
"return true, if filenames are case sensitive. |
|
831 |
We ask the OS about this, to be independent here." |
|
832 |
||
2906 | 833 |
(self ~~ ConcreteClass) ifTrue:[ |
834 |
^ ConcreteClass isCaseSensitive |
|
835 |
]. |
|
836 |
||
2903 | 837 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 838 |
|
839 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 840 |
! |
841 |
||
615 | 842 |
localNameStringFrom:aString |
843 |
"ST-80 compatibility. |
|
844 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 845 |
GUESS: |
846 |
does it strip off any volume characters and make a path relative ?" |
|
847 |
||
848 |
|sep| |
|
615 | 849 |
|
2906 | 850 |
(self ~~ ConcreteClass) ifTrue:[ |
851 |
^ ConcreteClass localNameStringFrom:aString |
|
852 |
]. |
|
853 |
||
2922 | 854 |
sep := self separator asString. |
855 |
(aString startsWith:sep) ifTrue:[ |
|
856 |
^ aString copyFrom:sep size + 1 |
|
615 | 857 |
]. |
858 |
^ aString |
|
859 |
||
860 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 861 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 862 |
! |
863 |
||
2908 | 864 |
maxComponentLength |
865 |
"return the maximum number of characters a filename component may |
|
866 |
be in size. This depends on the OperatingSystem." |
|
867 |
||
868 |
(self ~~ ConcreteClass) ifTrue:[ |
|
869 |
^ ConcreteClass maxComponentLength |
|
870 |
]. |
|
871 |
^ OperatingSystem maxFileNameLength |
|
872 |
! |
|
873 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
874 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
875 |
"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
|
876 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
877 |
|
2908 | 878 |
(self ~~ ConcreteClass) ifTrue:[ |
879 |
^ ConcreteClass maxLength |
|
880 |
]. |
|
881 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
882 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
883 |
"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
|
884 |
"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
|
885 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
886 |
|
3171 | 887 |
nullFilename |
888 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
889 |
The default is nil here" |
|
890 |
||
891 |
(self ~~ ConcreteClass) ifTrue:[ |
|
892 |
^ ConcreteClass nullFilename |
|
893 |
]. |
|
894 |
||
895 |
^ nil |
|
896 |
||
897 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
898 |
! |
|
899 |
||
615 | 900 |
parentDirectoryName |
901 |
"return the name used for the parent directory. |
|
902 |
This is '..' for unix and dos-like systems. |
|
903 |
(there may be more in the future." |
|
904 |
||
2906 | 905 |
(self ~~ ConcreteClass) ifTrue:[ |
906 |
^ ConcreteClass parentDirectoryName |
|
907 |
]. |
|
908 |
||
909 |
^ OperatingSystem parentDirectoryName |
|
910 |
||
911 |
" |
|
912 |
Filename parentDirectoryName |
|
913 |
" |
|
914 |
||
915 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 916 |
! |
917 |
||
918 |
separator |
|
919 |
"return the file/directory separator. |
|
2906 | 920 |
This is to be redefined in concrete classes; |
921 |
the following default usually leads to a flat view of |
|
922 |
the fileSystem (huh - BS2000 ?)" |
|
923 |
||
924 |
(self ~~ ConcreteClass) ifTrue:[ |
|
925 |
^ ConcreteClass separator |
|
926 |
]. |
|
927 |
^ $_ |
|
615 | 928 |
|
929 |
" |
|
930 |
Filename separator |
|
931 |
" |
|
2906 | 932 |
|
933 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 934 |
! |
935 |
||
936 |
suffixSeparator |
|
937 |
"return the filename suffix separator. |
|
938 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 939 |
(there is currently no known system, where this differs)" |
615 | 940 |
|
941 |
^ $. |
|
942 |
||
943 |
" |
|
944 |
Filename suffixSeparator |
|
945 |
" |
|
946 |
||
947 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 948 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 949 |
! |
950 |
||
2906 | 951 |
tempFileNameTemplate |
952 |
"return a template for temporary files. |
|
953 |
This is expanded with the current processID and a sequenceNumber |
|
954 |
to generate a unique filename." |
|
955 |
||
956 |
(self ~~ ConcreteClass) ifTrue:[ |
|
957 |
^ ConcreteClass tempFileNameTemplate |
|
958 |
]. |
|
959 |
||
960 |
^ 'stxtmp_%1_%2' |
|
961 |
||
962 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
963 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
964 |
! |
|
965 |
||
615 | 966 |
volumes |
967 |
"ST-80 compatibility. |
|
2896 | 968 |
GUESS: does it return the available drives on MSDOS systems ? |
969 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
970 |
||
2906 | 971 |
(self ~~ ConcreteClass) ifTrue:[ |
972 |
^ ConcreteClass volumes |
|
973 |
]. |
|
974 |
||
2896 | 975 |
^ OperatingSystem getDriveList |
615 | 976 |
|
977 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
2906 | 978 |
"Modified: 8.9.1997 / 00:35:19 / cg" |
615 | 979 |
! ! |
980 |
||
981 |
!Filename methodsFor:'comparing'! |
|
982 |
||
983 |
= aFilename |
|
984 |
"return true, if the argument represents the same filename" |
|
985 |
||
986 |
|str| |
|
987 |
||
988 |
self species == aFilename species ifTrue:[ |
|
989 |
str := aFilename asString. |
|
990 |
self class isCaseSensitive ifTrue:[ |
|
991 |
^ nameString = str |
|
992 |
]. |
|
993 |
^ nameString sameAs:str |
|
994 |
]. |
|
995 |
^ false |
|
996 |
! |
|
997 |
||
998 |
hash |
|
999 |
"return an integer useful as a hash-key" |
|
1000 |
||
1001 |
^ nameString hash |
|
1002 |
! ! |
|
1003 |
||
1004 |
!Filename methodsFor:'converting'! |
|
1005 |
||
1006 |
asAbsoluteFilename |
|
1007 |
"return the receiver converted to a filename with |
|
1008 |
an absolute pathname." |
|
1009 |
||
1010 |
^ self pathName asFilename |
|
1011 |
! |
|
1012 |
||
1013 |
asFilename |
|
1970 | 1014 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 1015 |
|
1016 |
"Thats pretty easy here :-)" |
|
1017 |
^ self |
|
1970 | 1018 |
|
1019 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 1020 |
! |
1021 |
||
1022 |
asString |
|
1023 |
"return the receiver converted to a string" |
|
1024 |
||
1025 |
^ nameString |
|
1026 |
! |
|
1027 |
||
1028 |
makeLegalFilename |
|
1970 | 1029 |
"convert the receivers name to be a legal filename. |
1030 |
This removes/replaces invalid characters and/or compresses |
|
1031 |
the name as required by the OS. |
|
615 | 1032 |
The implementation may change in the future to be more |
1033 |
OS specific." |
|
1034 |
||
1035 |
" |
|
1036 |
actually, in Unix spaces are allowed - but it makes life |
|
1037 |
so hard; therefore, replace them by underscores ... |
|
1038 |
" |
|
3658 | 1039 |
(nameString includes:Character space) ifTrue:[ |
1040 |
nameString := nameString copyReplaceAll:(Character space) with:$_. |
|
1041 |
]. |
|
615 | 1042 |
" |
1043 |
need more - especially on SYS5.3 type systems, |
|
1044 |
we may want to contract the fileName to 14 characters. |
|
1045 |
" |
|
1046 |
^ self |
|
1047 |
||
1048 |
" |
|
1049 |
'hello world' asFilename makeLegalFilename |
|
1050 |
" |
|
1970 | 1051 |
|
3658 | 1052 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1053 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1054 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1055 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1056 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1057 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1058 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1059 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1060 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 1061 |
! ! |
1062 |
||
542 | 1063 |
!Filename methodsFor:'error handling'! |
1064 |
||
615 | 1065 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1066 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1067 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1068 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1069 |
|
615 | 1070 |
^ OperatingSystem accessDeniedErrorSignal |
542 | 1071 |
raiseRequestWith:filename |
615 | 1072 |
errorString:('access denied: ' , filename asString) |
1073 |
! |
|
1074 |
||
1075 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1076 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1077 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1078 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1079 |
|
615 | 1080 |
^ OperatingSystem accessDeniedErrorSignal |
1081 |
raiseRequestWith:filename |
|
1082 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 1083 |
! |
1084 |
||
1085 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1086 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1087 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1088 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1089 |
|
542 | 1090 |
^ OperatingSystem fileNotFoundErrorSignal |
1091 |
raiseRequestWith:filename |
|
1092 |
errorString:('file not found: ' , filename asString) |
|
1093 |
! |
|
1094 |
||
1095 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1096 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1097 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1098 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1099 |
|
542 | 1100 |
^ OperatingSystem accessDeniedErrorSignal |
1101 |
raiseRequestWith:filename |
|
1102 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 1103 |
! |
1104 |
||
1105 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1106 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1107 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1108 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1109 |
|
615 | 1110 |
^ OperatingSystem errorSignal |
1111 |
raiseRequestWith:filename |
|
1112 |
errorString:string |
|
1113 |
! ! |
|
1114 |
||
1115 |
!Filename methodsFor:'file access'! |
|
1116 |
||
3015 | 1117 |
appendStream |
1118 |
"return a stream for appending to the file represented by the receiver. |
|
1119 |
If the file does not already exist, it is created. |
|
1120 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
1121 |
||
1122 |
^ self appendingWriteStream |
|
1123 |
! |
|
1124 |
||
615 | 1125 |
appendingWriteStream |
1126 |
"return a stream for appending to the file represented by the receiver. |
|
1127 |
If the file does not already exist, it is created." |
|
1128 |
||
2947 | 1129 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
615 | 1130 |
! |
1131 |
||
1132 |
newReadWriteStream |
|
1133 |
"return a stream for read/write the file represented by the receiver. |
|
1134 |
If the file does not already exist, it is created." |
|
1135 |
||
2947 | 1136 |
^ FileStream newFileNamed:(self osNameForAccess) |
615 | 1137 |
! |
1138 |
||
1139 |
readStream |
|
1140 |
"return a stream for reading from the file represented by the receiver. |
|
1141 |
If the file does not already exist, nil is returned." |
|
1142 |
||
2947 | 1143 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 1144 |
|
1145 |
" |
|
1146 |
'/tmp/foo' asFilename readStream |
|
1147 |
" |
|
1148 |
! |
|
1149 |
||
1150 |
readWriteStream |
|
1151 |
"return a stream for read/write the file represented by the receiver. |
|
1152 |
If the file does not already exist, nil is returned." |
|
1153 |
||
2947 | 1154 |
^ FileStream oldFileNamed:(self osNameForAccess) |
615 | 1155 |
! |
1156 |
||
1157 |
writeStream |
|
1158 |
"return a stream for writing to the file represented by the receiver. |
|
1159 |
If the file does not already exist, it is created." |
|
1160 |
||
2947 | 1161 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 1162 |
|
1163 |
" |
|
1164 |
'/tmp/foo' asFilename writeStream |
|
1165 |
" |
|
1166 |
! ! |
|
1167 |
||
1168 |
!Filename methodsFor:'file operations'! |
|
1169 |
||
1170 |
addAccessRights:aCollection |
|
1171 |
"add the access rights as specified in aCollection for the file represented |
|
1172 |
by the receiver. The argument must be a collection of symbols, |
|
1173 |
such as #readUser, #writeGroup etc." |
|
1174 |
||
2922 | 1175 |
|access osName| |
1176 |
||
2947 | 1177 |
osName := self osNameForFile. |
2922 | 1178 |
access := OperatingSystem accessModeOf:osName. |
615 | 1179 |
aCollection do:[:accessSymbol | |
1180 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
1181 |
]. |
|
2922 | 1182 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1183 |
^ self accessDeniedError:self |
1184 |
] |
|
1185 |
||
1186 |
" |
|
1187 |
'foo' asFilename writeStream close. |
|
1188 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
1189 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
1190 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
1191 |
" |
|
1192 |
! |
|
1193 |
||
2982 | 1194 |
basicMakeDirectory |
1195 |
"create a directory with the receivers name. |
|
1196 |
Return true if successful, false if not." |
|
1197 |
||
1198 |
^ OperatingSystem createDirectory:(self osNameForDirectory) |
|
1199 |
! |
|
1200 |
||
615 | 1201 |
copyTo:newName |
1202 |
"copy the file - the argument must be convertable to a filename. |
|
671 | 1203 |
Return true if successful, false if not." |
615 | 1204 |
|
1205 |
|inStream outStream buffer bufferSize count newFile| |
|
1206 |
||
1207 |
bufferSize := 8 * 1024. |
|
1208 |
buffer := ByteArray new:bufferSize. |
|
1209 |
inStream := self readStream. |
|
1210 |
inStream isNil ifTrue:[ |
|
1211 |
^ self fileNotFoundError:self |
|
1212 |
]. |
|
1213 |
||
1214 |
outStream := (newFile := newName asFilename) writeStream. |
|
1215 |
outStream isNil ifTrue:[ |
|
1216 |
^ self fileCreationError:newFile |
|
1217 |
]. |
|
1218 |
||
1219 |
[inStream atEnd] whileFalse:[ |
|
1220 |
count := inStream nextBytes:bufferSize into:buffer. |
|
1221 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
|
1222 |
^ self fileCreationError:newFile |
|
1223 |
] |
|
1224 |
]. |
|
1225 |
outStream close. |
|
1226 |
inStream close. |
|
1227 |
||
1228 |
" |
|
1229 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
1230 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
1231 |
" |
|
1232 |
! |
|
1233 |
||
1234 |
delete |
|
1235 |
"remove the file - same as remove, for ST-80 compatibility" |
|
1236 |
||
1237 |
self remove |
|
1238 |
! |
|
1239 |
||
1240 |
makeDirectory |
|
1241 |
"create a directory with the receivers name. |
|
671 | 1242 |
Return true if successful, false if not." |
615 | 1243 |
|
2982 | 1244 |
(self basicMakeDirectory) ifFalse:[ |
1245 |
"/ |
|
1246 |
"/ could have existed before ... |
|
1247 |
"/ |
|
2629 | 1248 |
(self exists and:[self isDirectory]) ifFalse:[ |
2982 | 1249 |
self fileCreationError:self. |
1250 |
^ false |
|
2629 | 1251 |
] |
2982 | 1252 |
]. |
1253 |
^ true |
|
1970 | 1254 |
|
1255 |
"Modified: 12.11.1996 / 12:25:22 / cg" |
|
615 | 1256 |
! |
1257 |
||
844 | 1258 |
makeExecutable |
1259 |
"make the file executable - you must have permission to do so. |
|
1260 |
For directories, execution means: 'allow changing into it'" |
|
1261 |
||
1262 |
^ self addAccessRights:#(executeUser) |
|
1263 |
||
1264 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
1265 |
! |
|
1266 |
||
1267 |
makeExecutableForAll |
|
1268 |
"make the file executable for all - you must have permission to do so. |
|
1269 |
For directories, execution means: 'allow changing into it'" |
|
1270 |
||
1271 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
1272 |
||
1273 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
1274 |
! |
|
1275 |
||
615 | 1276 |
makeReadable |
1277 |
"make the file readable for the owner - you must have permission to do so." |
|
1278 |
||
1279 |
^ self addAccessRights:#(readUser) |
|
1280 |
! |
|
1281 |
||
1282 |
makeReadableForAll |
|
1283 |
"make the file readable for all - you must have permission to do so." |
|
1284 |
||
1285 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
1286 |
! |
|
1287 |
||
1288 |
makeUnwritable |
|
1289 |
"make the file unwritable for all - you must have permission to do so." |
|
1290 |
||
1291 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
1292 |
! |
|
1293 |
||
1294 |
makeWritable |
|
1295 |
"make the file writableable for all - you must have permission to do so." |
|
1296 |
||
1297 |
^ self addAccessRights:#(writeUser) |
|
1298 |
! |
|
1299 |
||
1300 |
makeWritableForAll |
|
1301 |
"make the file writable for all - you must have permission to do so." |
|
1302 |
||
1303 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
1304 |
! |
|
1305 |
||
1306 |
moveTo:newName |
|
1307 |
"copy the file represented by the receiver, then delete it. |
|
1308 |
This is different to renaming in case of cross device moves. |
|
671 | 1309 |
Raise an error if not successful." |
615 | 1310 |
|
1311 |
self copyTo:newName. |
|
1312 |
self remove |
|
1313 |
! |
|
1314 |
||
659 | 1315 |
recursiveMakeDirectory |
1316 |
"create a directory with the receivers name and all required intermediate |
|
1317 |
directories. |
|
671 | 1318 |
Raise an error if not successful." |
659 | 1319 |
|
2922 | 1320 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
671 | 1321 |
^ self fileCreationError:self |
659 | 1322 |
] |
1323 |
||
1324 |
"Created: 27.11.1995 / 23:36:40 / cg" |
|
1325 |
! |
|
1326 |
||
615 | 1327 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1328 |
"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
|
1329 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
671 | 1330 |
Raise an error if not successful." |
615 | 1331 |
|
1332 |
|ok| |
|
1333 |
||
3302 | 1334 |
"/ typically, an 'rm -rf' is faster and removes better; |
1335 |
"/ however, if the fork fails, fallBack doing a manual |
|
1336 |
"/ directory walk. |
|
1337 |
||
1338 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
1339 |
ok ifFalse:[ |
|
1340 |
self recursiveRemoveWithoutOSCommand |
|
1341 |
]. |
|
1342 |
||
1343 |
" |
|
1344 |
'foo' asFilename makeDirectory. |
|
1345 |
'foo/bar' asFilename writeStream close. |
|
1346 |
('foo' asFilename remove) ifFalse:[ |
|
1347 |
Transcript showCR:'could not remove foo' |
|
1348 |
] |
|
1349 |
" |
|
1350 |
" |
|
1351 |
'foo' asFilename makeDirectory. |
|
1352 |
'foo/bar' asFilename writeStream close. |
|
1353 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
1354 |
Transcript showCR:'could not remove foo' |
|
1355 |
] |
|
1356 |
" |
|
1357 |
||
1358 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
1359 |
"Modified: / 25.2.1998 / 19:51:34 / cg" |
|
1360 |
! |
|
1361 |
||
1362 |
recursiveRemoveWithoutOSCommand |
|
1363 |
"if I represent a regular file, remove it. |
|
1364 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
1365 |
Raise an error if not successful. |
|
1366 |
This one walks down the directory hierarchy, not using any OS |
|
1367 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1368 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1369 |
self isDirectory ifTrue:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1370 |
self directoryContents do:[:aFilenameString | |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1371 |
|f| |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1372 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1373 |
f := self construct:aFilenameString. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1374 |
f isDirectory ifTrue:[ |
3302 | 1375 |
f recursiveRemoveWithoutOSCommand |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1376 |
] ifFalse:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1377 |
f remove |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1378 |
]. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1379 |
] |
615 | 1380 |
]. |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1381 |
self remove |
615 | 1382 |
|
1383 |
" |
|
1384 |
'foo' asFilename makeDirectory. |
|
1385 |
'foo/bar' asFilename writeStream close. |
|
1386 |
('foo' asFilename remove) ifFalse:[ |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1387 |
Transcript showCR:'could not remove foo' |
615 | 1388 |
] |
1389 |
" |
|
1390 |
" |
|
1391 |
'foo' asFilename makeDirectory. |
|
1392 |
'foo/bar' asFilename writeStream close. |
|
1393 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
1394 |
Transcript showCR:'could not remove foo' |
615 | 1395 |
] |
1396 |
" |
|
1397 |
||
3302 | 1398 |
"Created: / 25.2.1998 / 19:50:40 / cg" |
1399 |
"Modified: / 25.2.1998 / 19:52:08 / cg" |
|
615 | 1400 |
! |
1401 |
||
1402 |
remove |
|
845 | 1403 |
"remove the file/directory. |
672 | 1404 |
Raise an error if not successful. |
845 | 1405 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 1406 |
|
1407 |
|ok| |
|
1408 |
||
1409 |
self exists ifFalse:[ ^ self]. |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1410 |
(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
|
1411 |
ok := OperatingSystem removeDirectory:(self osNameForFile) |
615 | 1412 |
] ifFalse:[ |
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1413 |
ok := OperatingSystem removeFile:(self osNameForFile) |
615 | 1414 |
]. |
1415 |
ok ifFalse:[ |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1416 |
self removeError:self |
615 | 1417 |
]. |
1418 |
||
1419 |
" |
|
1420 |
(FileStream newFileNamed:'foo') close. |
|
1421 |
'foo' asFilename remove |
|
1422 |
" |
|
1423 |
||
1424 |
" |
|
1425 |
'foo' asFilename makeDirectory. |
|
1426 |
'foo/bar' asFilename writeStream close. |
|
1427 |
('foo' asFilename remove) ifFalse:[ |
|
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1428 |
Transcript showCR:'could not remove foo' |
615 | 1429 |
] |
1430 |
" |
|
1431 |
||
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
1432 |
"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
|
1433 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
615 | 1434 |
! |
1435 |
||
1436 |
removeAccessRights:aCollection |
|
1437 |
"remove the access rights as specified in aCollection for the file represented |
|
1438 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 1439 |
such as #readUser, #writeGroup etc. |
1440 |
Raise an error if not successful." |
|
615 | 1441 |
|
2922 | 1442 |
|access osName| |
1443 |
||
2947 | 1444 |
osName := self osNameForFile. |
2922 | 1445 |
access := OperatingSystem accessModeOf:osName. |
615 | 1446 |
aCollection do:[:accessSymbol | |
1447 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
|
1448 |
]. |
|
2922 | 1449 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
615 | 1450 |
^ self accessDeniedError:self |
1451 |
]. |
|
1452 |
||
1453 |
" |
|
1454 |
'foo' asFilename writeStream close. |
|
1455 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
1456 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
1457 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
1458 |
" |
|
1459 |
! |
|
1460 |
||
1461 |
renameTo:newName |
|
671 | 1462 |
"rename the file - the argument must be convertable to a String. |
1463 |
Raise an error if not successful." |
|
615 | 1464 |
|
2922 | 1465 |
(OperatingSystem |
1466 |
renameFile:(self osNameForFile) |
|
1467 |
to:(newName asFilename osNameForFile) |
|
1468 |
) ifFalse:[ |
|
615 | 1469 |
self exists ifFalse:[ |
1470 |
^ self fileNotFoundError:self |
|
1471 |
]. |
|
1472 |
^ self accessDeniedError:newName asFilename. |
|
1473 |
]. |
|
1474 |
||
1475 |
" |
|
1476 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1477 |
" |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1478 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1479 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1480 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1481 |
"change the files size. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1482 |
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
|
1483 |
|
2922 | 1484 |
(OperatingSystem truncateFile:(self osNameForFile) to:newSize) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1485 |
^ 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
|
1486 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1487 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1488 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1489 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1490 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1491 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1492 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1493 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1494 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1495 |
'test' asFilename truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1496 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1497 |
" |
615 | 1498 |
! ! |
1499 |
||
1500 |
!Filename methodsFor:'file queries'! |
|
1501 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1502 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1503 |
"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
|
1504 |
|
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
1505 |
^ self info accessed |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1506 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1507 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1508 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1509 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1510 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1511 |
"Created: 9.7.1996 / 10:19:15 / cg" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1512 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
1513 |
"Modified: 26.9.1997 / 13:05:51 / stefan" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1514 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1515 |
|
615 | 1516 |
dates |
1517 |
"return the files modification and access times as an object (currently a dictionary) |
|
1518 |
that responds to the at: message with arguments |
|
1519 |
#modified, #accessed or #statusChanged." |
|
1520 |
||
2922 | 1521 |
|info dates osName| |
1522 |
||
2947 | 1523 |
osName := self osNameForAccess. |
2922 | 1524 |
info := OperatingSystem infoOf:osName. |
615 | 1525 |
info isNil ifTrue:[ |
2922 | 1526 |
info := OperatingSystem linkInfoOf:osName. |
2629 | 1527 |
info isNil ifTrue:[ |
1528 |
^ nil |
|
1529 |
] |
|
615 | 1530 |
]. |
1531 |
dates := IdentityDictionary new. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1532 |
dates at:#modified put:(info modified). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1533 |
dates at:#accessed put:(info accessed). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1534 |
dates at:#statusChanged put:(info statusChanged). |
615 | 1535 |
^ dates |
1536 |
||
1537 |
" |
|
1538 |
Filename currentDirectory dates |
|
1539 |
'../regression' asFilename dates |
|
1540 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1541 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1542 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 1543 |
! |
1544 |
||
1545 |
fileSize |
|
1546 |
"return the size of the file in bytes" |
|
1547 |
||
1548 |
|info| |
|
1549 |
||
1550 |
info := self info. |
|
1551 |
info isNil ifTrue:[^ nil]. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1552 |
^ info size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1553 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1554 |
"Modified: 1.11.1996 / 20:24:43 / cg" |
615 | 1555 |
! |
1556 |
||
1557 |
fileType |
|
1558 |
"this returns a string describing the type of contents of |
|
1559 |
the file. This is done using the unix 'file' command, |
|
1560 |
(which usually is configurable by /etc/magic). |
|
3665 | 1561 |
On non-unix systems, this may simply return 'file', |
2922 | 1562 |
not knowning about the contents. |
1563 |
Warning: |
|
1564 |
Since the returned string differs among systems (and language settings), |
|
3665 | 1565 |
it is only useful for user-information; |
1566 |
NOT as a tag to be used by a program." |
|
1567 |
||
1568 |
|type buffer s n suffix idx baseNm| |
|
1569 |
||
1570 |
"/ since we cannot depend on a 'file' command being available, |
|
1571 |
"/ do the most obvious ones here. |
|
1572 |
"/ (also useful since the 'file' command takes some time, and the code |
|
1573 |
"/ 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
|
1574 |
|
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1575 |
self isSymbolicLink ifTrue:[ |
2906 | 1576 |
^ 'symbolic link to ' , (self linkInfo path) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1577 |
]. |
2573 | 1578 |
self isDirectory ifTrue:[ |
2906 | 1579 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
1580 |
self isExecutable ifFalse:[^ 'directory, locked']. |
|
1581 |
^ 'directory' |
|
2573 | 1582 |
]. |
3665 | 1583 |
(type := self type) == #characterSpecial ifTrue:[ |
1584 |
^ 'character device special file' |
|
1585 |
]. |
|
1586 |
type == #blockSpecial ifTrue:[ |
|
1587 |
^ 'block device special file' |
|
1588 |
]. |
|
1589 |
type == #socket ifTrue:[ |
|
1590 |
^ 'socket' |
|
1591 |
]. |
|
1592 |
||
1602 | 1593 |
self isReadable ifFalse:[^ 'unreadable']. |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1594 |
self fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 1595 |
|
2922 | 1596 |
suffix := self suffix asLowercase. |
1597 |
baseNm := self withoutSuffix baseName asLowercase. |
|
1598 |
||
1599 |
((#('st' 'rc' 'chg' 'htm' 'html' 'ps') includes:suffix) |
|
1600 |
or:[#('makefile') includes:baseNm]) ifTrue:[ |
|
1601 |
||
1602 |
buffer := String new:2024. |
|
1603 |
s := self readStream. |
|
1604 |
s notNil ifTrue:[ |
|
1605 |
n := s nextBytes:buffer size into:buffer. |
|
1606 |
s close. |
|
1607 |
||
1608 |
(suffix = 'st') ifTrue:[ |
|
2906 | 1609 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
1610 |
^ 'smalltalk source' |
|
1611 |
]. |
|
1612 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1613 |
^ 'smalltalk source' |
|
1614 |
]. |
|
1615 |
]. |
|
1616 |
||
1617 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
|
1618 |
^ 'smalltalk changes / method source' |
|
1619 |
]. |
|
1620 |
||
1621 |
(suffix = 'rc') ifTrue:[ |
|
1622 |
(buffer findString:'ST/X startup') ~~ 0 ifTrue:[ |
|
1623 |
^ 'smalltalk startup script' |
|
1624 |
]. |
|
1625 |
]. |
|
2922 | 1626 |
|
2906 | 1627 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
1628 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
|
1629 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
|
1630 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
|
1631 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
|
1632 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
|
1633 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
|
1634 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
|
1635 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
|
1636 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
|
1637 |
ifTrue:[ |
|
1638 |
^ 'HTML document text' |
|
1639 |
] |
|
1640 |
]. |
|
1641 |
]. |
|
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1642 |
|
2906 | 1643 |
(suffix = 'ps') ifTrue:[ |
1644 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
|
1645 |
^ 'PostScript document' |
|
1646 |
]. |
|
1647 |
]. |
|
1648 |
||
1649 |
(baseNm = 'makefile') ifTrue:[ |
|
1650 |
(buffer startsWith:'#') ifTrue:[ |
|
1651 |
^ 'make rules' |
|
1652 |
] |
|
3665 | 1653 |
] |
2906 | 1654 |
] |
1602 | 1655 |
]. |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1656 |
|
2906 | 1657 |
^ 'file' |
615 | 1658 |
|
1659 |
" |
|
1660 |
'Makefile' asFilename fileType |
|
1661 |
'.' asFilename fileType |
|
3665 | 1662 |
'/dev/null' asFilename fileType |
1663 |
'/tmp/.X11-unix/X0' asFilename fileType |
|
615 | 1664 |
'smalltalk.rc' asFilename fileType |
1665 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
1666 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1667 |
|
3665 | 1668 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 1669 |
! |
1670 |
||
2836 | 1671 |
id |
1672 |
"return the files/directories file-id (inode number)" |
|
1673 |
||
2947 | 1674 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 1675 |
|
1676 |
" |
|
1677 |
Filename currentDirectory id |
|
1678 |
" |
|
1679 |
||
1680 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
1681 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
1682 |
! |
|
1683 |
||
615 | 1684 |
info |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1685 |
"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
|
1686 |
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
|
1687 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1688 |
|
2629 | 1689 |
type - a symbol giving the files fileType |
1690 |
mode - numeric access mode |
|
1691 |
uid - owners user id |
|
1692 |
gid - owners group id |
|
1693 |
size - files size |
|
1694 |
id - files number (i.e. inode number) |
|
1695 |
accessed - last access time (as osTime-stamp) |
|
1696 |
modified - last modification time (as osTime-stamp) |
|
1697 |
statusChanged - last staus change (as osTime-stamp) |
|
615 | 1698 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1699 |
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
|
1700 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1701 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
2629 | 1702 |
modified |
1703 |
size |
|
1704 |
type |
|
615 | 1705 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1706 |
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
|
1707 |
to either handle nil values, |
615 | 1708 |
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
|
1709 |
(i.e. instead of: |
2629 | 1710 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1711 |
use |
2922 | 1712 |
someFilename isDirectory |
615 | 1713 |
" |
1714 |
||
2947 | 1715 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 1716 |
|
1717 |
" |
|
1718 |
Filename currentDirectory info |
|
1719 |
'/dev/null' asFilename info |
|
1720 |
'Make.proto' asFilename info |
|
1721 |
'source/Point.st' asFilename info |
|
1722 |
'source/Point.st' asFilename linkInfo |
|
1723 |
'../../libbasic/Point.st' asFilename info |
|
1724 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1725 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1726 |
"Modified: 1.11.1996 / 20:22:40 / cg" |
615 | 1727 |
! |
1728 |
||
1729 |
linkInfo |
|
1730 |
"return the files info if its a symbolic link; nil otherwise. |
|
1731 |
On OS's which do not support symbolic links, nil is always returned. |
|
1732 |
The information is the same as returned by #info, except that if the |
|
1733 |
receiver represents a symbolic link, the links information |
|
1734 |
is returned |
|
1735 |
(while in this case, #info returns the info of the target file, |
|
1736 |
which is accessed via the symbolic link). |
|
1737 |
||
1738 |
In addition to the normal entries, Unix returns an additional entry: |
|
2629 | 1739 |
path -> the target files pathname |
615 | 1740 |
|
1741 |
See the comment in #info for more details." |
|
1742 |
||
2947 | 1743 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 1744 |
|
1745 |
" |
|
1746 |
Filename currentDirectory linkInfo |
|
1747 |
'/dev/null' asFilename linkInfo |
|
1748 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1749 |
'Make.proto' asFilename linkInfo path |
615 | 1750 |
'source/Point.st' asFilename linkInfo |
1751 |
'../../libbasic/Point.st' asFilename linkInfo |
|
1752 |
" |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1753 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1754 |
"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
|
1755 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1756 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1757 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1758 |
"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
|
1759 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1760 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1761 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1762 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1763 |
^ i modified |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1764 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1765 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1766 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1767 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1768 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1769 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1770 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
1771 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 1772 |
! |
1773 |
||
1774 |
type |
|
1775 |
"return the symbolic type of the file" |
|
1776 |
||
2947 | 1777 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 1778 |
|
1779 |
" |
|
1780 |
Filename currentDirectory type |
|
1781 |
" |
|
1782 |
||
1783 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
1784 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 1785 |
! ! |
1786 |
||
1787 |
!Filename methodsFor:'file utilities'! |
|
1788 |
||
1789 |
edit |
|
1790 |
"start an editView on the file represented by the receiver" |
|
1791 |
||
1792 |
EditTextView openOn:self asString |
|
1793 |
||
1794 |
" |
|
1795 |
'smalltalk.rc' asFilename edit |
|
1796 |
" |
|
1797 |
! |
|
1798 |
||
1799 |
fileIn |
|
1800 |
"load smalltalk code from the file" |
|
1801 |
||
1802 |
^ self readStream fileIn |
|
542 | 1803 |
! ! |
1804 |
||
2 | 1805 |
!Filename methodsFor:'instance creation'! |
1806 |
||
615 | 1807 |
construct:subname |
1808 |
"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
|
1809 |
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
|
1810 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 1811 |
The argument may not specify an absolute path name. |
1812 |
Please do not use this to create filenames with suffixes, |
|
1813 |
since some systems require special naming conventions. |
|
1814 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 1815 |
|
2903 | 1816 |
^ self class named:(self constructString:subname) |
615 | 1817 |
|
1818 |
" |
|
1819 |
'/tmp' asFilename construct:'foo' |
|
1820 |
'/' asFilename construct:'foo' |
|
1821 |
'/usr/tmp' asFilename construct:'foo' |
|
1822 |
'/foo/bar' asFilename construct:'baz' |
|
2922 | 1823 |
|
1824 |
Bad example; works on UNIX, but may not on others: |
|
1825 |
'foo/bar.baz' construct:'.suff' |
|
615 | 1826 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1827 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1828 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 1829 |
! |
1830 |
||
2922 | 1831 |
constructDirectory:subname |
1832 |
"same as #construct: on most systems. |
|
1833 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
1834 |
||
1835 |
^ self class named:(self constructDirectoryString:subname) |
|
1836 |
! |
|
1837 |
||
1838 |
constructDirectoryString:subName |
|
1839 |
"same as #constructString: on most systems. |
|
1840 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
1841 |
||
1842 |
^ self constructString:subName |
|
1843 |
! |
|
1844 |
||
1845 |
constructString:subName |
|
2911 | 1846 |
"taking the receiver as a directory name, construct a new |
1847 |
filename-string for an entry within this directory |
|
2922 | 1848 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 1849 |
The argument may not specify an absolute path name. |
1850 |
The code below works for UNIX & MSDOS; |
|
1851 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
1852 |
||
1853 |
|sepString sub| |
|
1854 |
||
1855 |
sub := subName asString. |
|
2911 | 1856 |
sepString := self class separator asString. |
1857 |
nameString = sepString ifTrue:[ |
|
1858 |
"I am the root" |
|
2960 | 1859 |
^ sepString , sub |
2911 | 1860 |
]. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1861 |
(nameString endsWith:sepString) ifTrue:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1862 |
^ nameString , sub |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1863 |
]. |
2960 | 1864 |
^ nameString , sepString , sub |
2911 | 1865 |
|
1866 |
" |
|
1867 |
'/tmp' asFilename constructString:'foo' |
|
1868 |
'/' asFilename constructString:'foo' |
|
1869 |
'/usr/tmp' asFilename constructString:'foo' |
|
1870 |
'/foo/bar' asFilename constructString:'baz' |
|
1871 |
" |
|
1872 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1873 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1874 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1875 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
1876 |
"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
|
1877 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1878 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1879 |
filenameFor:fileName |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1880 |
"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
|
1881 |
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
|
1882 |
(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
|
1883 |
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
|
1884 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1885 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1886 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1887 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1888 |
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
|
1889 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1890 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1891 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1892 |
'/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
|
1893 |
'/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
|
1894 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1895 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
1896 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
2 | 1897 |
! ! |
1898 |
||
195 | 1899 |
!Filename methodsFor:'misc'! |
1900 |
||
1901 |
, aString |
|
1902 |
"this allows filenames to understand how names are concatenated. |
|
308 | 1903 |
Returns a string consisting of the receivers name, concatenated |
195 | 1904 |
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
|
1905 |
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
|
1906 |
See also: #withSuffix: which is new and better." |
195 | 1907 |
|
2906 | 1908 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 1909 |
^ (nameString , aString asString) |
195 | 1910 |
|
1911 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1912 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1913 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1914 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1915 |
'Makefile' asFilename construct:'.bak' |
195 | 1916 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1917 |
|
2906 | 1918 |
"Modified: 7.9.1997 / 23:45:36 / cg" |
195 | 1919 |
! ! |
1920 |
||
615 | 1921 |
!Filename methodsFor:'printing & storing'! |
174 | 1922 |
|
615 | 1923 |
printOn:aStream |
1924 |
"append a printed representation of the receiver to aStream." |
|
174 | 1925 |
|
2906 | 1926 |
aStream nextPutAll:(self class name). |
1927 |
aStream nextPutAll:'('''. |
|
615 | 1928 |
nameString printOn:aStream. |
1929 |
aStream nextPutAll:''')' |
|
2906 | 1930 |
|
1931 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 1932 |
! |
1933 |
||
615 | 1934 |
storeOn:aStream |
1935 |
"append a printed representation of the receiver to aStream, |
|
1936 |
which allows reconstructing it via readFrom:" |
|
328 | 1937 |
|
615 | 1938 |
aStream nextPut:$(. |
1939 |
nameString storeOn:aStream. |
|
1940 |
aStream nextPutAll:' asFilename)' |
|
1 | 1941 |
! ! |
1942 |
||
202 | 1943 |
!Filename methodsFor:'private accessing'! |
1 | 1944 |
|
68 | 1945 |
setName:aString |
38 | 1946 |
"set the filename" |
1947 |
||
3666 | 1948 |
nameString := self nameWithSpecialExpansions:aString. |
1949 |
||
1950 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 1951 |
! ! |
1952 |
||
2 | 1953 |
!Filename methodsFor:'queries'! |
1954 |
||
615 | 1955 |
canBeWritten |
1956 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 1957 |
|
615 | 1958 |
^ self isWritable |
92 | 1959 |
|
328 | 1960 |
" |
615 | 1961 |
'/foo/bar' asFilename canBeWritten |
1962 |
'/tmp' asFilename canBeWritten |
|
1963 |
'Makefile' asFilename canBeWritten |
|
328 | 1964 |
" |
1965 |
! |
|
1966 |
||
68 | 1967 |
exists |
92 | 1968 |
"return true, if such a file exists." |
68 | 1969 |
|
2947 | 1970 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 1971 |
|
85 | 1972 |
" |
92 | 1973 |
'/foo/bar' asFilename exists |
1974 |
'/tmp' asFilename exists |
|
1975 |
'Makefile' asFilename exists |
|
85 | 1976 |
" |
77 | 1977 |
! |
1978 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1979 |
filesMatching:aPattern |
2550 | 1980 |
"given the receiver, representing a directory; |
1981 |
return a collection of files matching a pattern. |
|
1982 |
The pattern may be a simple matchPattern, or a set of |
|
1983 |
multiple patterns separated by semicolons." |
|
1984 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
1985 |
|matchers notCaseSensitive| |
2550 | 1986 |
|
1987 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
1988 |
notCaseSensitive := self class isCaseSensitive not. |
2550 | 1989 |
^ self directoryContents |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
1990 |
select:[:name | |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
1991 |
(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
|
1992 |
] |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1993 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1994 |
" |
2550 | 1995 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1996 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1997 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
1998 |
"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
|
1999 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 2000 |
! |
2001 |
||
2002 |
filesMatchingWithoutDotDirs:aPattern |
|
2003 |
"given the receiver, representing a directory; |
|
2004 |
return a collection of files matching a pattern. |
|
2005 |
Exclude '.' and '..' from the returned list. |
|
2006 |
The pattern may be a simple matchPattern, or a set of |
|
2007 |
multiple patterns separated by semicolons." |
|
2008 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2009 |
|matchers notCaseSensitive| |
2550 | 2010 |
|
2011 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2012 |
notCaseSensitive := self class isCaseSensitive not. |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2013 |
|
2550 | 2014 |
^ self directoryContents |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2015 |
select:[:name | |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2016 |
name ~= '.' |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2017 |
and:[name ~= '..' |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2018 |
and:[(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0]] |
2550 | 2019 |
] |
2020 |
||
2021 |
" |
|
2022 |
Filename currentDirectory filesMatching:'M*' |
|
2023 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
2024 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
2025 |
" |
|
2026 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
2027 |
"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
|
2028 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2029 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
2030 |
|
615 | 2031 |
isAbsolute |
2032 |
"return true, if the receiver represents an absolute pathname |
|
2033 |
(in contrast to one relative to the current directory)." |
|
356 | 2034 |
|
2629 | 2035 |
(nameString startsWith:self class separator) ifTrue:[^ true]. |
2036 |
^ self isVolumeAbsolute |
|
328 | 2037 |
|
2038 |
" |
|
615 | 2039 |
'/foo/bar' asFilename isAbsolute |
2040 |
'..' asFilename isAbsolute |
|
2041 |
'..' asAbsoluteFilename isAbsolute |
|
2042 |
'source/SBrowser.st' asFilename isAbsolute |
|
2043 |
" |
|
2044 |
! |
|
2045 |
||
2046 |
isDirectory |
|
2047 |
"return true, if the receiver represents an existing, |
|
2048 |
readable directories pathname." |
|
2049 |
||
2947 | 2050 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
615 | 2051 |
|
2052 |
" |
|
2053 |
'/foo/bar' asFilename isDirectory |
|
2054 |
'/tmp' asFilename isDirectory |
|
2055 |
'Makefile' asFilename isDirectory |
|
2056 |
" |
|
2057 |
! |
|
2058 |
||
2059 |
isExecutable |
|
2060 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
2061 |
For directories, true is returned if the directory can be entered. |
|
2062 |
See isExecutableProgram for a related check." |
|
2063 |
||
2947 | 2064 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 2065 |
|
2066 |
" |
|
2067 |
'/foo/bar' asFilename isExecutable |
|
2068 |
'/tmp' asFilename isExecutable |
|
2069 |
'Makefile' asFilename isExecutable |
|
2070 |
'/bin/ls' asFilename isExecutable |
|
356 | 2071 |
" |
2072 |
! |
|
2073 |
||
615 | 2074 |
isExecutableProgram |
2075 |
"return true, if such a file exists and is an executable program. |
|
2076 |
(i.e. for directories, false is returned.)" |
|
356 | 2077 |
|
2922 | 2078 |
|osName| |
2079 |
||
2947 | 2080 |
osName := self osNameForAccess. |
2922 | 2081 |
^ (OperatingSystem isExecutable:osName) |
2082 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 2083 |
|
2084 |
" |
|
615 | 2085 |
'/tmp' asFilename isExecutable |
2086 |
'/bin/ls' asFilename isExecutable |
|
2087 |
'/tmp' asFilename isExecutableProgram |
|
2088 |
'/bin/ls' asFilename isExecutableProgram |
|
2089 |
" |
|
2090 |
! |
|
2091 |
||
2922 | 2092 |
isExplicitRelative |
2093 |
"return true, if this name is an explicit relative name |
|
2094 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
2095 |
||
2096 |
^ false |
|
2097 |
! |
|
2098 |
||
2099 |
isHidden |
|
2100 |
"return true, if the receiver represents a hidden file. |
|
2101 |
The definitions of hidden files depends on the OS used; |
|
2102 |
on UNIX, a name starting with a period is considered hidden; |
|
2103 |
on MSDOS, the files hidden attribute is used. |
|
2104 |
VMS has no concept of hidden files." |
|
2105 |
||
2106 |
^ false |
|
2107 |
! |
|
2108 |
||
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2109 |
isImplicit |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2110 |
"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
|
2111 |
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
|
2112 |
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
|
2113 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2114 |
^ false |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2115 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2116 |
"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
|
2117 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
2118 |
|
615 | 2119 |
isReadable |
2120 |
"return true, if such a file exists and is readable." |
|
2121 |
||
2947 | 2122 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 2123 |
|
2124 |
" |
|
2125 |
'/foo/bar' asFilename isReadable |
|
2126 |
'/tmp' asFilename isReadable |
|
2127 |
'Makefile' asFilename isReadable |
|
328 | 2128 |
" |
2129 |
! |
|
2130 |
||
615 | 2131 |
isRelative |
2132 |
"return true, if this name is interpreted relative to some |
|
2133 |
directory (opposite of absolute)" |
|
328 | 2134 |
|
615 | 2135 |
^ self isAbsolute not |
2175 | 2136 |
|
2137 |
" |
|
2138 |
'./foo/bar' asFilename isRelative |
|
2139 |
'../../foo/bar' asFilename isRelative |
|
2140 |
'/foo/bar' asFilename isRelative |
|
2141 |
'bar' asFilename isRelative |
|
2142 |
" |
|
2143 |
||
2144 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
615 | 2145 |
! |
328 | 2146 |
|
3045 | 2147 |
isRootDirectory |
3046 | 2148 |
"return true, if I represent the root directory |
2149 |
(i.e. I have no parentDir)" |
|
2150 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2151 |
"/ mhmh - should we use: |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2152 |
"/ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2153 |
"/ parentDir := self construct:'..'. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2154 |
"/ (parentDir exists |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2155 |
"/ and:[parentDir isDirectory |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2156 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2157 |
"/ ^ false |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2158 |
"/ ]. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2159 |
"/ ^ true |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2160 |
"/ |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2161 |
|
3046 | 2162 |
^ self pathName = Filename rootDirectory pathName |
2163 |
||
2164 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
3045 | 2165 |
! |
2166 |
||
615 | 2167 |
isSymbolicLink |
2168 |
"return true, if the file represented by the receiver is a symbolic |
|
2169 |
link. Notice that not all OS's support symbolic links; those that do |
|
2170 |
not will always return false." |
|
2171 |
||
2947 | 2172 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
328 | 2173 |
|
2174 |
" |
|
615 | 2175 |
'Make.proto' asFilename isSymbolicLink |
2176 |
'Makefile' asFilename isSymbolicLink |
|
2177 |
" |
|
2178 |
! |
|
2179 |
||
2629 | 2180 |
isVolumeAbsolute |
2181 |
"return true, if the receiver represents an absolute pathname |
|
2182 |
on some disk volume (MSDOS only)" |
|
2183 |
||
2184 |
^ false |
|
2906 | 2185 |
|
2186 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
2629 | 2187 |
! |
2188 |
||
615 | 2189 |
isWritable |
2190 |
"return true, if such a file exists and is writable." |
|
2191 |
||
2947 | 2192 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 2193 |
|
2194 |
" |
|
2195 |
'/foo/bar' asFilename isWritable |
|
2196 |
'/tmp' asFilename isWritable |
|
2197 |
'Makefile' asFilename isWritable |
|
328 | 2198 |
" |
174 | 2199 |
! |
2200 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2201 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2202 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2203 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2204 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2205 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2206 |
"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
|
2207 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2208 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2209 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2210 |
|
1540 | 2211 |
contents |
2212 |
"return the contents of the file as a collection of lines; |
|
2213 |
or nil, if the file is unreadable." |
|
2214 |
||
2215 |
|s contents| |
|
2216 |
||
2217 |
s := self readStream. |
|
2218 |
s isNil ifTrue:[^ nil]. |
|
2219 |
||
2220 |
[ |
|
2629 | 2221 |
contents := s contents |
1540 | 2222 |
] valueNowOrOnUnwindDo:[s close]. |
2223 |
^ contents |
|
2224 |
||
2225 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
2226 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
|
2227 |
"Created: 11.7.1996 / 14:09:11 / cg" |
|
2228 |
! |
|
2229 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2230 |
contentsOfEntireFile |
1540 | 2231 |
"return the contents of the file as a string; |
2232 |
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
|
2233 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2234 |
|s contents| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2235 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2236 |
s := self readStream. |
1535 | 2237 |
s isNil ifTrue:[^ nil]. |
2238 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2239 |
[ |
2629 | 2240 |
contents := s contentsOfEntireFile |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2241 |
] valueNowOrOnUnwindDo:[s close]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2242 |
^ contents |
1523 | 2243 |
|
2244 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1540 | 2245 |
"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
|
2246 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2247 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2248 |
directoryContents |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2249 |
"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
|
2250 |
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
|
2251 |
|
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2252 |
|s contents| |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2253 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
3713
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2254 |
s isNil ifTrue:[^nil]. |
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2255 |
|
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2256 |
contents := s contents. |
881d419652f3
care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents:
3677
diff
changeset
|
2257 |
s close. |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2258 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2259 |
contents remove:'.' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2260 |
contents remove:'..' ifAbsent:nil. |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2261 |
^ contents. |
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2262 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2263 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2264 |
'.' asFilename directoryContents |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2265 |
'/XXXdoesNotExist' asFilename directoryContents |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2266 |
" |
2946
c61e7226a7eb
#directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents:
2944
diff
changeset
|
2267 |
|
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2268 |
"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
|
2269 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
2960 | 2270 |
! |
2271 |
||
2272 |
fullDirectoryContents |
|
2273 |
"return the full contents of the directory as a collection of strings. |
|
2274 |
This is much like #directoryContents, but includes an entry for the |
|
2275 |
parent directory, if there is one." |
|
2276 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2277 |
|files| |
2960 | 2278 |
|
2279 |
files := self directoryContents. |
|
3302 | 2280 |
files isNil ifTrue:[ |
2281 |
"/ mhmh - that one does not exist |
|
2282 |
^ files |
|
2283 |
]. |
|
2960 | 2284 |
|
2285 |
"/ add parentDirectory if there is one |
|
2286 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2287 |
files remove:'.' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2288 |
self isRootDirectory ifTrue:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2289 |
files remove:'..' ifAbsent:nil. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2290 |
] ifFalse:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2291 |
(files includes:'..') ifFalse:[ |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2292 |
files addFirst:'..'. |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2293 |
] |
2960 | 2294 |
]. |
2295 |
^ files |
|
3046 | 2296 |
|
2297 |
" |
|
2298 |
'.' asFilename fullDirectoryContents |
|
2299 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
2300 |
" |
|
2301 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
2302 |
"Modified: / 27.7.1998 / 19:49:59 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2303 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2304 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2305 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2306 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2307 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2308 |
"return my baseName as a string. |
2012 | 2309 |
- thats the file/directory name without leading parent-dirs. |
2922 | 2310 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
2311 |
and '/usr/lib' asFilename baseName -> lib). |
|
2312 |
This method does not check if the path is valid |
|
2313 |
||
2911 | 2314 |
See also: #pathName, #directoryName and #directoryPathName. |
2315 |
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
|
2316 |
|
2922 | 2317 |
|len index sep endIdx| |
2318 |
||
2319 |
sep := self separator. |
|
2320 |
len := nameString size. |
|
2321 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
2322 |
^ nameString |
|
2323 |
]. |
|
2324 |
||
2325 |
endIdx := len. |
|
2326 |
len > 1 ifTrue:[ |
|
2327 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
|
2328 |
]. |
|
2329 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
2330 |
index == 0 ifTrue:[ |
|
2331 |
^ nameString copyTo:endIdx |
|
2332 |
]. |
|
2333 |
^ 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
|
2334 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2335 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2336 |
'/foo/bar' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2337 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2338 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2339 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2340 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2341 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2342 |
'../../libbasic/Object.st' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2343 |
" |
2012 | 2344 |
|
2922 | 2345 |
"Modified: 13.9.1997 / 09:32:49 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2346 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2347 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2348 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2349 |
"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
|
2350 |
- 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
|
2351 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2352 |
(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
|
2353 |
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
|
2354 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2355 |
^ self directoryName asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2356 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2357 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2358 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2359 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2360 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2361 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2362 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2363 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2364 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2365 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2366 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2367 |
"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
|
2368 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2369 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2370 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2371 |
"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
|
2372 |
- 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
|
2373 |
the receiver is contained in. |
2922 | 2374 |
This method does not check if the path is valid. |
2375 |
||
2376 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
2377 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
2378 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2379 |
(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
|
2380 |
a string instead of a Filename instance). |
2922 | 2381 |
|
2012 | 2382 |
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
|
2383 |
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
|
2384 |
|
2922 | 2385 |
|last index sep sepString p| |
2386 |
||
2387 |
sep := self separator. |
|
2388 |
sepString := sep asString. |
|
2389 |
(nameString = sepString) ifTrue:[ |
|
2390 |
"/ |
|
2391 |
"/ the trivial '/' case |
|
2392 |
"/ |
|
2393 |
^ nameString |
|
2394 |
]. |
|
2395 |
||
2396 |
"/ |
|
2397 |
"/ strip off multiple leading slashes |
|
2398 |
"/ |
|
2399 |
p := nameString. |
|
2400 |
[p endsWith:sepString] whileTrue:[ |
|
2401 |
(p = sepString) ifTrue:[ |
|
2402 |
^ p |
|
2403 |
]. |
|
2404 |
p := p copyWithoutLast:1 |
|
2405 |
]. |
|
2406 |
||
2407 |
last := 1. |
|
2408 |
[true] whileTrue:[ |
|
2409 |
index := p indexOf:sep startingAt:(last + 1). |
|
2410 |
index == 0 ifTrue:[ |
|
2411 |
(last == 1) ifTrue:[ |
|
2412 |
(p startsWith:sepString) ifTrue:[ |
|
2413 |
^ sepString |
|
2414 |
]. |
|
2415 |
^ '.' |
|
2416 |
]. |
|
2417 |
^ p copyTo:(last - 1) |
|
2418 |
]. |
|
2419 |
last := index. |
|
2420 |
]. |
|
2421 |
||
2422 |
"/ notreached |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2423 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2424 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2425 |
'/foo/bar/' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2426 |
'/foo/bar/' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2427 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2428 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2429 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2430 |
'bitmaps' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2431 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2432 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2433 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2434 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2435 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2436 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2437 |
"Modified: 7.9.1995 / 10:42:03 / claus" |
2012 | 2438 |
"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
|
2439 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2440 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2441 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2442 |
"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
|
2443 |
- 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
|
2444 |
the receiver is contained in. |
2012 | 2445 |
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
|
2446 |
|
2922 | 2447 |
^ self pathName asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2448 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2449 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2450 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2451 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2452 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2453 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2454 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2455 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2456 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2457 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2458 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2459 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2460 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2461 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2462 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2463 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2464 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 2465 |
"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
|
2466 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2467 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2468 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2469 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2470 |
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
|
2471 |
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
|
2472 |
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
|
2473 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2474 |
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
|
2475 |
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
|
2476 |
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
|
2477 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2478 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2479 |
|
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 |
'mak' asFilename filenameCompletion |
1517 | 2482 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2483 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2484 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2485 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2486 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2487 |
|
1517 | 2488 |
"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
|
2489 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2490 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2491 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2492 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2493 |
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
|
2494 |
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
|
2495 |
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
|
2496 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2497 |
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
|
2498 |
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
|
2499 |
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
|
2500 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2501 |
|dir baseName matching matchLen try allMatching |
3666 | 2502 |
sepString parentString prefix nMatch nm| |
2503 |
||
2504 |
nm := self nameWithSpecialExpansions:nameString. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2505 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2506 |
sepString := self class separator asString. |
3666 | 2507 |
(nm endsWith:sepString) ifTrue:[ |
2906 | 2508 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2509 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2510 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2511 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2512 |
baseName := self baseName. |
3666 | 2513 |
baseName ~= nm ifTrue:[ |
2906 | 2514 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2515 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2516 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2517 |
self isAbsolute ifTrue:[ |
2906 | 2518 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2519 |
] ifFalse:[ |
2906 | 2520 |
aDirectory isNil ifTrue:[ |
2521 |
dir := self directory |
|
2522 |
] ifFalse:[ |
|
3666 | 2523 |
dir := (aDirectory construct:nm) directory |
2906 | 2524 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2525 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2526 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2527 |
matching := OrderedCollection new. |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2528 |
dir class errorReporter openErrorSignal handle:[:ex| |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2529 |
^ #(). |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2530 |
] do:[ |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2531 |
dir directoryContents do:[:fileName | |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2532 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2533 |
(fileName startsWith:baseName) ifTrue:[ |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2534 |
matching add:fileName |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2535 |
] |
2906 | 2536 |
] |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2537 |
]. |
1049
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 |
(nMatch := matching size) > 1 ifTrue:[ |
2906 | 2540 |
" |
2541 |
find the longest common prefix |
|
2542 |
" |
|
2543 |
matchLen := baseName size. |
|
2544 |
matchLen > matching first size ifTrue:[ |
|
2545 |
try := baseName. |
|
2546 |
allMatching := false |
|
2547 |
] ifFalse:[ |
|
2548 |
try := matching first copyTo:matchLen. |
|
2549 |
allMatching := true. |
|
2550 |
]. |
|
2551 |
||
2552 |
[allMatching] whileTrue:[ |
|
2553 |
matching do:[:aName | |
|
2554 |
(aName startsWith:try) ifFalse:[ |
|
2555 |
allMatching := false |
|
2556 |
] |
|
2557 |
]. |
|
2558 |
allMatching ifTrue:[ |
|
2559 |
matchLen < matching first size ifTrue:[ |
|
2560 |
matchLen := matchLen + 1. |
|
2561 |
try := matching first copyTo:matchLen. |
|
2562 |
] ifFalse:[ |
|
2563 |
allMatching := false |
|
2564 |
] |
|
2565 |
] ifFalse:[ |
|
2566 |
try := matching first copyTo:matchLen - 1. |
|
2567 |
] |
|
2568 |
]. |
|
2569 |
" |
|
2570 |
and set my name to the last full match |
|
2571 |
" |
|
3666 | 2572 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2573 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2574 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2575 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2576 |
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
|
2577 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2578 |
prefix notNil ifTrue:[ |
2906 | 2579 |
prefix = sepString ifTrue:[ |
2580 |
"/ avoid introducing double slashes |
|
2581 |
prefix := '' |
|
2582 |
]. |
|
2583 |
matching := matching collect:[:n | prefix , sepString , n]. |
|
2584 |
nMatch == 1 ifTrue:[ |
|
3666 | 2585 |
nameString := nm := matching first |
2906 | 2586 |
] ifFalse:[ |
2587 |
nMatch > 1 ifTrue:[ |
|
3666 | 2588 |
nameString := nm := prefix , sepString , nm |
2906 | 2589 |
] |
2590 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2591 |
] ifFalse:[ |
2906 | 2592 |
nMatch == 1 ifTrue:[ |
3666 | 2593 |
nameString := nm := matching first |
2906 | 2594 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2595 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2596 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2597 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2598 |
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
|
2599 |
(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
|
2600 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2601 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2602 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2603 |
" trivial cases: |
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 |
'../' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2606 |
'/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2607 |
'/usr/' asFilename filenameCompletion |
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 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2610 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2611 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2612 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2613 |
'../../libpr' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2614 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2615 |
|
3666 | 2616 |
"Modified: / 22.9.1997 / 18:03:33 / stefan" |
3752 | 2617 |
"Modified: / 12.8.1998 / 13:02:16 / cg" |
2903 | 2618 |
! |
2619 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2620 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2621 |
"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
|
2622 |
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
|
2623 |
(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
|
2624 |
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
|
2625 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2626 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2627 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2628 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2629 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2630 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2631 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2632 |
" |
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 |
"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
|
2635 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2636 |
|
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2637 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2638 |
"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
|
2639 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2640 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2641 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2642 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2643 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
2644 |
|
615 | 2645 |
name |
2646 |
"return the name of the file represented by the receiver as a string. |
|
883 | 2647 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 2648 |
See also: pathName" |
174 | 2649 |
|
615 | 2650 |
self isAbsolute ifTrue:[^ self pathName]. |
2651 |
^ nameString |
|
174 | 2652 |
|
2653 |
" |
|
615 | 2654 |
'/foo/bar' asFilename name |
2655 |
'/foo/bar' asFilename pathName |
|
2656 |
'.' asFilename name |
|
2657 |
'.' asFilename pathName |
|
2658 |
'../..' asFilename name |
|
883 | 2659 |
'../..' asFilename pathName |
615 | 2660 |
'bitmaps' asFilename name |
2661 |
'bitmaps' asFilename pathName |
|
2662 |
'/tmp/../usr' asFilename name |
|
883 | 2663 |
'/tmp/../usr' asFilename pathName |
2664 |
'source/..' asFilename name |
|
2665 |
'source/..' asFilename pathName |
|
2666 |
'/tmp/..' asFilename name |
|
2667 |
'/tmp/..' asFilename pathName |
|
92 | 2668 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2669 |
|
883 | 2670 |
"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
|
2671 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2672 |
|
615 | 2673 |
pathName |
2674 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 2675 |
as a string. This will not include ..'s. |
2676 |
If the path represented by the receiver does NOT represent a valid path, |
|
2677 |
no compression will be done (for now; this may change). |
|
2678 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2679 |
|
1317 | 2680 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2681 |
|
1317 | 2682 |
"/ sep := self class separator. |
2683 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
2684 |
"/ parentName := self class parentDirectoryName. |
|
2685 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
2686 |
"/ ^ nameString |
|
2687 |
"/ ] |
|
2688 |
"/ ]. |
|
2689 |
p := OperatingSystem pathNameOf:nameString. |
|
2690 |
^ p |
|
2 | 2691 |
|
92 | 2692 |
" |
1317 | 2693 |
'/foo/bar' asFilename pathName |
2694 |
'.' asFilename pathName |
|
2695 |
'../..' asFilename pathName |
|
2696 |
'../..' asFilename name |
|
2697 |
'/tmp/../usr' asFilename pathName |
|
2698 |
'/././usr' asFilename pathName |
|
92 | 2699 |
" |
159 | 2700 |
|
1317 | 2701 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 2702 |
! |
2703 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2704 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2705 |
"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
|
2706 |
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
|
2707 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2708 |
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
|
2709 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2710 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2711 |
|t target path| |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2712 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2713 |
self isSymbolicLink ifFalse:[ |
2629 | 2714 |
self exists ifFalse:[^ nil]. |
2715 |
^ self pathName |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2716 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2717 |
t := self. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2718 |
[t isSymbolicLink] whileTrue:[ |
2629 | 2719 |
path := t linkInfo path. |
2720 |
path isNil ifTrue:[ |
|
2721 |
"/ cannot happen |
|
2722 |
^ nil |
|
2723 |
]. |
|
2724 |
target := t directoryName asFilename construct:path. |
|
2725 |
target exists ifFalse:[^ nil]. |
|
2726 |
t := target asFilename |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2727 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2728 |
t exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2729 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2730 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2731 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2732 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2733 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2734 |
'../..' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2735 |
'include/abbrev.stc' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2736 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2737 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2738 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2739 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2740 |
|
615 | 2741 |
tail |
2742 |
"the files name without directory prefix as a string. |
|
2743 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 2744 |
|
615 | 2745 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2746 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2747 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2748 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2749 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2750 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2751 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2752 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2753 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 2754 |
! |
2755 |
||
2756 |
volume |
|
2757 |
"return the disc volume part of the name or an empty string. |
|
2906 | 2758 |
This is only used with MSDOS and VMS filenames |
2759 |
- by default (and on unix), an empty string is returned" |
|
2760 |
||
2629 | 2761 |
^ '' |
2906 | 2762 |
|
2763 |
"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
|
2764 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2765 |
|
2922 | 2766 |
!Filename methodsFor:'special accessing'! |
2767 |
||
3665 | 2768 |
nameWithSpecialExpansions:aString |
2769 |
"return the nameString, expanding any OS specific |
|
2770 |
macros. This should be redefined for OS's where such macros |
|
2771 |
are common. |
|
2772 |
On unix, a ~/ prefix is expanded to the users home dir (as in csh)" |
|
2773 |
||
2774 |
^ aString |
|
2775 |
||
2776 |
"Modified: / 21.7.1998 / 10:43:20 / cg" |
|
2777 |
"Created: / 21.7.1998 / 10:45:58 / cg" |
|
2778 |
! |
|
2779 |
||
2922 | 2780 |
osName |
2781 |
"special - return the OS's name for the receiver." |
|
2782 |
||
2783 |
self isDirectory ifTrue:[ |
|
2784 |
^ self osNameForDirectory |
|
2785 |
]. |
|
2786 |
^ self osNameForFile |
|
2787 |
! |
|
2788 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2789 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2790 |
"internal - return the OS's name for the receiver to |
3665 | 2791 |
access its fileInfo. |
2792 |
This may be redefined for systems, where a special suffix must be |
|
2793 |
added in order to access directories (or others) as a file. |
|
2794 |
(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
|
2795 |
|
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2796 |
^ nameString |
3665 | 2797 |
|
2798 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2799 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
2800 |
|
2922 | 2801 |
osNameForDirectory |
3753 | 2802 |
"internal - return the OS's name for the receiver to |
2922 | 2803 |
access it as a directory." |
2804 |
||
2805 |
^ nameString |
|
3753 | 2806 |
|
2807 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 2808 |
! |
2809 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2810 |
osNameForDirectoryContents |
3753 | 2811 |
"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
|
2812 |
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
|
2813 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2814 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2815 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2816 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 2817 |
"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
|
2818 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
2819 |
|
2922 | 2820 |
osNameForFile |
2821 |
"internal - return the OS's name for the receiver to |
|
2822 |
access it as a file." |
|
2823 |
||
2824 |
^ nameString |
|
2825 |
! ! |
|
2826 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2827 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2828 |
|
2906 | 2829 |
hasSuffix:aSuffixString |
2830 |
"return true if my suffix is the same as aString. |
|
2831 |
This cares for systems, where case is ignored in filenames" |
|
2832 |
||
2833 |
|mySuffix| |
|
2834 |
||
2835 |
mySuffix := self suffix. |
|
2836 |
self class isCaseSensitive ifTrue:[ |
|
2837 |
^ mySuffix = aSuffixString |
|
2838 |
]. |
|
2839 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
2840 |
||
2841 |
" |
|
2842 |
'abc.st' asFilename hasSuffix:'st' |
|
2843 |
'abc.ST' asFilename hasSuffix:'st' |
|
2844 |
" |
|
2845 |
||
2846 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
2847 |
! |
|
2848 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2849 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2850 |
"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
|
2851 |
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
|
2852 |
the prefix everything before, except for the period. |
1517 | 2853 |
The directory name part is stripped off (i.e. the returned prefix |
2854 |
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
|
2855 |
(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
|
2856 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
1517 | 2857 |
See also: #withoutSuffix and #withSuffix |
2858 |
Notice: |
|
2629 | 2859 |
there is currently no known system which uses other than |
2860 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2861 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2862 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2863 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2864 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2865 |
idx := nm lastIndexOf:(self class suffixSeparator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2866 |
idx == 0 ifTrue:[ |
2629 | 2867 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2868 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2869 |
^ Array |
2629 | 2870 |
with:(nm copyTo:idx-1) |
2871 |
with:(nm copyFrom:idx+1) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2872 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2873 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2874 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2875 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2876 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 2877 |
'/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
|
2878 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2879 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2880 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 2881 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2882 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2883 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2884 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 2885 |
"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
|
2886 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2887 |
|
2906 | 2888 |
suffix |
2889 |
"return my suffix. |
|
2890 |
The suffix is the namepart after the final period character, |
|
2891 |
or the empty string, if the name does not contain a period." |
|
2892 |
||
2893 |
^ self prefixAndSuffix at:2 |
|
2894 |
||
2895 |
" |
|
2896 |
'abc.st' asFilename suffix |
|
2897 |
'abc' asFilename suffix |
|
2898 |
'a.b.c' asFilename suffix |
|
2899 |
" |
|
2900 |
||
2901 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
2902 |
! |
|
2903 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2904 |
withSuffix:aSuffix |
2922 | 2905 |
"return a new filename for the receivers name with a different suffix. |
1993 | 2906 |
If the name already has a suffix, the new suffix replacaes it; |
2907 |
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
|
2908 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2909 |
^ self class named: |
2629 | 2910 |
(self withoutSuffix name |
2911 |
, self class suffixSeparator asString |
|
2912 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2913 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2914 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2915 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2916 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2917 |
'a.b.c' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2918 |
'/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
|
2919 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 2920 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 2921 |
'/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
|
2922 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2923 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2924 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1993 | 2925 |
"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
|
2926 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2927 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2928 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2929 |
"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
|
2930 |
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
|
2931 |
|
2922 | 2932 |
|nm idx| |
2933 |
||
2934 |
nm := self baseName. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2935 |
idx := nameString lastIndexOf:(self class suffixSeparator). |
2922 | 2936 |
(idx == 0) ifTrue:[^ self]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2937 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2938 |
^ 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
|
2939 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2940 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2941 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2942 |
'abc' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2943 |
'a.b.c' asFilename withoutSuffix |
1516 | 2944 |
'/foo/bar/baz.c' asFilename withoutSuffix |
2945 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
|
2946 |
'/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
|
2947 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2948 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2949 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1516 | 2950 |
"Modified: 3.7.1996 / 10:49:58 / cg" |
174 | 2951 |
! ! |
2952 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2953 |
!Filename class methodsFor:'documentation'! |
630 | 2954 |
|
2955 |
version |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
2956 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.130 1998-08-14 16:19:03 cg Exp $' |
630 | 2957 |
! ! |
2906 | 2958 |
Filename initialize! |