author | Claus Gittinger <cg@exept.de> |
Mon, 21 Apr 1997 15:02:48 +0200 | |
changeset 2573 | 6545b4c31872 |
parent 2566 | e134970f84ab |
child 2589 | 06c8700d437d |
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' |
15 |
classVariableNames:'NextTempFilenameIndex' |
|
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 |
||
1286 | 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 |
||
1286 | 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. |
|
64 |
Especially the path-construction methods (i.e. #construct:) is highly |
|
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:] |
69 |
Claus Gittinger |
|
276 | 70 |
|
1286 | 71 |
[see also:] |
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 |
||
1317 | 83 |
|f| |
360 | 84 |
|
1317 | 85 |
f := 'foobar' asFilename. |
86 |
^ f exists |
|
360 | 87 |
|
88 |
||
89 |
is it a directory ?: |
|
90 |
||
1317 | 91 |
|f| |
360 | 92 |
|
1317 | 93 |
f := '/tmp' asFilename. |
94 |
^ f isDirectory. |
|
360 | 95 |
|
96 |
||
97 |
get the working directory: |
|
98 |
||
1317 | 99 |
^ Filename defaultDirectory |
360 | 100 |
|
101 |
||
102 |
get a files full pathname |
|
103 |
(caring for relative names or symbolic links): |
|
104 |
||
1317 | 105 |
|f| |
360 | 106 |
|
1317 | 107 |
f := '..' asFilename. |
108 |
^ f pathName |
|
360 | 109 |
|
110 |
||
111 |
get a directories directory: |
|
112 |
||
1317 | 113 |
|f| |
360 | 114 |
|
1317 | 115 |
f := Filename defaultDirectory. |
116 |
^ f directory |
|
360 | 117 |
|
118 |
||
119 |
get a files directory: |
|
120 |
||
1317 | 121 |
|f| |
360 | 122 |
|
1317 | 123 |
f := './smalltalk' asFilename. |
124 |
^ f directory |
|
360 | 125 |
|
126 |
||
127 |
getting access & modification times: |
|
128 |
||
129 |
||
1317 | 130 |
|f| |
360 | 131 |
|
1317 | 132 |
f := '/tmp' asFilename. |
133 |
^ f dates |
|
360 | 134 |
|
135 |
access time only: |
|
136 |
||
1317 | 137 |
|f| |
360 | 138 |
|
1317 | 139 |
f := '/tmp' asFilename. |
140 |
^ f dates at:#accessed |
|
360 | 141 |
|
142 |
||
143 |
getting all information on a file/directory: |
|
144 |
||
145 |
||
1317 | 146 |
|f| |
360 | 147 |
|
1317 | 148 |
f := '/tmp' asFilename. |
149 |
^ f info |
|
360 | 150 |
|
151 |
||
152 |
getting a temporary file (unique name): |
|
153 |
||
1317 | 154 |
|f| |
360 | 155 |
|
1317 | 156 |
f := Filename newTemporary. |
157 |
^ f |
|
360 | 158 |
|
159 |
||
160 |
creating, writing, reading and removing a temporary file: |
|
1317 | 161 |
[exBegin] |
162 |
|f writeStream readStream| |
|
360 | 163 |
|
1317 | 164 |
f := Filename newTemporary. |
165 |
writeStream := f writeStream. |
|
166 |
writeStream nextPutAll:'hello world'. |
|
167 |
writeStream cr. |
|
168 |
writeStream close. |
|
360 | 169 |
|
1317 | 170 |
'contents (as seen by unix''s cat command:' printNL. |
171 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
360 | 172 |
|
1317 | 173 |
readStream := f readStream. |
1422 | 174 |
Transcript showCR:'contents as seen by smalltalk:'. |
175 |
Transcript showCR:(readStream upToEnd). |
|
1317 | 176 |
readStream close. |
360 | 177 |
|
1317 | 178 |
f delete. |
179 |
[exEnd] |
|
360 | 180 |
|
181 |
||
182 |
getting a directories contents: |
|
1317 | 183 |
[exBegin] |
184 |
|f files| |
|
360 | 185 |
|
1317 | 186 |
f := '.' asFilename. |
187 |
files := f directoryContents. |
|
1422 | 188 |
Transcript showCR:'the files are:'. |
189 |
Transcript showCR:(files printString). |
|
1317 | 190 |
[exEnd] |
360 | 191 |
|
192 |
||
193 |
editing a file: |
|
1317 | 194 |
[exBegin] |
195 |
|f| |
|
360 | 196 |
|
1317 | 197 |
f := '/tmp/fooBar' asFilename. |
198 |
(f writeStream) nextPutAll:'hello world'; close. |
|
360 | 199 |
|
1317 | 200 |
f edit |
201 |
[exEnd] |
|
360 | 202 |
" |
88 | 203 |
! ! |
1 | 204 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
205 |
!Filename class methodsFor:'instance creation'! |
1 | 206 |
|
276 | 207 |
currentDirectory |
208 |
"return a filename for the current directory" |
|
209 |
||
2550 | 210 |
^ self named:('.' asFilename pathName) |
276 | 211 |
|
212 |
" |
|
213 |
Filename currentDirectory |
|
214 |
" |
|
2550 | 215 |
|
216 |
"Modified: 15.4.1997 / 13:22:46 / cg" |
|
276 | 217 |
! |
218 |
||
328 | 219 |
defaultDirectory |
220 |
"ST80 compatibility: same as currentDirectory" |
|
221 |
||
222 |
^ self currentDirectory |
|
223 |
||
224 |
" |
|
225 |
Filename defaultDirectory |
|
226 |
" |
|
227 |
! |
|
228 |
||
542 | 229 |
defaultDirectoryName |
230 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
|
231 |
||
232 |
^ self defaultDirectory name |
|
233 |
||
234 |
" |
|
235 |
Filename defaultDirectoryName |
|
236 |
" |
|
237 |
! |
|
238 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
239 |
fromComponents:aCollectionOfDirectoryNames |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
240 |
"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
|
241 |
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
|
242 |
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
|
243 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
244 |
|sep s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
245 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
246 |
sep := self separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
247 |
s := ''. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
248 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
249 |
index == 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
250 |
(component ~= sep |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
251 |
or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
252 |
s := s , component |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
253 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
254 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
255 |
s := s , '/' , component |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
256 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
257 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
258 |
^ self named:s |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
259 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
260 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
261 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
262 |
Filename fromComponents:#('foo' 'bar' 'baz') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
263 |
Filename fromComponents:#('/') |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
264 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
265 |
Filename fromComponents: |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
266 |
(Filename components:('.' asFilename pathName)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
267 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
268 |
Filename fromComponents: |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
269 |
(Filename components:('.' asFilename name)) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
270 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
271 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
272 |
"Modified: 29.2.1996 / 20:18:34 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
273 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
274 |
|
615 | 275 |
fromUser |
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
276 |
"show a box to enter a filename. |
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
277 |
Return a filename instance or nil (if cancel was pressed)." |
615 | 278 |
|
279 |
|name| |
|
280 |
||
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
281 |
name := Dialog requestFileName:'filename:' ifFail:nil. |
615 | 282 |
name notNil ifTrue:[^ self named:name]. |
283 |
^ nil |
|
284 |
||
285 |
" |
|
286 |
Filename fromUser |
|
287 |
" |
|
1225
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
288 |
|
b7def4d21cb8
use dialogs new requestFileName
Claus Gittinger <cg@exept.de>
parents:
1120
diff
changeset
|
289 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
615 | 290 |
! |
291 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
292 |
homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
293 |
"return your homeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
294 |
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
|
295 |
(which is the currentDirectory) is returned." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
296 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
297 |
|s| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
298 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
299 |
s := OperatingSystem getHomeDirectory. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
300 |
s isNil ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
301 |
^ self defaultDirectory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
302 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
303 |
^ s asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
304 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
305 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
306 |
Filename homeDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
307 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
308 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
309 |
"Modified: 29.2.1996 / 21:00:31 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
310 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
311 |
|
615 | 312 |
named:aString |
313 |
"return a filename for a directory named aString. |
|
314 |
This is the same as 'aString asFilename'." |
|
315 |
||
316 |
^ (self basicNew) setName:aString |
|
317 |
||
318 |
" |
|
319 |
Filename named:'/tmp/fooBar' |
|
320 |
" |
|
321 |
! |
|
322 |
||
276 | 323 |
newTemporary |
325 | 324 |
"return a new unique filename - use this for temporary files. |
325 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
326 |
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
|
327 |
call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
328 |
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
|
329 |
its value defines the temp directory." |
276 | 330 |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
331 |
^ self newTemporaryIn:self tempDirectory pathName |
276 | 332 |
|
333 |
" |
|
422 | 334 |
Filename newTemporary |
1080 | 335 |
Filename newTemporary |
276 | 336 |
" |
422 | 337 |
|
338 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
339 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
340 |
! |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
341 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
342 |
newTemporaryIn:aDirectoryPrefix |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
343 |
"return a new unique filename - use this for temporary files. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
344 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
345 |
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
|
346 |
with every call to this method. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
347 |
Notice: only a filename object is created and returned - no physical |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
348 |
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
|
349 |
whatever to it in order to really create something). |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
350 |
See also: #newTemporary which looks for a good temp directory." |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
351 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
352 |
|pid nm| |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
353 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
354 |
NextTempFilenameIndex isNil ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
355 |
NextTempFilenameIndex := 1. |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
356 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
357 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
358 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
359 |
the following has to be made OS independent ... |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
360 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
361 |
pid := OperatingSystem getProcessId printString. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
362 |
nm := 'stxtmp_' , pid , '_' , NextTempFilenameIndex printString. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
363 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
364 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
365 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
366 |
nm := aDirectoryPrefix asFilename construct:nm |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
367 |
] ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
368 |
nm := nm asFilename |
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
369 |
]. |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
370 |
^ nm |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
371 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
372 |
"temp files in '/tmp': |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
373 |
|
1080 | 374 |
Filename newTemporary |
375 |
" |
|
376 |
||
377 |
"temp files somewhere |
|
378 |
(not recommended - use above since it can be controlled via shell variables): |
|
379 |
||
483
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
380 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
381 |
Filename newTemporaryIn:'/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
382 |
Filename newTemporaryIn:'/usr/tmp' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
383 |
Filename newTemporaryIn:'/' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
384 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
385 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
386 |
"a local temp file: |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
387 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
388 |
Filename newTemporaryIn:'' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
389 |
Filename newTemporaryIn:nil |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
390 |
Filename newTemporaryIn:'.' |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
391 |
Filename newTemporaryIn:('source' asFilename) |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
392 |
" |
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
393 |
|
f36d0167b819
newTemporyary and newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
473
diff
changeset
|
394 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
1080 | 395 |
"Modified: 7.3.1996 / 14:49:56 / cg" |
396 |
! |
|
397 |
||
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
398 |
tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
399 |
"return the temp directory as a filename. |
1968 | 400 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
401 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
402 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
403 |
|
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
404 |
Notice: do not hardcode '/tmp' into your programs - things may be |
1968 | 405 |
different on other OS's. Also, the user may want to set the |
406 |
TMPDIR environment variable to have her temp files somewhere else. |
|
407 |
(especially on SUNOS, the root partition is ALWAYS too small ..." |
|
1080 | 408 |
|
409 |
|tempDir| |
|
410 |
||
1969 | 411 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
1968 | 412 |
tempDir isNil ifTrue:[ |
413 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
414 |
]. |
|
415 |
]. |
|
1080 | 416 |
tempDir isNil ifTrue:[ |
1968 | 417 |
tempDir := '/tmp' |
1080 | 418 |
]. |
419 |
^ self named:tempDir |
|
420 |
||
421 |
" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
422 |
Filename tempDirectory |
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
423 |
Filename tempDirectory pathName |
1080 | 424 |
" |
425 |
||
426 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1081
c2f1f8441663
renamed #temporaryDirectory to #tempDirectory
Claus Gittinger <cg@exept.de>
parents:
1080
diff
changeset
|
427 |
"Created: 7.3.1996 / 14:51:18 / cg" |
1969 | 428 |
"Modified: 12.11.1996 / 12:23:19 / cg" |
1 | 429 |
! ! |
430 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
431 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
432 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
433 |
concreteClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
434 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
435 |
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
|
436 |
OperatingSystems; concreteClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
437 |
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
|
438 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
439 |
^ self |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
440 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
441 |
"Created: 14.2.1997 / 16:36:13 / cg" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
442 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
443 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
444 |
defaultClass |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
445 |
"ST-80 compatibility: |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
446 |
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
|
447 |
OperatingSystems; defaultClass is supposed to return an appropriate class. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
448 |
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
|
449 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
450 |
^ self |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
451 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
452 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
453 |
isCaseSensitive |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
454 |
"return true, if filenames are case sensitive. |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
455 |
We ask the OS about this, to be independent here." |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
456 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
457 |
^ OperatingSystem caseSensitiveFilenames |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
458 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
459 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
460 |
!Filename class methodsFor:'queries'! |
2 | 461 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
462 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
463 |
"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
|
464 |
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
|
465 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
|
2503 | 469 |
|sep components| |
470 |
||
471 |
sep := self separator. |
|
472 |
components := aString asCollectionOfSubstringsSeparatedBy:sep. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
473 |
components first isEmpty ifTrue:[ |
2503 | 474 |
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
|
475 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
476 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
477 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
478 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
479 |
Filename components:'/foo/bar/baz' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
480 |
Filename components:'foo/bar/baz' |
2503 | 481 |
Filename components:'foo/bar' |
482 |
Filename components:'foo' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
483 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
484 |
|
2503 | 485 |
"Modified: 26.3.1997 / 18:27:04 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
486 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
487 |
|
1523 | 488 |
errorReporter |
489 |
"who knows the signals to report errors?" |
|
490 |
||
491 |
^ FileStream |
|
492 |
||
493 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
494 |
! |
|
495 |
||
440 | 496 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
497 |
"perform filename completion on aString in some directory; |
|
498 |
return the longest matching filename prefix as a string. |
|
1318 | 499 |
The boolean directoriesOnly and filesOnly control respectively, |
500 |
if only directories or only regular files are to be considered for completion. |
|
501 |
If multiple files match, the exception block aBlock is evaluated with a |
|
502 |
filename representing the directory (where the match was done) as argument. |
|
440 | 503 |
(this may be different from the inDirectory argument, if aString is absolute |
504 |
or starts with ../)" |
|
505 |
||
506 |
|s f matchSet nMatch name words dir| |
|
507 |
||
508 |
s := aString. |
|
509 |
" |
|
510 |
find the last word ... |
|
511 |
" |
|
512 |
words := s asCollectionOfWords. |
|
513 |
words size == 0 ifTrue:[ |
|
1318 | 514 |
aBlock value:'.' asFilename. |
515 |
^ '' |
|
440 | 516 |
]. |
517 |
||
518 |
f := words last asFilename. |
|
519 |
||
520 |
matchSet := f filenameCompletionIn:inDirectory. |
|
521 |
||
522 |
dir := f directory. |
|
523 |
||
524 |
directoriesOnly ifTrue:[ |
|
1318 | 525 |
matchSet := matchSet select:[:aFilename | |
526 |
(dir construct:aFilename) isDirectory |
|
527 |
]. |
|
440 | 528 |
] ifFalse:[ |
1318 | 529 |
filesOnly ifTrue:[ |
530 |
matchSet := matchSet select:[:aFilename | |
|
531 |
(dir construct:aFilename) isDirectory not |
|
532 |
]. |
|
533 |
] |
|
440 | 534 |
]. |
535 |
||
536 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
|
1318 | 537 |
" |
538 |
more than one possible completion - |
|
539 |
" |
|
540 |
aBlock value:f |
|
440 | 541 |
]. |
542 |
" |
|
543 |
even with more than one possible completion, |
|
544 |
f's name is now the common prefix |
|
545 |
" |
|
546 |
name := f asString. |
|
547 |
nMatch == 1 ifTrue:[ |
|
1318 | 548 |
" |
549 |
exactly one possible completion - |
|
550 |
" |
|
551 |
f := dir construct:matchSet first. |
|
440 | 552 |
|
1318 | 553 |
directoriesOnly ifFalse:[ |
554 |
f isDirectory ifTrue:[ |
|
555 |
(name endsWith:(Filename separator)) ifFalse:[ |
|
556 |
name := name , '/' |
|
557 |
]. |
|
558 |
]. |
|
559 |
] |
|
440 | 560 |
]. |
561 |
||
562 |
" |
|
563 |
construct new contents, by taking |
|
564 |
last words completion |
|
565 |
" |
|
566 |
s := ''. |
|
567 |
1 to:(words size - 1) do:[:idx | |
|
1318 | 568 |
s := s , (words at:idx) , ' ' |
440 | 569 |
]. |
570 |
s := s , name. |
|
571 |
||
572 |
"/ special: if there was no change, and the string represented |
|
573 |
"/ is a directories name, add a directory separator |
|
574 |
s = aString ifTrue:[ |
|
1318 | 575 |
(s endsWith:Filename separator) ifFalse:[ |
576 |
s asFilename isDirectory ifTrue:[ |
|
577 |
^ s , Filename separator asString |
|
578 |
] |
|
579 |
] |
|
440 | 580 |
]. |
581 |
||
582 |
^ s |
|
1318 | 583 |
|
584 |
"Modified: 30.4.1996 / 12:13:20 / cg" |
|
615 | 585 |
! |
586 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
587 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
588 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
589 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
590 |
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
|
591 |
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
|
592 |
The returned strings are the expanded names, in the same form |
2550 | 593 |
as given in pattern. |
594 |
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
|
595 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
596 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
597 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
598 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
599 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
600 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
601 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
602 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
603 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
604 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
605 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
606 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
607 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
608 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
609 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
610 |
|
2550 | 611 |
"Modified: 15.4.1997 / 15:42:37 / cg" |
615 | 612 |
! |
613 |
||
614 |
localNameStringFrom:aString |
|
615 |
"ST-80 compatibility. |
|
616 |
what does this do ? (used in FileNavigator-goody). |
|
617 |
GUESS: does it strip off the voulume-character on MSDOS systems ?" |
|
618 |
||
619 |
(aString startsWith:'/') ifTrue:[ |
|
620 |
^ aString copyFrom:2 |
|
621 |
]. |
|
622 |
^ aString |
|
623 |
||
624 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
625 |
! |
|
626 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
627 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
628 |
"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
|
629 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
630 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
631 |
^ OperatingSystem maxFileNameLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
632 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
633 |
"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
|
634 |
"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
|
635 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
636 |
|
615 | 637 |
parentDirectoryName |
638 |
"return the name used for the parent directory. |
|
639 |
This is '..' for unix and dos-like systems. |
|
640 |
(there may be more in the future." |
|
641 |
||
642 |
^ OperatingSystem parentDirectoryName |
|
643 |
||
644 |
" |
|
645 |
Filename parentDirectoryName |
|
646 |
" |
|
647 |
! |
|
648 |
||
649 |
separator |
|
650 |
"return the file/directory separator. |
|
651 |
Usually, this is $/ for unix-like systems |
|
652 |
and $\ for dos-like ones (there may be more in the future)." |
|
653 |
||
654 |
^ OperatingSystem fileSeparator |
|
655 |
||
656 |
" |
|
657 |
Filename separator |
|
658 |
" |
|
659 |
! |
|
660 |
||
661 |
suffixSeparator |
|
662 |
"return the filename suffix separator. |
|
663 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 664 |
(there is currently no known system, where this differs)" |
615 | 665 |
|
666 |
^ $. |
|
667 |
||
668 |
" |
|
669 |
Filename suffixSeparator |
|
670 |
" |
|
671 |
||
672 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 673 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 674 |
! |
675 |
||
676 |
volumes |
|
677 |
"ST-80 compatibility. |
|
2550 | 678 |
what does this do on Unix systems ? (used in FileNavigator-goody). |
615 | 679 |
GUESS: does it return the available drives on MSDOS systems ?" |
680 |
||
2550 | 681 |
OperatingSystem isMSDOSlike ifTrue:[ |
682 |
^ OperatingSystem getDriveList |
|
683 |
]. |
|
684 |
^ Array |
|
685 |
with:'/' |
|
686 |
with:(OperatingSystem getHomeDirectory) |
|
687 |
with:(Filename currentDirectory pathName) |
|
688 |
"/ ^ #('/') |
|
615 | 689 |
|
690 |
"Modified: 7.9.1995 / 10:45:25 / claus" |
|
2550 | 691 |
"Modified: 15.4.1997 / 13:25:21 / cg" |
615 | 692 |
! ! |
693 |
||
694 |
!Filename methodsFor:'comparing'! |
|
695 |
||
696 |
= aFilename |
|
697 |
"return true, if the argument represents the same filename" |
|
698 |
||
699 |
|str| |
|
700 |
||
701 |
self species == aFilename species ifTrue:[ |
|
702 |
str := aFilename asString. |
|
703 |
self class isCaseSensitive ifTrue:[ |
|
704 |
^ nameString = str |
|
705 |
]. |
|
706 |
^ nameString sameAs:str |
|
707 |
]. |
|
708 |
^ false |
|
709 |
! |
|
710 |
||
711 |
hash |
|
712 |
"return an integer useful as a hash-key" |
|
713 |
||
714 |
^ nameString hash |
|
715 |
! ! |
|
716 |
||
717 |
!Filename methodsFor:'converting'! |
|
718 |
||
719 |
asAbsoluteFilename |
|
720 |
"return the receiver converted to a filename with |
|
721 |
an absolute pathname." |
|
722 |
||
723 |
^ self pathName asFilename |
|
724 |
! |
|
725 |
||
726 |
asFilename |
|
1970 | 727 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 728 |
|
729 |
"Thats pretty easy here :-)" |
|
730 |
^ self |
|
1970 | 731 |
|
732 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 733 |
! |
734 |
||
735 |
asString |
|
736 |
"return the receiver converted to a string" |
|
737 |
||
738 |
^ nameString |
|
739 |
! |
|
740 |
||
741 |
makeLegalFilename |
|
1970 | 742 |
"convert the receivers name to be a legal filename. |
743 |
This removes/replaces invalid characters and/or compresses |
|
744 |
the name as required by the OS. |
|
615 | 745 |
The implementation may change in the future to be more |
746 |
OS specific." |
|
747 |
||
748 |
" |
|
749 |
actually, in Unix spaces are allowed - but it makes life |
|
750 |
so hard; therefore, replace them by underscores ... |
|
751 |
" |
|
752 |
nameString replaceAll:(Character space) by:$_. |
|
753 |
" |
|
754 |
need more - especially on SYS5.3 type systems, |
|
755 |
we may want to contract the fileName to 14 characters. |
|
756 |
" |
|
757 |
^ self |
|
758 |
||
759 |
" |
|
760 |
'hello world' asFilename makeLegalFilename |
|
761 |
" |
|
1970 | 762 |
|
763 |
"Modified: 12.11.1996 / 12:39:04 / cg" |
|
2 | 764 |
! ! |
765 |
||
542 | 766 |
!Filename methodsFor:'error handling'! |
767 |
||
615 | 768 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
769 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
770 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
771 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
772 |
|
615 | 773 |
^ OperatingSystem accessDeniedErrorSignal |
542 | 774 |
raiseRequestWith:filename |
615 | 775 |
errorString:('access denied: ' , filename asString) |
776 |
! |
|
777 |
||
778 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
779 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
780 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
781 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
782 |
|
615 | 783 |
^ OperatingSystem accessDeniedErrorSignal |
784 |
raiseRequestWith:filename |
|
785 |
errorString:('cannot create/write file: ' , filename asString) |
|
542 | 786 |
! |
787 |
||
788 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
789 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
790 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
791 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
792 |
|
542 | 793 |
^ OperatingSystem fileNotFoundErrorSignal |
794 |
raiseRequestWith:filename |
|
795 |
errorString:('file not found: ' , filename asString) |
|
796 |
! |
|
797 |
||
798 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
799 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
800 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
801 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
802 |
|
542 | 803 |
^ OperatingSystem accessDeniedErrorSignal |
804 |
raiseRequestWith:filename |
|
805 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 806 |
! |
807 |
||
808 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
809 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
810 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
811 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
812 |
|
615 | 813 |
^ OperatingSystem errorSignal |
814 |
raiseRequestWith:filename |
|
815 |
errorString:string |
|
816 |
! ! |
|
817 |
||
818 |
!Filename methodsFor:'file access'! |
|
819 |
||
820 |
appendingWriteStream |
|
821 |
"return a stream for appending to the file represented by the receiver. |
|
822 |
If the file does not already exist, it is created." |
|
823 |
||
824 |
^ FileStream appendingOldFileNamed:nameString |
|
825 |
! |
|
826 |
||
827 |
newReadWriteStream |
|
828 |
"return a stream for read/write the file represented by the receiver. |
|
829 |
If the file does not already exist, it is created." |
|
830 |
||
831 |
^ FileStream newFileNamed:nameString |
|
832 |
! |
|
833 |
||
834 |
readStream |
|
835 |
"return a stream for reading from the file represented by the receiver. |
|
836 |
If the file does not already exist, nil is returned." |
|
837 |
||
838 |
^ FileStream readonlyFileNamed:nameString |
|
839 |
||
840 |
" |
|
841 |
'/tmp/foo' asFilename readStream |
|
842 |
" |
|
843 |
! |
|
844 |
||
845 |
readWriteStream |
|
846 |
"return a stream for read/write the file represented by the receiver. |
|
847 |
If the file does not already exist, nil is returned." |
|
848 |
||
849 |
^ FileStream oldFileNamed:nameString |
|
850 |
! |
|
851 |
||
852 |
writeStream |
|
853 |
"return a stream for writing to the file represented by the receiver. |
|
854 |
If the file does not already exist, it is created." |
|
855 |
||
856 |
^ FileStream newFileForWritingNamed:nameString |
|
857 |
||
858 |
" |
|
859 |
'/tmp/foo' asFilename writeStream |
|
860 |
" |
|
861 |
! ! |
|
862 |
||
863 |
!Filename methodsFor:'file operations'! |
|
864 |
||
865 |
addAccessRights:aCollection |
|
866 |
"add the access rights as specified in aCollection for the file represented |
|
867 |
by the receiver. The argument must be a collection of symbols, |
|
868 |
such as #readUser, #writeGroup etc." |
|
869 |
||
870 |
|access| |
|
871 |
||
872 |
access := OperatingSystem accessModeOf:nameString. |
|
873 |
aCollection do:[:accessSymbol | |
|
874 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
|
875 |
]. |
|
876 |
(OperatingSystem changeAccessModeOf:nameString to:access) ifFalse:[ |
|
877 |
^ self accessDeniedError:self |
|
878 |
] |
|
879 |
||
880 |
" |
|
881 |
'foo' asFilename writeStream close. |
|
882 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
883 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
884 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
885 |
" |
|
886 |
! |
|
887 |
||
888 |
copyTo:newName |
|
889 |
"copy the file - the argument must be convertable to a filename. |
|
671 | 890 |
Return true if successful, false if not." |
615 | 891 |
|
892 |
|inStream outStream buffer bufferSize count newFile| |
|
893 |
||
894 |
bufferSize := 8 * 1024. |
|
895 |
buffer := ByteArray new:bufferSize. |
|
896 |
inStream := self readStream. |
|
897 |
inStream isNil ifTrue:[ |
|
898 |
^ self fileNotFoundError:self |
|
899 |
]. |
|
900 |
||
901 |
outStream := (newFile := newName asFilename) writeStream. |
|
902 |
outStream isNil ifTrue:[ |
|
903 |
^ self fileCreationError:newFile |
|
904 |
]. |
|
905 |
||
906 |
[inStream atEnd] whileFalse:[ |
|
907 |
count := inStream nextBytes:bufferSize into:buffer. |
|
908 |
(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[ |
|
909 |
^ self fileCreationError:newFile |
|
910 |
] |
|
911 |
]. |
|
912 |
outStream close. |
|
913 |
inStream close. |
|
914 |
||
915 |
" |
|
916 |
'Makefile' asFilename copyTo:'Makefile.foo' |
|
917 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
918 |
" |
|
919 |
! |
|
920 |
||
921 |
delete |
|
922 |
"remove the file - same as remove, for ST-80 compatibility" |
|
923 |
||
924 |
self remove |
|
925 |
! |
|
926 |
||
927 |
makeDirectory |
|
928 |
"create a directory with the receivers name. |
|
671 | 929 |
Return true if successful, false if not." |
615 | 930 |
|
931 |
(OperatingSystem createDirectory:nameString) ifFalse:[ |
|
1970 | 932 |
(self exists and:[self isDirectory]) ifFalse:[ |
933 |
^ self fileCreationError:self |
|
934 |
] |
|
615 | 935 |
] |
1970 | 936 |
|
937 |
"Modified: 12.11.1996 / 12:25:22 / cg" |
|
615 | 938 |
! |
939 |
||
844 | 940 |
makeExecutable |
941 |
"make the file executable - you must have permission to do so. |
|
942 |
For directories, execution means: 'allow changing into it'" |
|
943 |
||
944 |
^ self addAccessRights:#(executeUser) |
|
945 |
||
946 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
947 |
! |
|
948 |
||
949 |
makeExecutableForAll |
|
950 |
"make the file executable for all - you must have permission to do so. |
|
951 |
For directories, execution means: 'allow changing into it'" |
|
952 |
||
953 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
954 |
||
955 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
956 |
! |
|
957 |
||
615 | 958 |
makeReadable |
959 |
"make the file readable for the owner - you must have permission to do so." |
|
960 |
||
961 |
^ self addAccessRights:#(readUser) |
|
962 |
! |
|
963 |
||
964 |
makeReadableForAll |
|
965 |
"make the file readable for all - you must have permission to do so." |
|
966 |
||
967 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
968 |
! |
|
969 |
||
970 |
makeUnwritable |
|
971 |
"make the file unwritable for all - you must have permission to do so." |
|
972 |
||
973 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
974 |
! |
|
975 |
||
976 |
makeWritable |
|
977 |
"make the file writableable for all - you must have permission to do so." |
|
978 |
||
979 |
^ self addAccessRights:#(writeUser) |
|
980 |
! |
|
981 |
||
982 |
makeWritableForAll |
|
983 |
"make the file writable for all - you must have permission to do so." |
|
984 |
||
985 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
986 |
! |
|
987 |
||
988 |
moveTo:newName |
|
989 |
"copy the file represented by the receiver, then delete it. |
|
990 |
This is different to renaming in case of cross device moves. |
|
671 | 991 |
Raise an error if not successful." |
615 | 992 |
|
993 |
self copyTo:newName. |
|
994 |
self remove |
|
995 |
! |
|
996 |
||
659 | 997 |
recursiveMakeDirectory |
998 |
"create a directory with the receivers name and all required intermediate |
|
999 |
directories. |
|
671 | 1000 |
Raise an error if not successful." |
659 | 1001 |
|
1002 |
(OperatingSystem recursiveCreateDirectory:nameString) ifFalse:[ |
|
671 | 1003 |
^ self fileCreationError:self |
659 | 1004 |
] |
1005 |
||
1006 |
"Created: 27.11.1995 / 23:36:40 / cg" |
|
1007 |
! |
|
1008 |
||
615 | 1009 |
recursiveRemove |
671 | 1010 |
"remove the directory and all of its subfiles/subdirectories. |
1011 |
Raise an error if not successful." |
|
615 | 1012 |
|
1013 |
|ok| |
|
1014 |
||
1015 |
ok := OperatingSystem recursiveRemoveDirectory:nameString. |
|
1016 |
ok ifFalse:[ |
|
1017 |
self removeError:self |
|
1018 |
]. |
|
1019 |
||
1020 |
" |
|
1021 |
'foo' asFilename makeDirectory. |
|
1022 |
'foo/bar' asFilename writeStream close. |
|
1023 |
('foo' asFilename remove) ifFalse:[ |
|
1422 | 1024 |
Transcript showCR:'could not remove foo' |
615 | 1025 |
] |
1026 |
" |
|
1027 |
" |
|
1028 |
'foo' asFilename makeDirectory. |
|
1029 |
'foo/bar' asFilename writeStream close. |
|
1030 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
1422 | 1031 |
Transcript showCR:'could not remove foo' |
615 | 1032 |
] |
1033 |
" |
|
1034 |
||
1035 |
"Created: 14.11.1995 / 11:19:29 / cg" |
|
1036 |
! |
|
1037 |
||
1038 |
remove |
|
845 | 1039 |
"remove the file/directory. |
672 | 1040 |
Raise an error if not successful. |
845 | 1041 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 1042 |
|
1043 |
|ok| |
|
1044 |
||
1045 |
self exists ifFalse:[ ^ self]. |
|
1046 |
self isDirectory ifTrue:[ |
|
883 | 1047 |
ok := OperatingSystem removeDirectory:nameString |
615 | 1048 |
] ifFalse:[ |
883 | 1049 |
ok := OperatingSystem removeFile:nameString |
615 | 1050 |
]. |
1051 |
ok ifFalse:[ |
|
883 | 1052 |
self removeError:self |
615 | 1053 |
]. |
1054 |
||
1055 |
" |
|
1056 |
(FileStream newFileNamed:'foo') close. |
|
1057 |
'foo' asFilename remove |
|
1058 |
" |
|
1059 |
||
1060 |
" |
|
1061 |
'foo' asFilename makeDirectory. |
|
1062 |
'foo/bar' asFilename writeStream close. |
|
1063 |
('foo' asFilename remove) ifFalse:[ |
|
1422 | 1064 |
Transcript showCR:'could not remove foo' |
615 | 1065 |
] |
1066 |
" |
|
1067 |
||
845 | 1068 |
"Modified: 10.1.1996 / 18:44:50 / cg" |
615 | 1069 |
! |
1070 |
||
1071 |
removeAccessRights:aCollection |
|
1072 |
"remove the access rights as specified in aCollection for the file represented |
|
1073 |
by the receiver. The argument must be a collection of symbols, |
|
671 | 1074 |
such as #readUser, #writeGroup etc. |
1075 |
Raise an error if not successful." |
|
615 | 1076 |
|
1077 |
|access| |
|
1078 |
||
1079 |
access := OperatingSystem accessModeOf:nameString. |
|
1080 |
aCollection do:[:accessSymbol | |
|
1081 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
|
1082 |
]. |
|
1083 |
(OperatingSystem changeAccessModeOf:nameString to:access) ifFalse:[ |
|
1084 |
^ self accessDeniedError:self |
|
1085 |
]. |
|
1086 |
||
1087 |
" |
|
1088 |
'foo' asFilename writeStream close. |
|
1089 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
1090 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
1091 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
1092 |
" |
|
1093 |
! |
|
1094 |
||
1095 |
renameTo:newName |
|
671 | 1096 |
"rename the file - the argument must be convertable to a String. |
1097 |
Raise an error if not successful." |
|
615 | 1098 |
|
1099 |
|ok| |
|
1100 |
||
1101 |
ok := OperatingSystem renameFile:nameString to:(newName asString). |
|
1102 |
ok ifFalse:[ |
|
1103 |
self exists ifFalse:[ |
|
1104 |
^ self fileNotFoundError:self |
|
1105 |
]. |
|
1106 |
^ self accessDeniedError:newName asFilename. |
|
1107 |
]. |
|
1108 |
||
1109 |
" |
|
1110 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
1111 |
" |
|
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1112 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1113 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1114 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1115 |
"change the files size. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1116 |
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
|
1117 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1118 |
(OperatingSystem truncateFile:nameString to:newSize) ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1119 |
^ 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
|
1120 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1121 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1122 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1123 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1124 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1125 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1126 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1127 |
s close. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1128 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1129 |
'test' asFilename truncateTo:100. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1130 |
('test' asFilename fileSize) printNL. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
1131 |
" |
615 | 1132 |
! ! |
1133 |
||
1134 |
!Filename methodsFor:'file queries'! |
|
1135 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1136 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1137 |
"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
|
1138 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1139 |
^ self dates at:#accessed |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1140 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1141 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1142 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1143 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1144 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1145 |
"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
|
1146 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1147 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1148 |
|
615 | 1149 |
dates |
1150 |
"return the files modification and access times as an object (currently a dictionary) |
|
1151 |
that responds to the at: message with arguments |
|
1152 |
#modified, #accessed or #statusChanged." |
|
1153 |
||
1154 |
|info dates| |
|
1155 |
||
1156 |
info := OperatingSystem infoOf:nameString. |
|
1157 |
info isNil ifTrue:[ |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1158 |
info := OperatingSystem linkInfoOf:nameString. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1159 |
info isNil ifTrue:[ |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1160 |
^ nil |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1161 |
] |
615 | 1162 |
]. |
1163 |
dates := IdentityDictionary new. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1164 |
dates at:#modified put:(info modified). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1165 |
dates at:#accessed put:(info accessed). |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1166 |
dates at:#statusChanged put:(info statusChanged). |
615 | 1167 |
^ dates |
1168 |
||
1169 |
" |
|
1170 |
Filename currentDirectory dates |
|
1171 |
'../regression' asFilename dates |
|
1172 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1173 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1174 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 1175 |
! |
1176 |
||
1177 |
fileSize |
|
1178 |
"return the size of the file in bytes" |
|
1179 |
||
1180 |
|info| |
|
1181 |
||
1182 |
info := self info. |
|
1183 |
info isNil ifTrue:[^ nil]. |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1184 |
^ info size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1185 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1186 |
"Modified: 1.11.1996 / 20:24:43 / cg" |
615 | 1187 |
! |
1188 |
||
1189 |
fileType |
|
1190 |
"this returns a string describing the type of contents of |
|
1191 |
the file. This is done using the unix 'file' command, |
|
1192 |
(which usually is configurable by /etc/magic). |
|
1193 |
On non-unix systems, this may return an empty string, not knowning |
|
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1194 |
about the contents. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1195 |
Since the returned string differs among systems (and language settings), |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1196 |
it is only useful for user-information; NOT as a tag to be used by a program." |
615 | 1197 |
|
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1198 |
|stream buffer s n typeString suffix idx baseNm| |
615 | 1199 |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1200 |
"/ since executing 'file' takes some time, do the most obvious |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1201 |
"/ ones here. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1202 |
"/ (also useful for systems, which have no file command, such as NT) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1203 |
|
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1204 |
self isSymbolicLink ifTrue:[ |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1205 |
^ 'symbolic link to ' , (self linkInfo path) |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1206 |
]. |
2573 | 1207 |
self isDirectory ifTrue:[ |
1208 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
|
1209 |
self isExecutable ifFalse:[^ 'directory, locked']. |
|
1210 |
^ 'directory' |
|
1211 |
]. |
|
1602 | 1212 |
self isReadable ifFalse:[^ 'unreadable']. |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1213 |
self fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 1214 |
|
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1215 |
buffer := String new:2024. |
1602 | 1216 |
s := self readStream. |
1217 |
s notNil ifTrue:[ |
|
1218 |
n := s nextBytes:buffer size into:buffer. |
|
1219 |
s close. |
|
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1220 |
|
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1221 |
true "n == buffer size" ifTrue:[ |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1222 |
((suffix := self suffix asLowercase) = 'st') ifTrue:[ |
1602 | 1223 |
(buffer findString:'subclass:') ~~ 0 ifTrue:[ |
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1224 |
^ 'smalltalk class source' |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1225 |
]. |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1226 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1227 |
^ 'smalltalk method source' |
1602 | 1228 |
]. |
1229 |
]. |
|
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1230 |
|
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1231 |
(buffer findString:'methodsFor:') ~~ 0 ifTrue:[ |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1232 |
^ 'smalltalk changes / method source' |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1233 |
]. |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1234 |
|
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1235 |
(suffix = 'rc') ifTrue:[ |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1236 |
(buffer findString:'ST/X startup') ~~ 0 ifTrue:[ |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1237 |
^ 'smalltalk startup script' |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1238 |
]. |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1239 |
]. |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1240 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1241 |
(idx := buffer findString:'<H') ~~ 0 ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1242 |
((buffer continuesWith:'<HEAD' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1243 |
or:[(buffer continuesWith:'<HTML' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1244 |
or:[(buffer continuesWith:'<H1' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1245 |
or:[(buffer continuesWith:'<H2' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1246 |
or:[(buffer continuesWith:'<H3' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1247 |
or:[(buffer continuesWith:'<H4' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1248 |
or:[(buffer continuesWith:'<H5' startingAt:idx) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1249 |
or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]]) |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1250 |
ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1251 |
^ 'HTML document text' |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1252 |
] |
1612
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1253 |
]. |
730781a80e2a
inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents:
1602
diff
changeset
|
1254 |
]. |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1255 |
|
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1256 |
(suffix = 'ps') ifTrue:[ |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1257 |
(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[ |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1258 |
^ 'PostScript document' |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1259 |
]. |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1260 |
]. |
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
1261 |
|
2566
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1262 |
baseNm := self withoutSuffix baseName asLowercase. |
e134970f84ab
more internal fileType guessing (smalltalk stuff)
Claus Gittinger <cg@exept.de>
parents:
2550
diff
changeset
|
1263 |
(baseNm = 'makefile') ifTrue:[ |
1602 | 1264 |
(buffer startsWith:'#') ifTrue:[ |
1265 |
^ 'make rules' |
|
1266 |
] |
|
1267 |
] |
|
1268 |
] |
|
1269 |
]. |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1270 |
|
615 | 1271 |
typeString := ''. |
1272 |
stream := PipeStream readingFrom:('file ' , self pathName). |
|
1273 |
stream notNil ifTrue:[ |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1274 |
typeString := stream contents asString. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1275 |
stream close. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1276 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1277 |
typeString := typeString withoutSeparators |
615 | 1278 |
] ifFalse:[ |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1279 |
" |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1280 |
could add some fallback code here, for systems, where no |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1281 |
file command is avaliable ... |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1282 |
... or at least analyze directory info. |
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1283 |
" |
615 | 1284 |
]. |
1285 |
^ typeString |
|
1286 |
||
1287 |
" |
|
1288 |
'Makefile' asFilename fileType |
|
1289 |
'.' asFilename fileType |
|
1290 |
'/dev/null' asFilename fileType |
|
1291 |
'smalltalk.rc' asFilename fileType |
|
1292 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
1293 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
1294 |
|
2573 | 1295 |
"Modified: 21.4.1997 / 14:57:51 / cg" |
615 | 1296 |
! |
1297 |
||
1298 |
info |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1299 |
"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
|
1300 |
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
|
1301 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1302 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1303 |
type - a symbol giving the files fileType |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1304 |
mode - numeric access mode |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1305 |
uid - owners user id |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1306 |
gid - owners group id |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1307 |
size - files size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1308 |
id - files number (i.e. inode number) |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1309 |
accessed - last access time (as osTime-stamp) |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1310 |
modified - last modification time (as osTime-stamp) |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1311 |
statusChanged - last staus change (as osTime-stamp) |
615 | 1312 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1313 |
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
|
1314 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1315 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1316 |
modified |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1317 |
size |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1318 |
type |
615 | 1319 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1320 |
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
|
1321 |
to either handle nil values, |
615 | 1322 |
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
|
1323 |
(i.e. instead of: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1324 |
someFilename type == #directory |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1325 |
use |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1326 |
someFIlename isDirectory |
615 | 1327 |
" |
1328 |
||
1329 |
^ OperatingSystem infoOf:nameString |
|
1330 |
||
1331 |
" |
|
1332 |
Filename currentDirectory info |
|
1333 |
'/dev/null' asFilename info |
|
1334 |
'Make.proto' asFilename info |
|
1335 |
'source/Point.st' asFilename info |
|
1336 |
'source/Point.st' asFilename linkInfo |
|
1337 |
'../../libbasic/Point.st' asFilename info |
|
1338 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1339 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1340 |
"Modified: 1.11.1996 / 20:22:40 / cg" |
615 | 1341 |
! |
1342 |
||
1343 |
linkInfo |
|
1344 |
"return the files info if its a symbolic link; nil otherwise. |
|
1345 |
On OS's which do not support symbolic links, nil is always returned. |
|
1346 |
The information is the same as returned by #info, except that if the |
|
1347 |
receiver represents a symbolic link, the links information |
|
1348 |
is returned |
|
1349 |
(while in this case, #info returns the info of the target file, |
|
1350 |
which is accessed via the symbolic link). |
|
1351 |
||
1352 |
In addition to the normal entries, Unix returns an additional entry: |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1353 |
path -> the target files pathname |
615 | 1354 |
|
1355 |
See the comment in #info for more details." |
|
1356 |
||
1357 |
^ OperatingSystem linkInfoOf:nameString |
|
1358 |
||
1359 |
" |
|
1360 |
Filename currentDirectory linkInfo |
|
1361 |
'/dev/null' asFilename linkInfo |
|
1362 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1363 |
'Make.proto' asFilename linkInfo path |
615 | 1364 |
'source/Point.st' asFilename linkInfo |
1365 |
'../../libbasic/Point.st' asFilename linkInfo |
|
1366 |
" |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1367 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1368 |
"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
|
1369 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1370 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1371 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1372 |
"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
|
1373 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1374 |
^ self dates at:#modified |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1375 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1376 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1377 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1378 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1379 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
1380 |
"Created: 9.7.1996 / 10:18:59 / cg" |
615 | 1381 |
! ! |
1382 |
||
1383 |
!Filename methodsFor:'file utilities'! |
|
1384 |
||
1385 |
edit |
|
1386 |
"start an editView on the file represented by the receiver" |
|
1387 |
||
1388 |
EditTextView openOn:self asString |
|
1389 |
||
1390 |
" |
|
1391 |
'smalltalk.rc' asFilename edit |
|
1392 |
" |
|
1393 |
! |
|
1394 |
||
1395 |
fileIn |
|
1396 |
"load smalltalk code from the file" |
|
1397 |
||
1398 |
^ self readStream fileIn |
|
542 | 1399 |
! ! |
1400 |
||
2 | 1401 |
!Filename methodsFor:'instance creation'! |
1402 |
||
615 | 1403 |
construct:subname |
1404 |
"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
|
1405 |
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
|
1406 |
(i.e. for a file or a subdirectory in that directory). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1407 |
See also: #withSuffix: (which is different, but often needed)" |
615 | 1408 |
|
1409 |
^ (self constructString:subname) asFilename |
|
1410 |
||
1411 |
" |
|
1412 |
'/tmp' asFilename construct:'foo' |
|
1413 |
'/' asFilename construct:'foo' |
|
1414 |
'/usr/tmp' asFilename construct:'foo' |
|
1415 |
'/foo/bar' asFilename construct:'baz' |
|
1416 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1417 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1418 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
615 | 1419 |
! |
1420 |
||
249 | 1421 |
constructString:subname |
38 | 1422 |
"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
|
1423 |
filenames string for an entry within this directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1424 |
(i.e. for a file or a subdirectory in that directory)." |
38 | 1425 |
|
276 | 1426 |
|sepString| |
202 | 1427 |
|
1428 |
sepString := self class separator asString. |
|
1429 |
nameString = sepString ifTrue:[ |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1430 |
"I am the root" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1431 |
^ sepString , subname |
85 | 1432 |
]. |
422 | 1433 |
^ nameString , sepString , subname asString |
38 | 1434 |
|
85 | 1435 |
" |
249 | 1436 |
'/tmp' asFilename constructString:'foo' |
1437 |
'/' asFilename constructString:'foo' |
|
1438 |
'/usr/tmp' asFilename constructString:'foo' |
|
328 | 1439 |
'/foo/bar' asFilename constructString:'baz' |
249 | 1440 |
" |
422 | 1441 |
|
1442 |
"Modified: 7.9.1995 / 10:15:22 / claus" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1443 |
"Modified: 29.2.1996 / 20:55:18 / cg" |
2 | 1444 |
! ! |
1445 |
||
195 | 1446 |
!Filename methodsFor:'misc'! |
1447 |
||
1448 |
, aString |
|
1449 |
"this allows filenames to understand how names are concatenated. |
|
308 | 1450 |
Returns a string consisting of the receivers name, concatenated |
195 | 1451 |
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
|
1452 |
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
|
1453 |
See also: #withSuffix: which is new and better." |
195 | 1454 |
|
308 | 1455 |
^ (nameString , aString asString) |
195 | 1456 |
|
1457 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1458 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1459 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1460 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1461 |
'Makefile' asFilename construct:'.bak' |
195 | 1462 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1463 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1464 |
"Modified: 29.2.1996 / 20:54:12 / cg" |
195 | 1465 |
! ! |
1466 |
||
615 | 1467 |
!Filename methodsFor:'printing & storing'! |
174 | 1468 |
|
615 | 1469 |
printOn:aStream |
1470 |
"append a printed representation of the receiver to aStream." |
|
174 | 1471 |
|
615 | 1472 |
aStream nextPutAll:'FileName('''. |
1473 |
nameString printOn:aStream. |
|
1474 |
aStream nextPutAll:''')' |
|
1 | 1475 |
! |
1476 |
||
615 | 1477 |
storeOn:aStream |
1478 |
"append a printed representation of the receiver to aStream, |
|
1479 |
which allows reconstructing it via readFrom:" |
|
328 | 1480 |
|
615 | 1481 |
aStream nextPut:$(. |
1482 |
nameString storeOn:aStream. |
|
1483 |
aStream nextPutAll:' asFilename)' |
|
1 | 1484 |
! ! |
1485 |
||
202 | 1486 |
!Filename methodsFor:'private accessing'! |
1 | 1487 |
|
68 | 1488 |
setName:aString |
38 | 1489 |
"set the filename" |
1490 |
||
68 | 1491 |
nameString := aString |
1 | 1492 |
! ! |
1493 |
||
2 | 1494 |
!Filename methodsFor:'queries'! |
1495 |
||
615 | 1496 |
canBeWritten |
1497 |
"same as isWritable - for ST-80 compatibility" |
|
328 | 1498 |
|
615 | 1499 |
^ self isWritable |
92 | 1500 |
|
328 | 1501 |
" |
615 | 1502 |
'/foo/bar' asFilename canBeWritten |
1503 |
'/tmp' asFilename canBeWritten |
|
1504 |
'Makefile' asFilename canBeWritten |
|
328 | 1505 |
" |
1506 |
! |
|
1507 |
||
68 | 1508 |
exists |
92 | 1509 |
"return true, if such a file exists." |
68 | 1510 |
|
1511 |
^ OperatingSystem isValidPath:nameString |
|
1512 |
||
85 | 1513 |
" |
92 | 1514 |
'/foo/bar' asFilename exists |
1515 |
'/tmp' asFilename exists |
|
1516 |
'Makefile' asFilename exists |
|
85 | 1517 |
" |
77 | 1518 |
! |
1519 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1520 |
filesMatching:aPattern |
2550 | 1521 |
"given the receiver, representing a directory; |
1522 |
return a collection of files matching a pattern. |
|
1523 |
The pattern may be a simple matchPattern, or a set of |
|
1524 |
multiple patterns separated by semicolons." |
|
1525 |
||
1526 |
|matchers| |
|
1527 |
||
1528 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
1529 |
^ self directoryContents |
|
1530 |
select:[:name | |
|
1531 |
(matchers detect:[:p | p match:name] ifNone:0) ~~ 0 |
|
1532 |
] |
|
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1533 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1534 |
" |
2550 | 1535 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1536 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1537 |
|
2550 | 1538 |
"Created: 15.4.1997 / 15:40:02 / cg" |
1539 |
"Modified: 15.4.1997 / 15:41:33 / cg" |
|
1540 |
! |
|
1541 |
||
1542 |
filesMatchingWithoutDotDirs:aPattern |
|
1543 |
"given the receiver, representing a directory; |
|
1544 |
return a collection of files matching a pattern. |
|
1545 |
Exclude '.' and '..' from the returned list. |
|
1546 |
The pattern may be a simple matchPattern, or a set of |
|
1547 |
multiple patterns separated by semicolons." |
|
1548 |
||
1549 |
|matchers| |
|
1550 |
||
1551 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
1552 |
^ self directoryContents |
|
1553 |
select:[:name | |
|
1554 |
name ~= '.' |
|
1555 |
and:[name ~= '..' |
|
1556 |
and:[(matchers detect:[:p | p match:name] ifNone:0) ~~ 0]] |
|
1557 |
] |
|
1558 |
||
1559 |
" |
|
1560 |
Filename currentDirectory filesMatching:'M*' |
|
1561 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
1562 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
1563 |
" |
|
1564 |
||
1565 |
"Created: 15.4.1997 / 12:52:10 / cg" |
|
1566 |
"Modified: 15.4.1997 / 15:41:40 / cg" |
|
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1567 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1568 |
|
615 | 1569 |
isAbsolute |
1570 |
"return true, if the receiver represents an absolute pathname |
|
1571 |
(in contrast to one relative to the current directory)." |
|
356 | 1572 |
|
615 | 1573 |
^ (nameString startsWith:self class separator) |
328 | 1574 |
|
1575 |
" |
|
615 | 1576 |
'/foo/bar' asFilename isAbsolute |
1577 |
'..' asFilename isAbsolute |
|
1578 |
'..' asAbsoluteFilename isAbsolute |
|
1579 |
'source/SBrowser.st' asFilename isAbsolute |
|
1580 |
" |
|
1581 |
! |
|
1582 |
||
1583 |
isDirectory |
|
1584 |
"return true, if the receiver represents an existing, |
|
1585 |
readable directories pathname." |
|
1586 |
||
1587 |
^ OperatingSystem isDirectory:nameString |
|
1588 |
||
1589 |
" |
|
1590 |
'/foo/bar' asFilename isDirectory |
|
1591 |
'/tmp' asFilename isDirectory |
|
1592 |
'Makefile' asFilename isDirectory |
|
1593 |
" |
|
1594 |
! |
|
1595 |
||
1596 |
isExecutable |
|
1597 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
1598 |
For directories, true is returned if the directory can be entered. |
|
1599 |
See isExecutableProgram for a related check." |
|
1600 |
||
1601 |
^ OperatingSystem isExecutable:nameString |
|
1602 |
||
1603 |
" |
|
1604 |
'/foo/bar' asFilename isExecutable |
|
1605 |
'/tmp' asFilename isExecutable |
|
1606 |
'Makefile' asFilename isExecutable |
|
1607 |
'/bin/ls' asFilename isExecutable |
|
356 | 1608 |
" |
1609 |
! |
|
1610 |
||
615 | 1611 |
isExecutableProgram |
1612 |
"return true, if such a file exists and is an executable program. |
|
1613 |
(i.e. for directories, false is returned.)" |
|
356 | 1614 |
|
615 | 1615 |
^ (OperatingSystem isExecutable:nameString) |
1616 |
and:[(OperatingSystem isDirectory:nameString) not] |
|
356 | 1617 |
|
1618 |
" |
|
615 | 1619 |
'/tmp' asFilename isExecutable |
1620 |
'/bin/ls' asFilename isExecutable |
|
1621 |
'/tmp' asFilename isExecutableProgram |
|
1622 |
'/bin/ls' asFilename isExecutableProgram |
|
1623 |
" |
|
1624 |
! |
|
1625 |
||
1626 |
isReadable |
|
1627 |
"return true, if such a file exists and is readable." |
|
1628 |
||
1629 |
^ OperatingSystem isReadable:nameString |
|
1630 |
||
1631 |
" |
|
1632 |
'/foo/bar' asFilename isReadable |
|
1633 |
'/tmp' asFilename isReadable |
|
1634 |
'Makefile' asFilename isReadable |
|
328 | 1635 |
" |
1636 |
! |
|
1637 |
||
615 | 1638 |
isRelative |
1639 |
"return true, if this name is interpreted relative to some |
|
1640 |
directory (opposite of absolute)" |
|
328 | 1641 |
|
615 | 1642 |
^ self isAbsolute not |
2175 | 1643 |
|
1644 |
" |
|
1645 |
'./foo/bar' asFilename isRelative |
|
1646 |
'../../foo/bar' asFilename isRelative |
|
1647 |
'/foo/bar' asFilename isRelative |
|
1648 |
'bar' asFilename isRelative |
|
1649 |
" |
|
1650 |
||
1651 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
615 | 1652 |
! |
328 | 1653 |
|
615 | 1654 |
isSymbolicLink |
1655 |
"return true, if the file represented by the receiver is a symbolic |
|
1656 |
link. Notice that not all OS's support symbolic links; those that do |
|
1657 |
not will always return false." |
|
1658 |
||
1659 |
^ OperatingSystem isSymbolicLink:nameString |
|
328 | 1660 |
|
1661 |
" |
|
615 | 1662 |
'Make.proto' asFilename isSymbolicLink |
1663 |
'Makefile' asFilename isSymbolicLink |
|
1664 |
" |
|
1665 |
! |
|
1666 |
||
1667 |
isWritable |
|
1668 |
"return true, if such a file exists and is writable." |
|
1669 |
||
1670 |
^ OperatingSystem isWritable:nameString |
|
1671 |
||
1672 |
" |
|
1673 |
'/foo/bar' asFilename isWritable |
|
1674 |
'/tmp' asFilename isWritable |
|
1675 |
'Makefile' asFilename isWritable |
|
328 | 1676 |
" |
174 | 1677 |
! |
1678 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1679 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1680 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1681 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1682 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1683 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1684 |
"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
|
1685 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1686 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1687 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1688 |
|
1540 | 1689 |
contents |
1690 |
"return the contents of the file as a collection of lines; |
|
1691 |
or nil, if the file is unreadable." |
|
1692 |
||
1693 |
|s contents| |
|
1694 |
||
1695 |
s := self readStream. |
|
1696 |
s isNil ifTrue:[^ nil]. |
|
1697 |
||
1698 |
[ |
|
1699 |
contents := s contents |
|
1700 |
] valueNowOrOnUnwindDo:[s close]. |
|
1701 |
^ contents |
|
1702 |
||
1703 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1704 |
"Modified: 11.7.1996 / 14:08:47 / cg" |
|
1705 |
"Created: 11.7.1996 / 14:09:11 / cg" |
|
1706 |
! |
|
1707 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1708 |
contentsOfEntireFile |
1540 | 1709 |
"return the contents of the file as a string; |
1710 |
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
|
1711 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1712 |
|s contents| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1713 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1714 |
s := self readStream. |
1535 | 1715 |
s isNil ifTrue:[^ nil]. |
1716 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1717 |
[ |
1523 | 1718 |
contents := s contentsOfEntireFile |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1719 |
] valueNowOrOnUnwindDo:[s close]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1720 |
^ contents |
1523 | 1721 |
|
1722 |
"Modified: 2.7.1996 / 12:49:45 / stefan" |
|
1540 | 1723 |
"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
|
1724 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1725 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1726 |
directoryContents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1727 |
"return the contents of the directory as a collection of strings" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1728 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1729 |
^ (FileDirectory directoryNamed:self asString) contents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1730 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1731 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1732 |
'.' asFilename directoryContents |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1733 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1734 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1735 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1736 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1737 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1738 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1739 |
"return my baseName as a string. |
2012 | 1740 |
- thats the file/directory name without leading parent-dirs. |
1741 |
See also: #pathName, #directoryName and #directoryPathName" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1742 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1743 |
^ OperatingSystem baseNameOf:nameString "/ (self pathName) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1744 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1745 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1746 |
'/foo/bar' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1747 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1748 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1749 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1750 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1751 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1752 |
'../../libbasic/Object.st' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1753 |
" |
2012 | 1754 |
|
1755 |
"Modified: 21.12.1996 / 15:22:16 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1756 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1757 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1758 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1759 |
"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
|
1760 |
- 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
|
1761 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1762 |
(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
|
1763 |
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
|
1764 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1765 |
^ self directoryName asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1766 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1767 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1768 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1769 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1770 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1771 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1772 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1773 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1774 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1775 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1776 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1777 |
"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
|
1778 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1779 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1780 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1781 |
"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
|
1782 |
- 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
|
1783 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1784 |
(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
|
1785 |
a string instead of a Filename instance). |
2012 | 1786 |
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
|
1787 |
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
|
1788 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1789 |
^ OperatingSystem directoryNameOf:nameString "/ (self pathName) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1790 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1791 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1792 |
'/foo/bar/' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1793 |
'/foo/bar/' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1794 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1795 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1796 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1797 |
'bitmaps' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1798 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1799 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1800 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1801 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1802 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1803 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1804 |
"Modified: 7.9.1995 / 10:42:03 / claus" |
2012 | 1805 |
"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
|
1806 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1807 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1808 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1809 |
"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
|
1810 |
- 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
|
1811 |
the receiver is contained in. |
2012 | 1812 |
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
|
1813 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1814 |
^ OperatingSystem directoryNameOf:(self pathName) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1815 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1816 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1817 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1818 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1819 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1820 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1821 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1822 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1823 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1824 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1825 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1826 |
'..' asFilename directory |
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 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1829 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1830 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1831 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 1832 |
"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
|
1833 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1834 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1835 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1836 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1837 |
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
|
1838 |
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
|
1839 |
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
|
1840 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1841 |
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
|
1842 |
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
|
1843 |
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
|
1844 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1845 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1846 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1847 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1848 |
'mak' asFilename filenameCompletion |
1517 | 1849 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1850 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1851 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1852 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1853 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1854 |
|
1517 | 1855 |
"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
|
1856 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1857 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1858 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1859 |
"try to complete the receiver filename. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1860 |
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
|
1861 |
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
|
1862 |
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
|
1863 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1864 |
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
|
1865 |
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
|
1866 |
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
|
1867 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1868 |
|dir baseName matching matchLen try allMatching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1869 |
sepString parentString prefix nMatch| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1870 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1871 |
sepString := self class separator asString. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1872 |
(nameString endsWith:sepString) ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1873 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1874 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1875 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1876 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1877 |
baseName := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1878 |
baseName ~= nameString ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1879 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1880 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1881 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1882 |
self isAbsolute ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1883 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1884 |
] ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1885 |
aDirectory isNil ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1886 |
dir := self directory |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1887 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1888 |
dir := (aDirectory construct:nameString) directory |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1889 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1890 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1891 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1892 |
matching := OrderedCollection new. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1893 |
dir directoryContents do:[:fileName | |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1894 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1895 |
(fileName startsWith:baseName) ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1896 |
matching add:fileName |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1897 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1898 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1899 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1900 |
(nMatch := matching size) > 1 ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1901 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1902 |
find the longest common prefix |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1903 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1904 |
matchLen := baseName size. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1905 |
matchLen > matching first size ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1906 |
try := baseName. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1907 |
allMatching := false |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1908 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1909 |
try := matching first copyTo:matchLen. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1910 |
allMatching := true. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1911 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1912 |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1913 |
[allMatching] whileTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1914 |
matching do:[:aName | |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1915 |
(aName startsWith:try) ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1916 |
allMatching := false |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1917 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1918 |
]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1919 |
allMatching ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1920 |
matchLen < matching first size ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1921 |
matchLen := matchLen + 1. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1922 |
try := matching first copyTo:matchLen. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1923 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1924 |
allMatching := false |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1925 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1926 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1927 |
try := matching first copyTo:matchLen - 1. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1928 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1929 |
]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1930 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1931 |
and set my name to the last full match |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1932 |
" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1933 |
nameString := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1934 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1935 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1936 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1937 |
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
|
1938 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1939 |
prefix notNil ifTrue:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1940 |
prefix = '/' ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1941 |
"/ avoid introducing double slashes |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1942 |
prefix := '' |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1943 |
]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1944 |
matching := matching collect:[:n | prefix , '/' , n]. |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1945 |
nMatch == 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1946 |
nameString := matching first |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1947 |
] ifFalse:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1948 |
nMatch > 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1949 |
nameString := prefix , '/' , nameString |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1950 |
] |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1951 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1952 |
] ifFalse:[ |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1953 |
nMatch == 1 ifTrue:[ |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1954 |
nameString := matching first |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
1955 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1956 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1957 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1958 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1959 |
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
|
1960 |
(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
|
1961 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1962 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1963 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1964 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1965 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1966 |
'../' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1967 |
'/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1968 |
'/usr/' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1969 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1970 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1971 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1972 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1973 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1974 |
'../../libpr' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1975 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1976 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1977 |
"Modified: 29.2.1996 / 20:28:45 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1978 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1979 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1980 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1981 |
"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
|
1982 |
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
|
1983 |
(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
|
1984 |
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
|
1985 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1986 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1987 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1988 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1989 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1990 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1991 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1992 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1993 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1994 |
"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
|
1995 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1996 |
|
615 | 1997 |
name |
1998 |
"return the name of the file represented by the receiver as a string. |
|
883 | 1999 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 2000 |
See also: pathName" |
174 | 2001 |
|
615 | 2002 |
self isAbsolute ifTrue:[^ self pathName]. |
2003 |
^ nameString |
|
174 | 2004 |
|
2005 |
" |
|
615 | 2006 |
'/foo/bar' asFilename name |
2007 |
'/foo/bar' asFilename pathName |
|
2008 |
'.' asFilename name |
|
2009 |
'.' asFilename pathName |
|
2010 |
'../..' asFilename name |
|
883 | 2011 |
'../..' asFilename pathName |
615 | 2012 |
'bitmaps' asFilename name |
2013 |
'bitmaps' asFilename pathName |
|
2014 |
'/tmp/../usr' asFilename name |
|
883 | 2015 |
'/tmp/../usr' asFilename pathName |
2016 |
'source/..' asFilename name |
|
2017 |
'source/..' asFilename pathName |
|
2018 |
'/tmp/..' asFilename name |
|
2019 |
'/tmp/..' asFilename pathName |
|
92 | 2020 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2021 |
|
883 | 2022 |
"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
|
2023 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2024 |
|
615 | 2025 |
pathName |
2026 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 2027 |
as a string. This will not include ..'s. |
2028 |
If the path represented by the receiver does NOT represent a valid path, |
|
2029 |
no compression will be done (for now; this may change). |
|
2030 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2031 |
|
1317 | 2032 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
2033 |
|
1317 | 2034 |
"/ sep := self class separator. |
2035 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
2036 |
"/ parentName := self class parentDirectoryName. |
|
2037 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
2038 |
"/ ^ nameString |
|
2039 |
"/ ] |
|
2040 |
"/ ]. |
|
2041 |
p := OperatingSystem pathNameOf:nameString. |
|
2042 |
^ p |
|
2 | 2043 |
|
92 | 2044 |
" |
1317 | 2045 |
'/foo/bar' asFilename pathName |
2046 |
'.' asFilename pathName |
|
2047 |
'../..' asFilename pathName |
|
2048 |
'../..' asFilename name |
|
2049 |
'/tmp/../usr' asFilename pathName |
|
2050 |
'/././usr' asFilename pathName |
|
92 | 2051 |
" |
159 | 2052 |
|
1317 | 2053 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 2054 |
! |
2055 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2056 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2057 |
"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
|
2058 |
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
|
2059 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2060 |
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
|
2061 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2062 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2063 |
|t target path| |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2064 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2065 |
self isSymbolicLink ifFalse:[ |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2066 |
self exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2067 |
^ self pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2068 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2069 |
t := self. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2070 |
[t isSymbolicLink] whileTrue:[ |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2071 |
path := t linkInfo path. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2072 |
path isNil ifTrue:[ |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2073 |
"/ cannot happen |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2074 |
^ nil |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2075 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2076 |
target := t directoryName asFilename construct:path. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2077 |
target exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2078 |
t := target asFilename |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2079 |
]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2080 |
t exists ifFalse:[^ nil]. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2081 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2082 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2083 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2084 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2085 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2086 |
'../..' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2087 |
'include/abbrev.stc' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2088 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2089 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2090 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2091 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
2092 |
|
615 | 2093 |
suffix |
2094 |
"return my suffix. |
|
2095 |
The suffix is the namepart after the final period character, |
|
2096 |
or the empty string, if the name does not contain a period." |
|
2097 |
||
2098 |
^ self prefixAndSuffix at:2 |
|
174 | 2099 |
|
615 | 2100 |
" |
2101 |
'abc.st' asFilename suffix |
|
2102 |
'abc' asFilename suffix |
|
2103 |
'a.b.c' asFilename suffix |
|
2104 |
" |
|
174 | 2105 |
|
615 | 2106 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
174 | 2107 |
! |
2108 |
||
615 | 2109 |
tail |
2110 |
"the files name without directory prefix as a string. |
|
2111 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 2112 |
|
615 | 2113 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2114 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2115 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2116 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2117 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2118 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2119 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2120 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2121 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2122 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2123 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2124 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2125 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2126 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2127 |
"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
|
2128 |
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
|
2129 |
the prefix everything before, except for the period. |
1517 | 2130 |
The directory name part is stripped off (i.e. the returned prefix |
2131 |
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
|
2132 |
(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
|
2133 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
1517 | 2134 |
See also: #withoutSuffix and #withSuffix |
2135 |
Notice: |
|
2136 |
there is currently no known system which uses other than |
|
2137 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2138 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2139 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2140 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2141 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2142 |
idx := nm lastIndexOf:(self class suffixSeparator). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2143 |
idx == 0 ifTrue:[ |
1517 | 2144 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2145 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2146 |
^ Array |
1517 | 2147 |
with:(nm copyTo:idx-1) |
2148 |
with:(nm copyFrom:idx+1) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2149 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2150 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2151 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2152 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2153 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 2154 |
'/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
|
2155 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2156 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2157 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 2158 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2159 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2160 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2161 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 2162 |
"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
|
2163 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2164 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2165 |
withSuffix:aSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2166 |
"return a new filename for the receivers name with a suffix. |
1993 | 2167 |
If the name already has a suffix, the new suffix replacaes it; |
2168 |
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
|
2169 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2170 |
^ self class named: |
1517 | 2171 |
(self withoutSuffix name |
2172 |
, self class suffixSeparator asString |
|
2173 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2174 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2175 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2176 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2177 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2178 |
'a.b.c' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2179 |
'/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
|
2180 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 2181 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 2182 |
'/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
|
2183 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2184 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2185 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1993 | 2186 |
"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
|
2187 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2188 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2189 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2190 |
"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
|
2191 |
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
|
2192 |
|
1516 | 2193 |
|lastComponentsIndex idx| |
2194 |
||
2195 |
lastComponentsIndex := nameString lastIndexOf:(self class separator). |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2196 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2197 |
idx := nameString lastIndexOf:(self class suffixSeparator). |
1516 | 2198 |
(idx == 0 or:[idx <= lastComponentsIndex]) ifTrue:[^ self]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2199 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2200 |
^ 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
|
2201 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2202 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2203 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2204 |
'abc' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2205 |
'a.b.c' asFilename withoutSuffix |
1516 | 2206 |
'/foo/bar/baz.c' asFilename withoutSuffix |
2207 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
|
2208 |
'/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
|
2209 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2210 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
2211 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1516 | 2212 |
"Modified: 3.7.1996 / 10:49:58 / cg" |
174 | 2213 |
! ! |
2214 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
2215 |
!Filename class methodsFor:'documentation'! |
630 | 2216 |
|
2217 |
version |
|
2573 | 2218 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.85 1997-04-21 13:02:48 cg Exp $' |
630 | 2219 |
! ! |