author | Claus Gittinger <cg@exept.de> |
Wed, 28 Oct 2009 14:59:52 +0100 | |
changeset 12388 | 906dbb652511 |
parent 12336 | 7610de9a7e4b |
child 12437 | 704dc2f7a1d0 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
9453 | 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 |
" |
|
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
12 |
"{ Package: 'stx:libbasic' }" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
13 |
|
1 | 14 |
Object subclass:#Filename |
9806 | 15 |
instanceVariableNames:'nameString' |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
16 |
classVariableNames:'NextTempFilenameIndex TempDirectory DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
17 |
ConcreteClass' |
9806 | 18 |
poolDictionaries:'' |
19 |
category:'System-Support' |
|
615 | 20 |
! |
1 | 21 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
22 |
!Filename class methodsFor:'documentation'! |
88 | 23 |
|
24 |
copyright |
|
25 |
" |
|
26 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
9453 | 27 |
All Rights Reserved |
1 | 28 |
|
88 | 29 |
This software is furnished under a license and may be used |
30 |
only in accordance with the terms of that license and with the |
|
31 |
inclusion of the above copyright notice. This software may not |
|
32 |
be provided or otherwise made available to, or used by, any |
|
33 |
other person. No title to or ownership of the software is |
|
34 |
hereby transferred. |
|
35 |
" |
|
36 |
! |
|
37 |
||
38 |
documentation |
|
39 |
" |
|
40 |
Filenames; originally added for ST-80 compatibility, is |
|
41 |
taking over functionality from other classes (FileDirectory). |
|
92 | 42 |
|
43 |
Instances of Filename do not nescessarily represent valid or existing |
|
44 |
files - i.e. it is possible (and useful) to have instances for non-existing |
|
45 |
files around. In other words: the name-string is not checked automatically |
|
46 |
for being correct or existing. |
|
47 |
Thus, it is possible to do queries such as: |
|
48 |
||
8738 | 49 |
'/fee/foo/foe' asFilename exists |
50 |
'/not_existing' asFilename isDirectory |
|
51 |
'/foo/bar' asFilename isReadable |
|
92 | 52 |
|
195 | 53 |
(all of the above examples will probably return false on your machine ;-). |
276 | 54 |
|
55 |
examples: |
|
56 |
||
8738 | 57 |
'Makefile' asFilename readStream |
58 |
||
59 |
'newFile' asFilename writeStream |
|
60 |
||
61 |
Filename newTemporary writeStream |
|
276 | 62 |
|
1318 | 63 |
Beside lots of protocol to query for a files attributes, the class |
64 |
protocol offers methods for filename completion, to construct pathes |
|
65 |
(in an OS-independent way) and to create temporary files. |
|
2911 | 66 |
Especially the path-construction methods (i.e. #construct:) are highly |
1318 | 67 |
recommended in order to avoid having OS details (like directory separators |
68 |
being slash or backslash) spreaded in your application. |
|
69 |
||
8738 | 70 |
Since Filenames have different semantics under different operating systems, |
71 |
class methods are delegated to concrete implementations in various subclasses like |
|
72 |
UnixFilename, PCFilename, ... |
|
73 |
The delegation is implemented in a way, so that some methods of |
|
74 |
specific OS Filenames might be used, even if ST/X is currently running |
|
75 |
on a different OS (as long as the method does not depend on the OperatingSystem class). |
|
76 |
||
1286 | 77 |
[author:] |
8738 | 78 |
Claus Gittinger |
276 | 79 |
|
1286 | 80 |
[see also:] |
8738 | 81 |
String |
82 |
FileStream DirectoryStream PipeStream Socket |
|
83 |
OperatingSystem |
|
84 |
Date Time |
|
88 | 85 |
" |
360 | 86 |
! |
87 |
||
88 |
examples |
|
89 |
" |
|
90 |
does a file/directory exist ?: |
|
9453 | 91 |
[exBegin] |
92 |
|f| |
|
93 |
||
94 |
f := 'foobar' asFilename. |
|
95 |
^ f exists |
|
96 |
[exEnd] |
|
360 | 97 |
|
98 |
||
99 |
is it a directory ?: |
|
9453 | 100 |
[exBegin] |
101 |
|f| |
|
102 |
||
103 |
f := '/tmp' asFilename. |
|
104 |
^ f isDirectory. |
|
105 |
[exEnd] |
|
360 | 106 |
|
107 |
||
108 |
get the working directory: |
|
9453 | 109 |
[exBegin] |
110 |
^ Filename defaultDirectory |
|
111 |
[exEnd] |
|
360 | 112 |
|
113 |
||
114 |
get a files full pathname |
|
115 |
(caring for relative names or symbolic links): |
|
9453 | 116 |
[exBegin] |
117 |
|f| |
|
118 |
||
119 |
f := '..' asFilename. |
|
120 |
^ f pathName |
|
121 |
[exEnd] |
|
360 | 122 |
|
123 |
||
124 |
get a directories directory: |
|
9453 | 125 |
[exBegin] |
126 |
|f| |
|
127 |
||
128 |
f := Filename defaultDirectory. |
|
129 |
^ f directory |
|
130 |
[exEnd] |
|
360 | 131 |
|
132 |
||
133 |
get a files directory: |
|
9453 | 134 |
[exBegin] |
135 |
|f| |
|
136 |
||
137 |
f := './smalltalk' asFilename. |
|
138 |
^ f directory |
|
139 |
[exEnd] |
|
360 | 140 |
|
141 |
||
142 |
getting access & modification times: |
|
9453 | 143 |
[exBegin] |
144 |
|f| |
|
145 |
||
146 |
f := '/tmp' asFilename. |
|
147 |
^ f dates |
|
148 |
[exEnd] |
|
360 | 149 |
|
150 |
access time only: |
|
9453 | 151 |
[exBegin] |
152 |
|f| |
|
153 |
||
154 |
f := '/tmp' asFilename. |
|
155 |
^ f dates at:#accessed |
|
156 |
[exEnd] |
|
360 | 157 |
|
158 |
||
159 |
getting all information on a file/directory: |
|
9453 | 160 |
[exBegin] |
161 |
|f| |
|
162 |
||
163 |
f := '/tmp' asFilename. |
|
164 |
^ f info |
|
165 |
[exEnd] |
|
360 | 166 |
|
167 |
||
168 |
getting a temporary file (unique name): |
|
9453 | 169 |
[exBegin] |
170 |
|f| |
|
171 |
||
172 |
f := Filename newTemporary. |
|
173 |
^ f |
|
174 |
[exEnd] |
|
360 | 175 |
|
176 |
creating, writing, reading and removing a temporary file: |
|
9453 | 177 |
[exBegin] |
178 |
|f writeStream readStream| |
|
179 |
||
180 |
f := Filename newTemporary. |
|
181 |
writeStream := f writeStream. |
|
182 |
writeStream nextPutAll:'hello world'. |
|
183 |
writeStream cr. |
|
184 |
writeStream close. |
|
185 |
||
186 |
'contents (as seen by unix''s cat command:' printNL. |
|
187 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
188 |
||
189 |
readStream := f readStream. |
|
190 |
Transcript showCR:'contents as seen by smalltalk:'. |
|
191 |
Transcript showCR:(readStream upToEnd). |
|
192 |
readStream close. |
|
193 |
||
194 |
f delete. |
|
195 |
[exEnd] |
|
360 | 196 |
|
197 |
||
198 |
getting a directories contents: |
|
9453 | 199 |
[exBegin] |
200 |
|f files| |
|
201 |
||
202 |
f := Filename currentDirectory. |
|
203 |
files := f directoryContents. |
|
204 |
Transcript showCR:'the files are:'. |
|
205 |
Transcript showCR:(files printString). |
|
206 |
[exEnd] |
|
360 | 207 |
|
208 |
||
209 |
editing a file: |
|
9453 | 210 |
[exBegin] |
211 |
|f| |
|
212 |
||
213 |
f := Filename newTemporary. |
|
214 |
(f writeStream) nextPutAll:'hello world'; close. |
|
215 |
||
216 |
f edit |
|
217 |
[exEnd] |
|
360 | 218 |
" |
88 | 219 |
! ! |
1 | 220 |
|
2906 | 221 |
!Filename class methodsFor:'initialization'! |
222 |
||
223 |
initialize |
|
224 |
"initialize for the OS we are running on" |
|
225 |
||
8754 | 226 |
ConcreteClass isNil ifTrue:[ |
7702 | 227 |
self initializeConcreteClass |
228 |
]. |
|
2906 | 229 |
|
230 |
" |
|
231 |
self initialize |
|
232 |
" |
|
233 |
||
234 |
"Created: 7.9.1997 / 23:32:55 / cg" |
|
235 |
! |
|
236 |
||
237 |
initializeConcreteClass |
|
238 |
"initialize for the OS we are running on" |
|
239 |
||
8754 | 240 |
OperatingSystem isUNIXlike ifTrue:[ |
241 |
ConcreteClass := UnixFilename |
|
242 |
] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[ |
|
8738 | 243 |
ConcreteClass := PCFilename |
8754 | 244 |
] ifFalse:[OperatingSystem isVMSlike ifTrue:[ |
245 |
ConcreteClass := OpenVMSFilename |
|
2906 | 246 |
] ifFalse:[ |
8754 | 247 |
self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'. |
248 |
]]]. |
|
249 |
||
250 |
ConcreteClass isNil ifTrue:[ |
|
251 |
self error:'Filename: Missing concrete Filename class'. |
|
252 |
]. |
|
253 |
||
254 |
" |
|
255 |
self initializeConcreteClass |
|
2906 | 256 |
" |
257 |
||
258 |
"Modified: 7.9.1997 / 23:32:37 / cg" |
|
259 |
! |
|
260 |
||
261 |
reinitialize |
|
8738 | 262 |
"initialize for the OS we are running on (after a restart)" |
2906 | 263 |
|
9806 | 264 |
TempDirectory := nil. |
265 |
self initializeConcreteClass. |
|
2906 | 266 |
|
267 |
" |
|
8754 | 268 |
self reinitialize |
2906 | 269 |
" |
270 |
||
9806 | 271 |
"Created: / 07-09-1997 / 23:33:02 / cg" |
272 |
"Modified: / 29-08-2006 / 12:40:28 / cg" |
|
2906 | 273 |
! ! |
274 |
||
3959 | 275 |
!Filename class methodsFor:'instance creation'! |
276 |
||
277 |
currentDirectory |
|
278 |
"return a filename for the current directory" |
|
279 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
280 |
self isAbstract ifTrue:[ |
6256 | 281 |
^ ConcreteClass currentDirectory |
3959 | 282 |
]. |
283 |
||
284 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
285 |
||
286 |
^ self named:'.' |
|
287 |
"/ ^ self named:('.' asFilename pathName) |
|
288 |
||
289 |
" |
|
290 |
Filename currentDirectory |
|
291 |
" |
|
292 |
||
293 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
294 |
! |
|
295 |
||
296 |
defaultDirectory |
|
297 |
"ST80 compatibility: same as currentDirectory" |
|
298 |
||
299 |
^ self currentDirectory |
|
300 |
||
301 |
" |
|
302 |
Filename defaultDirectory |
|
303 |
" |
|
304 |
! |
|
305 |
||
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
306 |
defaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
307 |
"return the default temp directory as a filename. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
308 |
That is the same as TempDirectory, except that TempDirectory can be changed |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
309 |
from the outside (via tempDirectory:). |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
310 |
Use this for files which MUST remain the same (stx_sourceCache)" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
311 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
312 |
DefaultTempDirectory isNil ifTrue:[ |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
313 |
self tempDirectory. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
314 |
DefaultTempDirectory isNil ifTrue:[ |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
315 |
DefaultTempDirectory := TempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
316 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
317 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
318 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
319 |
DefaultTempDirectory exists ifFalse:[ |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
320 |
DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
321 |
makeDirectory; |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
322 |
addAccessRights:#(readUser readGroup readOthers |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
323 |
writeUser writeGroup writeOthers |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
324 |
executeUser executeGroup executeOthers |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
325 |
removeOnlyByOwner). |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
326 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
327 |
^ DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
328 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
329 |
" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
330 |
Filename tempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
331 |
Filename defaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
332 |
" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
333 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
334 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
335 |
"Modified: / 29-08-2006 / 12:57:16 / cg" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
336 |
! |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
337 |
|
10546 | 338 |
desktopDirectory |
339 |
"return your desktop directory. |
|
340 |
Under windows, thats the real desktop directory; |
|
341 |
under other OperatingSystems, the home directory is returned." |
|
342 |
||
343 |
|s| |
|
344 |
||
345 |
s := OperatingSystem getDesktopDirectory. |
|
346 |
s isNil ifTrue:[ |
|
347 |
^ self homeDirectory |
|
348 |
]. |
|
349 |
^ self named:s |
|
350 |
||
351 |
" |
|
352 |
Filename desktopDirectory |
|
353 |
" |
|
354 |
||
355 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
356 |
! |
|
357 |
||
11763 | 358 |
documentsDirectory |
359 |
"return your documents directory. |
|
360 |
Under windows, thats the real 'Documents' or 'My Documents'; |
|
361 |
under other OperatingSystems, the home directory is returned." |
|
362 |
||
363 |
|s| |
|
364 |
||
365 |
s := OperatingSystem getDocumentsDirectory. |
|
366 |
s isNil ifTrue:[ |
|
367 |
^ self homeDirectory |
|
368 |
]. |
|
369 |
^ self named:s |
|
370 |
||
371 |
" |
|
372 |
Filename documentsDirectory |
|
373 |
" |
|
374 |
||
375 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
376 |
! |
|
377 |
||
3959 | 378 |
findDefaultDirectory |
379 |
"same as #defaultDirectory for ST80 compatibility" |
|
380 |
||
381 |
^ self defaultDirectory |
|
382 |
||
383 |
"Created: 20.6.1997 / 17:00:29 / cg" |
|
384 |
! |
|
385 |
||
386 |
fromComponents:aCollectionOfDirectoryNames |
|
387 |
"create & return a new filename from components given in |
|
388 |
aCollectionOfDirectoryNames. If the first component is the name of the |
|
389 |
root directory (i.e. '/') an absolute path-filename is returned." |
|
390 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
391 |
self isAbstract ifTrue:[ |
6802 | 392 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
3959 | 393 |
]. |
394 |
||
6802 | 395 |
^ self named:(self nameFromComponents:aCollectionOfDirectoryNames) |
3959 | 396 |
|
397 |
" |
|
398 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
|
8754 | 399 |
PCFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
400 |
UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
|
401 |
OpenVMSFilename fromComponents:#('foo' 'bar' 'baz') |
|
402 |
||
3959 | 403 |
Filename fromComponents:#('foo' 'bar' 'baz') |
404 |
Filename fromComponents:#('/') |
|
405 |
||
406 |
Filename fromComponents: |
|
6802 | 407 |
(Filename components:('.' asFilename pathName)) |
3959 | 408 |
|
409 |
Filename fromComponents: |
|
6802 | 410 |
(Filename components:('.' asFilename name)) |
3959 | 411 |
" |
412 |
||
413 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
414 |
! |
|
415 |
||
416 |
fromUser |
|
417 |
"show a box to enter a filename. |
|
418 |
Return a filename instance or nil (if cancel was pressed)." |
|
419 |
||
420 |
|name| |
|
421 |
||
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
422 |
name := Dialog |
8738 | 423 |
requestFileName:'filename:' |
424 |
default:nil |
|
425 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory). |
|
426 |
||
427 |
name notEmptyOrNil ifTrue:[ |
|
428 |
^ self named:name |
|
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
429 |
]. |
3959 | 430 |
^ nil |
431 |
||
432 |
" |
|
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
433 |
Filename fromUser |
3959 | 434 |
" |
435 |
||
436 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
|
437 |
! |
|
438 |
||
439 |
homeDirectory |
|
440 |
"return your homeDirectory. |
|
441 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
|
442 |
(which is the currentDirectory) is returned." |
|
443 |
||
444 |
|s| |
|
445 |
||
446 |
s := OperatingSystem getHomeDirectory. |
|
447 |
s isNil ifTrue:[ |
|
9453 | 448 |
^ self defaultDirectory |
3959 | 449 |
]. |
450 |
^ self named:s |
|
451 |
||
452 |
" |
|
453 |
Filename homeDirectory |
|
454 |
" |
|
455 |
||
456 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
|
457 |
! |
|
458 |
||
459 |
named:aString |
|
460 |
"return a filename for a directory named aString. |
|
461 |
This is the same as 'aString asFilename'." |
|
462 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
463 |
self isAbstract ifTrue:[ |
8738 | 464 |
^ ConcreteClass named:aString |
3959 | 465 |
]. |
8738 | 466 |
^ self basicNew setName:aString |
3959 | 467 |
|
468 |
" |
|
469 |
Filename named:'/tmp/fooBar' |
|
470 |
" |
|
471 |
||
472 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
473 |
! |
|
474 |
||
475 |
newTemporary |
|
476 |
"return a new unique filename - use this for temporary files. |
|
477 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
478 |
unix process id, and nn is a unique number, incremented with every |
|
479 |
call to this method. |
|
480 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
4757 | 481 |
its value defines the temp directory. |
482 |
Notice, that no file is created by this - only a unique name |
|
483 |
is generated." |
|
3959 | 484 |
|
9912 | 485 |
^ self newTemporaryIn:(self tempDirectory) |
3959 | 486 |
|
487 |
" |
|
488 |
Filename newTemporary |
|
489 |
Filename newTemporary |
|
490 |
" |
|
491 |
||
492 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
493 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
|
494 |
! |
|
495 |
||
9912 | 496 |
newTemporaryDirectory |
497 |
"return a new unique temporary directory - use this for temporary files. |
|
498 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
499 |
unix process id, and nn is a unique number, incremented with every |
|
500 |
call to this method. |
|
501 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
502 |
its value defines the temp directory." |
|
503 |
||
504 |
^ self newTemporaryDirectoryIn:(self tempDirectory) |
|
505 |
! |
|
506 |
||
507 |
newTemporaryDirectoryIn:aDirectoryOrNil |
|
508 |
"return a new unique temporary directory in another directory, or the current dir. |
|
509 |
Use this for temporary files. |
|
510 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
511 |
unix process id, and nn is a unique number, incremented with every |
|
512 |
call to this method. |
|
513 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
514 |
its value defines the temp directory." |
|
515 |
||
516 |
|tempdir| |
|
517 |
||
518 |
tempdir := Filename newTemporaryIn:aDirectoryOrNil. |
|
519 |
tempdir exists ifTrue:[ |
|
520 |
tempdir recursiveRemove. |
|
521 |
]. |
|
522 |
tempdir makeDirectory. |
|
523 |
^ tempdir |
|
524 |
! |
|
525 |
||
526 |
newTemporaryIn:aDirectoryOrNil |
|
3959 | 527 |
"return a new unique filename - use this for temporary files. |
528 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
|
529 |
where xx is our unix process id, and nn is a unique number, incremented |
|
530 |
with every call to this method. |
|
531 |
Notice: only a unique filename object is created and returned - no physical |
|
532 |
file is created by this method (i.e. you have to send #writeStream or |
|
533 |
whatever to it in order to really create something). |
|
534 |
See also: #newTemporary which looks for a good temp directory." |
|
535 |
||
9912 | 536 |
^ self newTemporaryIn:aDirectoryOrNil nameTemplate:self tempFileNameTemplate |
3959 | 537 |
|
538 |
"temp files in '/tmp': |
|
539 |
||
540 |
Filename newTemporary |
|
541 |
" |
|
542 |
||
543 |
"temp files somewhere |
|
544 |
(not recommended - use above since it can be controlled via shell variables): |
|
545 |
||
546 |
UnixFilename newTemporaryIn:'/tmp' |
|
547 |
UnixFilename newTemporaryIn:'/tmp' |
|
548 |
UnixFilename newTemporaryIn:'/usr/tmp' |
|
549 |
UnixFilename newTemporaryIn:'/' |
|
550 |
" |
|
551 |
||
552 |
"a local temp file: |
|
553 |
||
554 |
Filename newTemporaryIn:'' |
|
555 |
Filename newTemporaryIn:nil |
|
556 |
Filename newTemporaryIn:'.' |
|
557 |
Filename newTemporaryIn:('source' asFilename) |
|
558 |
" |
|
559 |
||
560 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
|
561 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
|
562 |
! |
|
563 |
||
9912 | 564 |
newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
565 |
"return a new unique filename - use this for temporary files. |
9912 | 566 |
The filenames returned are in aDirectoryOrNil and named after the given template, |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
567 |
in which %1 and %2 are expanded to the unix process id, and a unique number, incremented |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
568 |
with every call to this method respectively. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
569 |
Notice: only a unique filename object is created and returned - no physical |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
570 |
file is created by this method (i.e. you have to send #writeStream or |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
571 |
whatever to it in order to really create something). |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
572 |
See also: #newTemporary which looks for a good temp directory." |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
573 |
|
8738 | 574 |
|nameString newTempFilename| |
575 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
576 |
self isAbstract ifTrue:[ |
9912 | 577 |
^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
578 |
]. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
579 |
|
8738 | 580 |
"although the above allows things to be redefined in concrete classes, |
581 |
the following should work on all systems ..." |
|
582 |
||
583 |
NextTempFilenameIndex isNil ifTrue:[ |
|
584 |
NextTempFilenameIndex := 1. |
|
585 |
]. |
|
586 |
||
587 |
[ |
|
588 |
nameString := template bindWith:OperatingSystem getProcessId with:NextTempFilenameIndex. |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
589 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
590 |
|
9912 | 591 |
(aDirectoryOrNil isNil or:[aDirectoryOrNil asString isEmpty]) ifFalse:[ |
592 |
newTempFilename := aDirectoryOrNil asFilename construct:nameString |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
593 |
] ifTrue:[ |
8738 | 594 |
newTempFilename := self named:nameString |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
595 |
] |
8738 | 596 |
] doWhile:[ |
597 |
"care for existing leftOver tempFiles |
|
598 |
from a previous boot of the OS |
|
599 |
i.e. my pid could be the same as when executed |
|
600 |
the last time before system reboot ...)" |
|
601 |
||
602 |
newTempFilename exists |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
603 |
]. |
8738 | 604 |
^ newTempFilename |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
605 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
606 |
"temp files in '/tmp': |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
607 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
608 |
Filename newTemporary |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
609 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
610 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
611 |
"temp files somewhere |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
612 |
(not recommended - use above since it can be controlled via shell variables): |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
613 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
614 |
UnixFilename newTemporaryIn:'/tmp' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
615 |
UnixFilename newTemporaryIn:'/tmp' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
616 |
UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
617 |
UnixFilename newTemporaryIn:'/' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
618 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
619 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
620 |
"a local temp file: |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
621 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
622 |
Filename newTemporaryIn:'' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
623 |
Filename newTemporaryIn:nil nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
624 |
Filename newTemporaryIn:'.' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
625 |
Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
626 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
627 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
628 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
629 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
630 |
! |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
631 |
|
4199 | 632 |
nullDevice |
633 |
"return the filename of the nullDevice (if available). |
|
634 |
returns nil, if the OperatingSystem does not support this." |
|
635 |
||
636 |
|s| |
|
637 |
||
8754 | 638 |
s := self nullFilename. |
4199 | 639 |
s isNil ifTrue:[ |
8754 | 640 |
^ nil |
4199 | 641 |
]. |
642 |
^ self named:s |
|
643 |
||
644 |
" |
|
8754 | 645 |
Filename nullDevice |
646 |
UnixFilename nullDevice |
|
647 |
PCFilename nullDevice |
|
4199 | 648 |
" |
649 |
||
650 |
"Created: / 19.5.1999 / 12:24:26 / cg" |
|
651 |
! |
|
652 |
||
6256 | 653 |
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames |
654 |
"create & return a new filename from components given in |
|
655 |
aCollectionOfDirectoryNames on a host named remoteHostString. |
|
656 |
An absolute network-filename is returned." |
|
657 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
658 |
self isAbstract ifTrue:[ |
6256 | 659 |
^ ConcreteClass remoteHost:remoteHostString |
660 |
rootComponents:aCollectionOfDirectoryNames |
|
661 |
]. |
|
662 |
||
10390 | 663 |
remoteHostString notEmptyOrNil ifTrue:[ |
664 |
self error:'remote hosts are not supported by OS' |
|
665 |
]. |
|
666 |
||
667 |
^ self rootComponents:aCollectionOfDirectoryNames |
|
668 |
||
669 |
" |
|
670 |
'file:///tmp/test' asURI asFilename |
|
671 |
" |
|
6256 | 672 |
! |
673 |
||
674 |
rootComponents:aCollectionOfDirectoryNames |
|
675 |
"create & return a new filename from components given in |
|
676 |
aCollectionOfDirectoryNames. |
|
677 |
An absolute path-filename is returned." |
|
678 |
||
679 |
|sep s| |
|
680 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
681 |
self isAbstract ifTrue:[ |
6256 | 682 |
^ ConcreteClass rootComponents:aCollectionOfDirectoryNames |
683 |
]. |
|
684 |
||
685 |
"/ fallBack - works on Unix & MSDOS |
|
686 |
||
8243 | 687 |
sep := self separatorString. |
6256 | 688 |
s := WriteStream on:''. |
689 |
aCollectionOfDirectoryNames do:[:component | |
|
690 |
component ~= sep ifTrue:[ |
|
691 |
s nextPutAll:sep; nextPutAll:component |
|
692 |
] |
|
693 |
]. |
|
694 |
s := s contents. |
|
695 |
s size == 0 ifTrue:[s := sep]. |
|
696 |
^ self named:s |
|
697 |
||
698 |
" |
|
8754 | 699 |
Filename rootComponents:#('/' 'foo' 'bar' 'baz') |
700 |
||
6256 | 701 |
Filename rootComponents:#('foo' 'bar' 'baz') |
8754 | 702 |
PCFilename rootComponents:#('foo' 'bar' 'baz') |
703 |
UnixFilename rootComponents:#('foo' 'bar' 'baz') |
|
704 |
||
6256 | 705 |
Filename rootComponents:#('/') |
706 |
||
707 |
Filename rootComponents: |
|
708 |
(Filename components:('.' asFilename pathName)) |
|
709 |
||
710 |
Filename rootComponents: |
|
711 |
(Filename components:('.' asFilename name)) |
|
712 |
" |
|
713 |
||
714 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
715 |
! |
|
716 |
||
3959 | 717 |
rootDirectory |
718 |
"return a filename for the root directory" |
|
719 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
720 |
self isAbstract ifTrue:[ |
8243 | 721 |
^ ConcreteClass rootDirectory |
3959 | 722 |
]. |
723 |
||
724 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
725 |
||
8243 | 726 |
^ self named:(self separatorString) |
3959 | 727 |
|
728 |
" |
|
729 |
Filename rootDirectory |
|
730 |
" |
|
731 |
||
732 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
733 |
! |
|
734 |
||
735 |
rootDirectoryOnVolume:aVolumeName |
|
736 |
"return a filename for the root directory on some volume" |
|
737 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
738 |
self isAbstract ifTrue:[ |
8668 | 739 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
3959 | 740 |
]. |
741 |
||
742 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
|
743 |
||
744 |
^ self rootDirectory |
|
745 |
||
746 |
" |
|
747 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
|
748 |
Filename rootDirectoryOnVolume:'d:' |
|
749 |
" |
|
750 |
||
751 |
"Modified: / 5.10.1998 / 12:45:39 / cg" |
|
752 |
! |
|
753 |
||
754 |
tempDirectory |
|
755 |
"return the temp directory as a filename. |
|
756 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
|
757 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
758 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
759 |
||
760 |
Notice: do not hardcode '/tmp' into your programs - things may be |
|
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
761 |
different on other operating systems. Also, the user may want to set the |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
762 |
TMPDIR environment variable to have her temp files somewhere else." |
3959 | 763 |
|
764 |
|tempDir| |
|
765 |
||
9806 | 766 |
TempDirectory isNil ifTrue:[ |
767 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
|
768 |
tempDir isNil ifTrue:[ |
|
769 |
tempDir := OperatingSystem getEnvironment:envVar. |
|
770 |
tempDir notNil ifTrue:[ |
|
771 |
tempDir := self named:tempDir. |
|
772 |
tempDir exists ifFalse:[ |
|
773 |
tempDir := nil. |
|
774 |
]. |
|
8660 | 775 |
]. |
776 |
]. |
|
7064 | 777 |
]. |
9806 | 778 |
tempDir isNil ifTrue:[ |
10850 | 779 |
tempDir := self named:(self defaultTempDirectoryName pathName) |
9806 | 780 |
]. |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
781 |
TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'. |
3959 | 782 |
]. |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
783 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
784 |
"Make sure, that the TempDirectory exists - it might have been removed |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
785 |
by a cleanup (cron) job. |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
786 |
Since it is shared between users, it must be accessable by all users." |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
787 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
788 |
TempDirectory exists ifFalse:[ |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
789 |
TempDirectory |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
790 |
makeDirectory; |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
791 |
addAccessRights:#(readUser readGroup readOthers |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
792 |
writeUser writeGroup writeOthers |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
793 |
executeUser executeGroup executeOthers |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
794 |
removeOnlyByOwner). |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
795 |
]. |
9806 | 796 |
^ TempDirectory |
3959 | 797 |
|
798 |
" |
|
799 |
Filename tempDirectory |
|
800 |
Filename tempDirectory pathName |
|
8660 | 801 |
Filename tempDirectory exists |
7836 | 802 |
Filename tempDirectory isWritable |
803 |
(Filename tempDirectory construct:'foo') makeDirectory |
|
8660 | 804 |
(Filename tempDirectory construct:'foo') remove |
3959 | 805 |
" |
806 |
||
9806 | 807 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
808 |
"Modified: / 29-08-2006 / 12:57:16 / cg" |
|
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
809 |
! |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
810 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
811 |
tempDirectory:aFilename |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
812 |
"set the xdefault temporary directory pathname" |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
813 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
814 |
|temp| |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
815 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
816 |
aFilename isNil ifTrue:[ |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
817 |
TempDirectory := nil. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
818 |
^ self. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
819 |
]. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
820 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
821 |
temp := aFilename asFilename. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
822 |
self assert:temp isDirectory. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
823 |
TempDirectory := temp. |
3959 | 824 |
! ! |
825 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
826 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
827 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
828 |
concreteClass |
6256 | 829 |
"different subclasses of Filename are used for different |
830 |
OperatingSystems; concreteClass is supposed to return an appropriate class." |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
831 |
|
2906 | 832 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
833 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
834 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 835 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
836 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
837 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
838 |
defaultClass |
6256 | 839 |
"different subclasses of Filename are used for different |
840 |
OperatingSystems; defaultClass is supposed to return an appropriate class" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
841 |
|
2906 | 842 |
^ ConcreteClass |
843 |
||
844 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
7836 | 845 |
! |
846 |
||
847 |
defaultTempDirectoryName |
|
848 |
"return the default temp directory as a filename. |
|
849 |
This is used, if no special preferences were defined in |
|
850 |
any of the TEMP-environment variables (see tempDirectory)." |
|
851 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
852 |
self isAbstract ifTrue:[ |
8738 | 853 |
^ ConcreteClass defaultTempDirectoryName |
7836 | 854 |
]. |
855 |
||
10994
1a3776d0b845
always return a fileName from defaultTempDirectoryName
fm
parents:
10969
diff
changeset
|
856 |
^ '/tmp' asFilename |
7836 | 857 |
|
858 |
" |
|
859 |
Filename defaultTempDirectoryName |
|
860 |
" |
|
861 |
||
862 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
863 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
864 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
865 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
866 |
|
2922 | 867 |
!Filename class methodsFor:'misc'! |
868 |
||
869 |
canonicalize:aPathString |
|
3077 | 870 |
"convert the argument, aPathString to a good format. |
871 |
This should eliminate useless directory components (i.e. '././') |
|
872 |
and useless tree walks (i.e. '../foo/..')." |
|
873 |
||
6802 | 874 |
|comps newComps parentName currentName rootName| |
875 |
||
876 |
parentName := self parentDirectoryName. |
|
877 |
currentName := self currentDirectoryName. |
|
878 |
rootName := self rootDirectory name. |
|
879 |
||
880 |
comps := self components:aPathString. |
|
881 |
newComps := OrderedCollection new. |
|
882 |
comps do:[:eachComponent | |
|
9263 | 883 |
(eachComponent ~= currentName |
884 |
and:[eachComponent notEmpty or:[newComps size == 1]]) ifTrue:[ |
|
6802 | 885 |
eachComponent = parentName ifTrue:[ |
886 |
(newComps isEmpty |
|
9263 | 887 |
or:[newComps = (Array with:rootName) |
888 |
or:[newComps last = parentName]]) ifTrue:[ |
|
6802 | 889 |
newComps add:eachComponent |
890 |
] ifFalse:[ |
|
891 |
newComps removeLast |
|
892 |
]. |
|
893 |
] ifFalse:[ |
|
894 |
newComps add:eachComponent |
|
895 |
]. |
|
896 |
] |
|
7666
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
897 |
]. |
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
898 |
"/ add current Directory if empty |
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
899 |
newComps isEmpty ifTrue:[ |
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
900 |
newComps add:currentName. |
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
901 |
]. |
6802 | 902 |
^ self nameFromComponents:newComps |
903 |
||
904 |
" |
|
905 |
Filename canonicalize:'/etc/../etc' |
|
906 |
Filename canonicalize:'/home/cg/../' |
|
907 |
Filename canonicalize:'/home/cg/../././' |
|
7666
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
908 |
Filename canonicalize:'./home/cg/../././' |
6802 | 909 |
Filename canonicalize:'/home/././cg/../././' |
910 |
Filename canonicalize:'/home/././cg/././' |
|
911 |
Filename canonicalize:'/home/cg/../../..' |
|
912 |
Filename canonicalize:'cg/../../..' |
|
7666
4cfcb1c3d0cc
cononilize current directory '.' no empty filename anymore
penk
parents:
7596
diff
changeset
|
913 |
Filename canonicalize:'./' |
6803 | 914 |
Filename canonicalize:'/home/.' |
9263 | 915 |
Filename canonicalize:'/home/../..' |
916 |
Filename canonicalize:'//foo' |
|
917 |
Filename canonicalize:'///foo' |
|
918 |
Filename canonicalize:'//foo//bar' |
|
6802 | 919 |
" |
3077 | 920 |
! |
921 |
||
922 |
filterSeps:aFilenameString |
|
923 |
"ST80 compatibility: |
|
924 |
filter out (invalid) separators in aFilenameString. |
|
925 |
We recommend using #makeLegalFilename" |
|
926 |
||
3658 | 927 |
^ aFilenameString copyReplaceAll:(Character space) with:$_. |
3077 | 928 |
|
929 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 930 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 931 |
! |
932 |
||
933 |
suggest:aFilenameString |
|
934 |
"return a fileNamestring based on the argument, |
|
935 |
which is legal on the current platform." |
|
936 |
||
937 |
^ self canonicalize:aFilenameString |
|
938 |
||
939 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 940 |
! ! |
941 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
942 |
!Filename class methodsFor:'queries'! |
2 | 943 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
944 |
components:aString |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
945 |
"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
|
946 |
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
|
947 |
the final component. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
948 |
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
|
949 |
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
|
950 |
|
3852 | 951 |
|sep f vol rest components| |
2503 | 952 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
953 |
self isAbstract ifTrue:[ |
8668 | 954 |
^ ConcreteClass components:aString |
2906 | 955 |
]. |
956 |
||
957 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
3852 | 958 |
"/ However, MSDOS drive-letters and network drives are |
959 |
"/ not correctly handled here. |
|
2906 | 960 |
|
2503 | 961 |
sep := self separator. |
3852 | 962 |
f := aString asFilename. |
963 |
vol := f volume. |
|
964 |
vol size ~~ 0 ifTrue:[ |
|
8668 | 965 |
rest := f localPathName. |
3852 | 966 |
] ifFalse:[ |
8668 | 967 |
rest := aString |
3852 | 968 |
]. |
969 |
||
970 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
971 |
components first isEmpty ifTrue:[ |
8668 | 972 |
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
|
973 |
]. |
3852 | 974 |
|
975 |
"/ prepend volume to first component (the root directory) |
|
976 |
vol size ~~ 0 ifTrue:[ |
|
8668 | 977 |
components at:1 put:(vol , (components at:1)). |
3852 | 978 |
]. |
3373 | 979 |
components last isEmpty ifTrue:[ |
8668 | 980 |
^ components copyWithoutLast:1 |
3373 | 981 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
982 |
^ components |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
983 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
984 |
" |
3373 | 985 |
Filename components:'/foo/bar/baz' |
3852 | 986 |
Filename components:'/' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
987 |
Filename components:'foo/bar/baz' |
2503 | 988 |
Filename components:'foo/bar' |
989 |
Filename components:'foo' |
|
3852 | 990 |
Filename components:'/foo' |
991 |
||
992 |
Filename components:'\' |
|
993 |
Filename components:'\foo' |
|
994 |
Filename components:'\foo\' |
|
995 |
Filename components:'\foo\bar' |
|
996 |
Filename components:'\foo\bar\' |
|
997 |
Filename components:'c:' |
|
998 |
Filename components:'c:\' |
|
999 |
Filename components:'c:\foo' |
|
1000 |
Filename components:'c:\foo\' |
|
1001 |
Filename components:'c:\foo\bar' |
|
1002 |
Filename components:'c:\foo\bar\' |
|
1003 |
Filename components:'\\idefix' |
|
1004 |
Filename components:'\\idefix\home' |
|
1005 |
Filename components:'\\idefix\home\bar' |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1006 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1007 |
|
3852 | 1008 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1009 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1010 |
|
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1011 |
currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1012 |
"return a filename for the current directory" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1013 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1014 |
self isAbstract ifTrue:[ |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1015 |
^ ConcreteClass currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1016 |
]. |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1017 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1018 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1019 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1020 |
^ '.' |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1021 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1022 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1023 |
Filename currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1024 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1025 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1026 |
"Modified: / 8.9.1997 / 00:24:15 / cg" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1027 |
"Created: / 21.10.1998 / 17:49:57 / cg" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1028 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1029 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1030 |
defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1031 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1032 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1033 |
^ self defaultDirectory name |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1034 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1035 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1036 |
Filename defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1037 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1038 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1039 |
|
2963 | 1040 |
directorySuffix |
1041 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
1042 |
The default is nil here, redefined for VMS" |
|
1043 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1044 |
self isAbstract ifTrue:[ |
8668 | 1045 |
^ ConcreteClass directorySuffix |
2963 | 1046 |
]. |
1047 |
||
1048 |
^ nil |
|
1049 |
! |
|
1050 |
||
1523 | 1051 |
errorReporter |
1052 |
"who knows the signals to report errors?" |
|
1053 |
||
1054 |
^ FileStream |
|
1055 |
||
1056 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
1057 |
! |
|
1058 |
||
440 | 1059 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
1060 |
"perform filename completion on aString in some directory; |
|
1061 |
return the longest matching filename prefix as a string. |
|
1318 | 1062 |
The boolean directoriesOnly and filesOnly control respectively, |
1063 |
if only directories or only regular files are to be considered for completion. |
|
1064 |
If multiple files match, the exception block aBlock is evaluated with a |
|
1065 |
filename representing the directory (where the match was done) as argument. |
|
440 | 1066 |
(this may be different from the inDirectory argument, if aString is absolute |
1067 |
or starts with ../)" |
|
1068 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1069 |
self isAbstract ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1070 |
^ ConcreteClass |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1071 |
filenameCompletionFor:aString |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1072 |
directory:inDirectory |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1073 |
directoriesOnly:directoriesOnly |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1074 |
filesOnly:filesOnly |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1075 |
ifMultiple:aBlock |
2906 | 1076 |
]. |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1077 |
^ self filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock forMultipleDo:nil |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1078 |
! |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1079 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1080 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock forMultipleDo:aMultipleBlock |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1081 |
"perform filename completion on aString in some directory; |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1082 |
return the longest matching filename prefix as a string. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1083 |
The boolean directoriesOnly and filesOnly control respectively, |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1084 |
if only directories or only regular files are to be considered for completion. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1085 |
If multiple files match, the exception block aBlock is evaluated with a |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1086 |
filename representing the directory (where the match was done) as argument and the aMultipleBlock |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1087 |
is evaluated with both the directory (where the match was done) and the matchSet |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1088 |
(list of matched filenames) as arguments. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1089 |
(this may be different from the inDirectory argument, if aString is absolute |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1090 |
or starts with ../)" |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1091 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1092 |
|s f matchSet nMatch name dir isAbsolute sep| |
2906 | 1093 |
|
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1094 |
aString size == 0 ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1095 |
aBlock value:(self named:'.'). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1096 |
^ '' |
440 | 1097 |
]. |
1098 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1099 |
sep := self separator. |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1100 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1101 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1102 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1103 |
f := self named:aString. |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
1104 |
isAbsolute := f isAbsolute. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1105 |
matchSet := f filenameCompletionIn:inDirectory. "/ BAD DESIGN: has side effect on f |
440 | 1106 |
dir := f directory. |
1107 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1108 |
matchSet := matchSet select:[:aFilename | |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1109 |
|f isDir| |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1110 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1111 |
isAbsolute ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1112 |
f := aFilename asFilename |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1113 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1114 |
f := (dir construct:aFilename). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1115 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1116 |
isDir := f isDirectory. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1117 |
directoriesOnly ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1118 |
isDir |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1119 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1120 |
filesOnly ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1121 |
isDir not |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1122 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1123 |
true |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1124 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1125 |
] |
440 | 1126 |
]. |
1127 |
||
6803 | 1128 |
f := f asCanonicalizedFilename. |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1129 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1130 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1131 |
more than one possible completion - |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1132 |
" |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1133 |
aMultipleBlock notNil ifTrue:[ |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1134 |
aMultipleBlock value:f value:matchSet. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1135 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1136 |
aBlock value:f |
440 | 1137 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1138 |
|
440 | 1139 |
" |
1140 |
even with more than one possible completion, |
|
1141 |
f's name is now the common prefix |
|
1142 |
" |
|
1143 |
name := f asString. |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1144 |
|
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1145 |
nMatch <= 1 ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1146 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1147 |
exactly one possible completion - |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1148 |
" |
3752 | 1149 |
"/ f := dir construct:matchSet first. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1150 |
false "directoriesOnly" ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1151 |
(f exists and:[f isDirectory]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1152 |
(name endsWith:sep) ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1153 |
name := name , sep asString |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1154 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1155 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1156 |
] |
440 | 1157 |
]. |
1158 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1159 |
s := name. |
440 | 1160 |
|
1161 |
"/ special: if there was no change, and the string represented |
|
1162 |
"/ is a directories name, add a directory separator |
|
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
1163 |
((nMatch == 1) or:[s = aString]) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1164 |
(s endsWith:sep) ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1165 |
(self named:s) isDirectory ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1166 |
^ s , sep asString |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1167 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1168 |
]. |
440 | 1169 |
]. |
1170 |
||
1171 |
^ s |
|
1318 | 1172 |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1173 |
"Modified: / 30.4.1999 / 09:40:13 / cg" |
615 | 1174 |
! |
1175 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1176 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1177 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1178 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1179 |
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
|
1180 |
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
|
1181 |
The returned strings are the expanded names, in the same form |
2550 | 1182 |
as given in pattern. |
1183 |
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
|
1184 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1185 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1186 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1187 |
self isAbstract ifTrue:[ |
8738 | 1188 |
^ ConcreteClass filesMatching:aPattern |
2906 | 1189 |
]. |
1190 |
||
1191 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1192 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1193 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1194 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1195 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1196 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1197 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1198 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1199 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1200 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1201 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1202 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1203 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1204 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1205 |
|
2906 | 1206 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 1207 |
! |
1208 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1209 |
isAbstract |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1210 |
"return true, if this is not a concrete class" |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1211 |
|
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1212 |
^ self == Filename |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1213 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1214 |
|
2903 | 1215 |
isBadCharacter:aCharacter |
1216 |
"return true, if aCharacter is unallowed in a filename." |
|
1217 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1218 |
self isAbstract ifTrue:[ |
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1219 |
^ ConcreteClass isBadCharacter:aCharacter |
2906 | 1220 |
]. |
1221 |
||
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1222 |
^ aCharacter isControlCharacter |
2903 | 1223 |
! |
1224 |
||
1225 |
isCaseSensitive |
|
1226 |
"return true, if filenames are case sensitive. |
|
1227 |
We ask the OS about this, to be independent here." |
|
1228 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1229 |
self isAbstract ifTrue:[ |
8668 | 1230 |
^ ConcreteClass isCaseSensitive |
2906 | 1231 |
]. |
1232 |
||
2903 | 1233 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 1234 |
|
1235 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 1236 |
! |
1237 |
||
615 | 1238 |
localNameStringFrom:aString |
1239 |
"ST-80 compatibility. |
|
1240 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 1241 |
GUESS: |
8243 | 1242 |
does it strip off any volume characters and make a path relative ?" |
2922 | 1243 |
|
1244 |
|sep| |
|
615 | 1245 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1246 |
self isAbstract ifTrue:[ |
8243 | 1247 |
^ ConcreteClass localNameStringFrom:aString |
2906 | 1248 |
]. |
1249 |
||
8243 | 1250 |
sep := self separatorString. |
2922 | 1251 |
(aString startsWith:sep) ifTrue:[ |
8243 | 1252 |
^ aString copyFrom:sep size + 1 |
615 | 1253 |
]. |
1254 |
^ aString |
|
1255 |
||
1256 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 1257 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 1258 |
! |
1259 |
||
2908 | 1260 |
maxComponentLength |
1261 |
"return the maximum number of characters a filename component may |
|
1262 |
be in size. This depends on the OperatingSystem." |
|
1263 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1264 |
self isAbstract ifTrue:[ |
8668 | 1265 |
^ ConcreteClass maxComponentLength |
2908 | 1266 |
]. |
1267 |
^ OperatingSystem maxFileNameLength |
|
1268 |
! |
|
1269 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1270 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1271 |
"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
|
1272 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1273 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1274 |
self isAbstract ifTrue:[ |
8668 | 1275 |
^ ConcreteClass maxLength |
2908 | 1276 |
]. |
1277 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1278 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1279 |
"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
|
1280 |
"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
|
1281 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1282 |
|
3171 | 1283 |
nullFilename |
1284 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
1285 |
The default is nil here" |
|
1286 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1287 |
self isAbstract ifTrue:[ |
8668 | 1288 |
^ ConcreteClass nullFilename |
3171 | 1289 |
]. |
1290 |
||
8754 | 1291 |
^ OperatingSystem getNullDevice |
3171 | 1292 |
|
1293 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1294 |
! |
|
1295 |
||
615 | 1296 |
parentDirectoryName |
1297 |
"return the name used for the parent directory. |
|
1298 |
This is '..' for unix and dos-like systems. |
|
1299 |
(there may be more in the future." |
|
1300 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1301 |
self isAbstract ifTrue:[ |
8668 | 1302 |
^ ConcreteClass parentDirectoryName |
2906 | 1303 |
]. |
1304 |
||
1305 |
^ OperatingSystem parentDirectoryName |
|
1306 |
||
1307 |
" |
|
1308 |
Filename parentDirectoryName |
|
1309 |
" |
|
1310 |
||
1311 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1312 |
! |
1313 |
||
1314 |
separator |
|
1315 |
"return the file/directory separator. |
|
2906 | 1316 |
This is to be redefined in concrete classes; |
1317 |
the following default usually leads to a flat view of |
|
1318 |
the fileSystem (huh - BS2000 ?)" |
|
1319 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1320 |
self isAbstract ifTrue:[ |
8243 | 1321 |
^ ConcreteClass separator |
1322 |
]. |
|
1323 |
^ $_ |
|
1324 |
||
1325 |
" |
|
8754 | 1326 |
Filename separator |
1327 |
PCFilename separator |
|
8243 | 1328 |
" |
2906 | 1329 |
|
1330 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1331 |
! |
1332 |
||
8243 | 1333 |
separatorString |
1334 |
"return the file/directory separator as a string." |
|
1335 |
||
1336 |
^ self separator asString |
|
1337 |
||
1338 |
" |
|
1339 |
Filename separatorString |
|
1340 |
" |
|
1341 |
! |
|
1342 |
||
615 | 1343 |
suffixSeparator |
1344 |
"return the filename suffix separator. |
|
1345 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 1346 |
(there is currently no known system, where this differs)" |
615 | 1347 |
|
1348 |
^ $. |
|
1349 |
||
1350 |
" |
|
1351 |
Filename suffixSeparator |
|
1352 |
" |
|
1353 |
||
1354 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1355 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1356 |
! |
1357 |
||
2906 | 1358 |
tempFileNameTemplate |
1359 |
"return a template for temporary files. |
|
1360 |
This is expanded with the current processID and a sequenceNumber |
|
1361 |
to generate a unique filename." |
|
1362 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1363 |
self isAbstract ifTrue:[ |
8668 | 1364 |
^ ConcreteClass tempFileNameTemplate |
2906 | 1365 |
]. |
1366 |
||
1367 |
^ 'stxtmp_%1_%2' |
|
1368 |
||
1369 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1370 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1371 |
! |
|
1372 |
||
615 | 1373 |
volumes |
1374 |
"ST-80 compatibility. |
|
2896 | 1375 |
GUESS: does it return the available drives on MSDOS systems ? |
1376 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1377 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1378 |
self isAbstract ifTrue:[ |
8679 | 1379 |
^ ConcreteClass volumes |
2906 | 1380 |
]. |
1381 |
||
2896 | 1382 |
^ OperatingSystem getDriveList |
615 | 1383 |
|
8679 | 1384 |
" |
1385 |
Filename volumes |
|
1386 |
" |
|
615 | 1387 |
! ! |
1388 |
||
6383 | 1389 |
!Filename class methodsFor:'utilities'! |
1390 |
||
6802 | 1391 |
nameFromComponents:aCollectionOfDirectoryNames |
1392 |
"return a filenameString from components given in aCollectionOfDirectoryNames. |
|
1393 |
If the first component is the name of the root directory (i.e. '/'), |
|
1394 |
an absolute path-string is returned." |
|
1395 |
||
1396 |
|sep s| |
|
1397 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1398 |
self isAbstract ifTrue:[ |
6802 | 1399 |
^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames |
1400 |
]. |
|
1401 |
||
1402 |
"/ fallBack - works on Unix & MSDOS |
|
1403 |
||
8243 | 1404 |
sep := self separatorString. |
6802 | 1405 |
s := ''. |
1406 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
|
1407 |
index == 1 ifTrue:[ |
|
7074 | 1408 |
s := component. |
1409 |
] ifFalse:[ |
|
1410 |
(index == 2 and:[ (s endsWith:sep) ]) ifTrue:[ |
|
6802 | 1411 |
s := s , component |
7074 | 1412 |
] ifFalse:[ |
1413 |
s := s , sep , component |
|
6802 | 1414 |
] |
1415 |
]. |
|
1416 |
]. |
|
1417 |
^ s |
|
1418 |
||
1419 |
" |
|
1420 |
Filename nameFromComponents:#('/' 'foo' 'bar' 'baz') |
|
1421 |
Filename nameFromComponents:#('foo' 'bar' 'baz') |
|
7074 | 1422 |
Filename nameFromComponents:#('/') |
1423 |
||
1424 |
|comps| |
|
1425 |
comps := Filename components:'/foo/bar/baz'. |
|
1426 |
Filename nameFromComponents:comps |
|
1427 |
||
1428 |
|comps| |
|
1429 |
comps := Filename components:'\foo\bar\baz'. |
|
1430 |
Filename nameFromComponents:comps |
|
1431 |
||
1432 |
|comps| |
|
1433 |
comps := Filename components:'c:\foo\bar\baz'. |
|
1434 |
Filename nameFromComponents:comps |
|
1435 |
||
1436 |
|comps| |
|
1437 |
comps := Filename components:'foo\bar\baz'. |
|
1438 |
Filename nameFromComponents:comps |
|
1439 |
||
1440 |
|comps| |
|
1441 |
comps := Filename components:'foo'. |
|
1442 |
Filename nameFromComponents:comps |
|
1443 |
||
1444 |
|comps| |
|
1445 |
comps := Filename components:'\'. |
|
1446 |
Filename nameFromComponents:comps |
|
1447 |
||
1448 |
|comps| |
|
1449 |
comps := Filename components:'c:\'. |
|
1450 |
Filename nameFromComponents:comps |
|
6802 | 1451 |
" |
1452 |
||
1453 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
1454 |
! |
|
1455 |
||
6383 | 1456 |
readingFile:aPathName do:aBlock |
1457 |
"create a read-stream on a file, evaluate aBlock, passing that stream, |
|
1458 |
and return the blocks value. |
|
1459 |
Ensures that the stream is closed." |
|
1460 |
||
6529 | 1461 |
^ aPathName asFilename readingFileDo:aBlock. |
1462 |
||
1463 |
" |
|
1464 |
read the first line from some file: |
|
1465 |
||
1466 |
|rslt| |
|
1467 |
||
1468 |
rslt := |
|
1469 |
Filename |
|
1470 |
readingFile:'/etc/passwd' |
|
1471 |
do:[:s | |
|
1472 |
s nextLine |
|
1473 |
]. |
|
1474 |
Transcript showCR:rslt. |
|
1475 |
" |
|
1476 |
||
1477 |
" |
|
1478 |
find all used shells in /etc/passwd and count their usage: |
|
1479 |
||
6383 | 1480 |
|rslt| |
1481 |
||
6529 | 1482 |
rslt := |
1483 |
Filename |
|
1484 |
readingFile:'/etc/passwd' |
|
1485 |
do: |
|
1486 |
[:s | |
|
1487 |
|shells| |
|
1488 |
||
1489 |
shells := Bag new. |
|
1490 |
s linesDo: |
|
1491 |
[:line | |
|
1492 |
|parts| |
|
1493 |
||
1494 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
1495 |
shells add:(parts seventh). |
|
1496 |
]. |
|
1497 |
shells contents |
|
1498 |
]. |
|
1499 |
Transcript showCR:rslt. |
|
1500 |
" |
|
6383 | 1501 |
! ! |
1502 |
||
7261 | 1503 |
!Filename methodsFor:'Compatibility-VW5.4'! |
6139 | 1504 |
|
1505 |
asLogicalFileSpecification |
|
1506 |
^ self |
|
1507 |
||
1508 |
"Created: / 30.10.2001 / 17:31:10 / cg" |
|
6447 | 1509 |
! |
1510 |
||
10583 | 1511 |
canBeWritten |
1512 |
"same as isWritable - for ST-80 compatibility" |
|
1513 |
||
1514 |
^ self isWritable |
|
1515 |
||
1516 |
" |
|
1517 |
'/foo/bar' asFilename canBeWritten |
|
1518 |
'/tmp' asFilename canBeWritten |
|
1519 |
'Makefile' asFilename canBeWritten |
|
1520 |
" |
|
1521 |
! |
|
1522 |
||
7596 | 1523 |
definitelyExists |
1524 |
"for now - a kludge" |
|
1525 |
||
1526 |
^ self exists |
|
1527 |
! |
|
1528 |
||
6447 | 1529 |
extension |
6454 | 1530 |
"return the receiver's extension; |
1531 |
that is the characters from and including |
|
1532 |
the last period or nil, if there is none." |
|
1533 |
||
1534 |
|string idx| |
|
1535 |
||
1536 |
string := self asString. |
|
1537 |
idx := string lastIndexOf:$.. |
|
1538 |
idx > 1 ifTrue:[ |
|
1539 |
^ string copyFrom:idx |
|
1540 |
]. |
|
1541 |
^ nil |
|
1542 |
||
1543 |
" |
|
1544 |
'foo.html' asFilename extension |
|
1545 |
'foo.bar' asFilename extension |
|
1546 |
'foo.bar.baz' asFilename extension |
|
1547 |
'foo.' asFilename extension |
|
1548 |
'foo' asFilename extension |
|
1549 |
'.login' asFilename extension |
|
1550 |
" |
|
6139 | 1551 |
! ! |
1552 |
||
615 | 1553 |
!Filename methodsFor:'comparing'! |
1554 |
||
1555 |
= aFilename |
|
1556 |
"return true, if the argument represents the same filename" |
|
1557 |
||
1558 |
|str| |
|
1559 |
||
1560 |
self species == aFilename species ifTrue:[ |
|
9453 | 1561 |
str := aFilename asString. |
1562 |
self class isCaseSensitive ifTrue:[ |
|
1563 |
^ nameString = str |
|
1564 |
]. |
|
1565 |
^ nameString sameAs:str |
|
615 | 1566 |
]. |
1567 |
^ false |
|
1568 |
! |
|
1569 |
||
5877 | 1570 |
contentsIsPrefixOf:aFilename |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1571 |
"return true if the contents of the file represented by the receiver |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1572 |
is the same as or a prefix of the contents of the file represented by the argument, aFilename. |
3868 | 1573 |
This compares the files actual contents; not the filenames." |
1574 |
||
8771 | 1575 |
|f2 s1 s2 bufferSize buffer1 buffer2 n| |
1576 |
||
1577 |
bufferSize := 8192 * 4. |
|
4979 | 1578 |
|
1579 |
f2 := aFilename asFilename. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1580 |
self fileSize > f2 fileSize ifTrue:[^ false]. |
3868 | 1581 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1582 |
[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1583 |
s1 := self readStream. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1584 |
s2 := f2 readStream. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1585 |
s1 binary. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1586 |
s2 binary. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1587 |
|
8771 | 1588 |
buffer1 := ByteArray new:bufferSize. |
1589 |
buffer2 := ByteArray new:bufferSize. |
|
7776 | 1590 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1591 |
[s1 atEnd] whileFalse:[ |
8771 | 1592 |
n := s1 nextBytes:bufferSize into:buffer1 startingAt:1. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1593 |
n == 0 ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1594 |
"/ receiver shorter. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1595 |
^ true |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1596 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1597 |
(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1598 |
"/ aFilename shorter |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1599 |
^ false |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1600 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1601 |
buffer1 ~= buffer2 ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1602 |
^ false |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1603 |
] |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1604 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1605 |
"/ receiver shorter or same size. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1606 |
] ensure:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1607 |
s1 notNil ifTrue:[s1 close]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1608 |
s2 notNil ifTrue:[s2 close]. |
3868 | 1609 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1610 |
^ true |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1611 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1612 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1613 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1614 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1615 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1616 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1617 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1618 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1619 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1620 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1621 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1622 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1623 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1624 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1625 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1626 |
|
5877 | 1627 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1628 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1629 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1630 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1631 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1632 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1633 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1634 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1635 |
|
5877 | 1636 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1637 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1638 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1639 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1640 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1641 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1642 |
|
5877 | 1643 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1644 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1645 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1646 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1647 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1648 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1649 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1650 |
|
5877 | 1651 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
1652 |
||
1653 |
" |
|
1654 |
! |
|
1655 |
||
1656 |
contentsStartsWithContentsOf:aFilename |
|
1657 |
"return true if the contents of the file represented by aFilename |
|
1658 |
is the same as or a prefix of the contents of the file represented by the receiver. |
|
1659 |
This compares the files actual contents; not the filenames." |
|
1660 |
||
1661 |
^ aFilename asFilename contentsIsPrefixOf:self |
|
1662 |
||
1663 |
" |
|
1664 |
|s| |
|
1665 |
||
1666 |
s := 'testFile1' asFilename writeStream. |
|
1667 |
s nextPutAll:'11111'. |
|
1668 |
s nextPutAll:'22222'. |
|
1669 |
s nextPutAll:'33333'. |
|
1670 |
s close. |
|
1671 |
||
1672 |
s := 'testFile2' asFilename writeStream. |
|
1673 |
s nextPutAll:'11111'. |
|
1674 |
s nextPutAll:'22222'. |
|
1675 |
s nextPutAll:'33333'. |
|
1676 |
s close. |
|
1677 |
||
1678 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1679 |
||
1680 |
s := 'testFile2' asFilename writeStream. |
|
1681 |
s nextPutAll:'11111'. |
|
1682 |
s nextPutAll:'22222'. |
|
1683 |
s nextPutAll:'33333'. |
|
1684 |
s nextPutAll:'44444'. |
|
1685 |
s close. |
|
1686 |
||
1687 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1688 |
||
1689 |
s := 'testFile2' asFilename writeStream. |
|
1690 |
s nextPutAll:'11111'. |
|
1691 |
s nextPutAll:'22222'. |
|
1692 |
s close. |
|
1693 |
||
1694 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
1695 |
||
1696 |
s := 'testFile2' asFilename writeStream. |
|
1697 |
s nextPutAll:'11111'. |
|
1698 |
s nextPutAll:'22222'. |
|
1699 |
s nextPutAll:'33334'. |
|
1700 |
s close. |
|
1701 |
||
1702 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1703 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1704 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1705 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1706 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1707 |
hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1708 |
"return an integer useful as a hash-key" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1709 |
|
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
1710 |
self class isCaseSensitive ifFalse:[ |
11425 | 1711 |
^ nameString asUppercase hash |
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
1712 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1713 |
^ nameString hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1714 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1715 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1716 |
sameContentsAs:aFilename |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1717 |
"return true if the file represented by the receiver has the |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1718 |
same contents as the file represented by the argument, aFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1719 |
This compares the files actual contents; not the filenames." |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1720 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1721 |
|f2| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1722 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1723 |
f2 := aFilename asFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1724 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
5877 | 1725 |
^ self contentsIsPrefixOf:f2. |
3868 | 1726 |
|
1727 |
" |
|
1728 |
'Make.proto' asFilename sameContentsAs:'Makefile' |
|
7122 | 1729 |
'Make.proto' asFilename sameContentsAs:'Make.proto' |
3868 | 1730 |
" |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1731 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1732 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1733 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1734 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1735 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1736 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1737 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1738 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1739 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1740 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1741 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1742 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1743 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1744 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1745 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1746 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1747 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifFalse:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1748 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1749 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1750 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1751 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1752 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1753 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1754 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1755 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1756 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1757 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1758 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1759 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1760 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1761 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1762 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1763 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1764 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1765 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1766 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1767 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1768 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1769 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1770 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1771 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1772 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1773 |
" |
615 | 1774 |
! ! |
1775 |
||
1776 |
!Filename methodsFor:'converting'! |
|
1777 |
||
1778 |
asAbsoluteFilename |
|
1779 |
"return the receiver converted to a filename with |
|
1780 |
an absolute pathname." |
|
1781 |
||
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
1782 |
^ self class named:self pathName |
7332 | 1783 |
|
1784 |
" |
|
1785 |
'.' asFilename |
|
1786 |
'.' asFilename asAbsoluteFilename |
|
9173 | 1787 |
'c:' asFilename asAbsoluteFilename |
7332 | 1788 |
" |
615 | 1789 |
! |
1790 |
||
10769 | 1791 |
asAutoDeletedFilename |
11784 | 1792 |
^ AutoDeletedFilename basicNew setName:self name |
10769 | 1793 |
! |
1794 |
||
6802 | 1795 |
asCanonicalizedFilename |
1796 |
"return the receiver converted to a filename without intermediate ..'s and .'s |
|
1797 |
(similar to an absolute pathname, but symlinks are not resolved)." |
|
1798 |
||
1799 |
^ self class named:(self class canonicalize:nameString) |
|
7074 | 1800 |
|
1801 |
" |
|
1802 |
'c:\test\work' asFilename asCanonicalizedFilename |
|
1803 |
'/test/work' asFilename asCanonicalizedFilename |
|
1804 |
" |
|
6802 | 1805 |
! |
1806 |
||
615 | 1807 |
asFilename |
1970 | 1808 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 1809 |
|
1810 |
"Thats pretty easy here :-)" |
|
1811 |
^ self |
|
1970 | 1812 |
|
1813 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 1814 |
! |
1815 |
||
1816 |
asString |
|
1817 |
"return the receiver converted to a string" |
|
1818 |
||
1819 |
^ nameString |
|
1820 |
! |
|
1821 |
||
6256 | 1822 |
asURI |
1823 |
"return the receiver converted to a string" |
|
1824 |
||
1825 |
^ FileURI fromFilename:self. |
|
1826 |
! |
|
1827 |
||
5890 | 1828 |
components |
1829 |
"return the receivers filename components - that is the name of each directory |
|
1830 |
along the pathName (that DOES include the root directory)" |
|
1831 |
||
1832 |
^ self class components:self name |
|
1833 |
||
1834 |
" |
|
1835 |
'.' asFilename asAbsoluteFilename components |
|
1836 |
'Makefile' asFilename asAbsoluteFilename components |
|
1837 |
" |
|
1838 |
! |
|
1839 |
||
615 | 1840 |
makeLegalFilename |
1970 | 1841 |
"convert the receivers name to be a legal filename. |
1842 |
This removes/replaces invalid characters and/or compresses |
|
1843 |
the name as required by the OS. |
|
615 | 1844 |
The implementation may change in the future to be more |
1845 |
OS specific." |
|
1846 |
||
1847 |
" |
|
1848 |
actually, in Unix spaces are allowed - but it makes life |
|
1849 |
so hard; therefore, replace them by underscores ... |
|
1850 |
" |
|
3658 | 1851 |
(nameString includes:Character space) ifTrue:[ |
9453 | 1852 |
nameString := nameString copyReplaceAll:(Character space) with:$_. |
3658 | 1853 |
]. |
615 | 1854 |
" |
1855 |
need more - especially on SYS5.3 type systems, |
|
1856 |
we may want to contract the fileName to 14 characters. |
|
1857 |
" |
|
1858 |
^ self |
|
1859 |
||
1860 |
" |
|
1861 |
'hello world' asFilename makeLegalFilename |
|
1862 |
" |
|
1970 | 1863 |
|
3658 | 1864 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1865 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1866 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1867 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1868 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1869 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1870 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1871 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
1872 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 1873 |
! ! |
1874 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1875 |
!Filename methodsFor:'enumerating-contents'! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1876 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1877 |
allDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1878 |
"evaluate aBlock for all (recursive) directories contained in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1879 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1880 |
The enumerations order within a directory is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1881 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1882 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1883 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1884 |
may be changed in the near future, to raise an exception instead. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1885 |
So users of this method better test for existing directory before." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1886 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1887 |
self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | |
9453 | 1888 |
|eachFileOrDirectory| |
1889 |
||
1890 |
eachFileOrDirectory := self construct:eachFileOrDirectoryName. |
|
1891 |
eachFileOrDirectory isDirectory ifTrue:[ |
|
1892 |
aBlock value:eachFileOrDirectory |
|
1893 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1894 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1895 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1896 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1897 |
'.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1898 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1899 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1900 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1901 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1902 |
allParentDirectoriesDo:aBlock |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1903 |
"evaluate aBlock for all (recursive) directories along the parent directory path. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1904 |
The block is invoked with a filename-arguments." |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1905 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1906 |
|parent here| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1907 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1908 |
here := self. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1909 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1910 |
[here notNil and:[parent ~= here]] whileTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1911 |
aBlock value:parent. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1912 |
here := parent. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1913 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1914 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1915 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1916 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1917 |
'.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1918 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1919 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
1920 |
|
9362 | 1921 |
directories |
1922 |
"return a collection of directories contained in the directory represented by the receiver." |
|
1923 |
||
10557 | 1924 |
^ self directoryContentsAsFilenames |
1925 |
select:[:eachFileOrDirectory | eachFileOrDirectory isDirectory] |
|
9362 | 1926 |
|
1927 |
" |
|
1928 |
'.' asFilename directories. |
|
1929 |
" |
|
10557 | 1930 |
|
1931 |
"Modified: / 29-05-2007 / 12:02:56 / cg" |
|
9362 | 1932 |
! |
1933 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1934 |
directoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1935 |
"evaluate aBlock for directories contained in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1936 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1937 |
The enumerations order is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1938 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1939 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1940 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1941 |
may be changed in the near future, to raise an exception instead. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1942 |
So users of this method better test for existing directory before." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1943 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1944 |
self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
9453 | 1945 |
eachFileOrDirectory isDirectory ifTrue:[ |
1946 |
aBlock value:eachFileOrDirectory |
|
1947 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1948 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1949 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1950 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1951 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1952 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1953 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1954 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1955 |
directoryContentsAsFilenamesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1956 |
"evaluate aBlock for each file in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1957 |
The block is invoked with a filename-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1958 |
The enumerations order is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1959 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1960 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1961 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1962 |
may be changed in the near future, to raise an exception instead. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1963 |
So users of this method better test for existing directory before. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1964 |
Notice: this enumerates fileName objects; see also |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1965 |
#directoryContentsDo:, which enumerates strings." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1966 |
|
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
1967 |
self directoryContentsDo:[:entry | |
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
1968 |
aBlock value:(self construct:entry). |
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
1969 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1970 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1971 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1972 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1973 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1974 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1975 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1976 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1977 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
1978 |
|
7464 | 1979 |
directoryContentsDo:aBlock |
1980 |
"evaluate aBlock for each file in the directory represented by the receiver. |
|
1981 |
The block is invoked with a string as argument. |
|
1982 |
The enumerations order is undefined - i.e. usually NOT sorted by |
|
1983 |
filenames (but by creation time - on some systems). |
|
1984 |
This excludes entries for '.' or '..'. |
|
7473 | 1985 |
An exception is raised it the directory does not exist.. |
7464 | 1986 |
So users of this method better test for existing directory before. |
1987 |
Notice: this enumerates strings; see also |
|
1988 |
#directoryContentsAsFilenamesDo:, which enumerates fileName objects." |
|
1989 |
||
1990 |
|s fn| |
|
1991 |
||
7846 | 1992 |
FileStream openErrorSignal |
1993 |
handle:[:ex |] |
|
1994 |
do:[ |
|
1995 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
|
1996 |
]. |
|
1997 |
s isNil ifTrue:[^ self]. |
|
7464 | 1998 |
|
1999 |
[ |
|
2000 |
[s atEnd] whileFalse:[ |
|
2001 |
fn := s nextLine. |
|
2002 |
((fn ~= '.') and:[fn ~= '..']) ifTrue:[ |
|
2003 |
aBlock value:fn |
|
2004 |
] |
|
2005 |
] |
|
2006 |
] ensure:[ |
|
2007 |
s close |
|
2008 |
]. |
|
2009 |
||
2010 |
" |
|
2011 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
7473 | 2012 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
7464 | 2013 |
" |
2014 |
||
2015 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
2016 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
|
2017 |
! |
|
2018 |
||
9382 | 2019 |
files |
9383 | 2020 |
"return a collection of files contained in the directory represented by the receiver." |
9382 | 2021 |
|
10557 | 2022 |
^ self directoryContentsAsFilenames |
2023 |
select:[:eachFileOrDirectory | eachFileOrDirectory isDirectory not] |
|
9382 | 2024 |
|
2025 |
" |
|
2026 |
'.' asFilename files. |
|
2027 |
" |
|
10557 | 2028 |
|
2029 |
"Modified: / 29-05-2007 / 12:02:15 / cg" |
|
9382 | 2030 |
! |
2031 |
||
9806 | 2032 |
filesDo:aBlock |
2033 |
"evaluate aBlock for all files contained in the directory represented by the receiver." |
|
2034 |
||
10557 | 2035 |
^ self directoryContentsAsFilenames |
2036 |
do:[:eachFileOrDirectory | |
|
2037 |
eachFileOrDirectory isDirectory ifFalse:[ aBlock value: eachFileOrDirectory]]. |
|
9806 | 2038 |
|
2039 |
" |
|
2040 |
'.' asFilename filesDo:[:f | Transcript showCR:f]. |
|
2041 |
" |
|
2042 |
||
2043 |
"Created: / 29-08-2006 / 11:03:15 / cg" |
|
10557 | 2044 |
"Modified: / 29-05-2007 / 12:02:46 / cg" |
9806 | 2045 |
! |
2046 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2047 |
recursiveDirectoryContentsDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2048 |
"evaluate aBlock for all files and directories found under the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2049 |
The block is invoked with a string-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2050 |
The walk is bread-first. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2051 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2052 |
Subdirectory files are included with a relative pathname. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2053 |
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2054 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2055 |
self recursiveDirectoryContentsDo:aBlock directoryPrefix:'' |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2056 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2057 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2058 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2059 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2060 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2061 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2062 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2063 |
"evaluate aBlock for all files and directories found under the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2064 |
The block is invoked with a string-argument. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2065 |
The walk is breadth-first. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2066 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2067 |
Subdirectory files are included with a relative pathname. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2068 |
A proceedable exception is raised forn non-accessable directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2069 |
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2070 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2071 |
|fileNames dirNames p| |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2072 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2073 |
fileNames := OrderedCollection new. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2074 |
dirNames := OrderedCollection new. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2075 |
self directoryContentsDo:[:f | |t| |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2076 |
t := self construct:f. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2077 |
t isDirectory ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2078 |
t isSymbolicLink ifFalse:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2079 |
dirNames add:f |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2080 |
] |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2081 |
] ifFalse:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2082 |
fileNames add:f |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2083 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2084 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2085 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2086 |
aPrefix size > 0 ifTrue:[ |
8243 | 2087 |
p := aPrefix , self separator |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2088 |
] ifFalse:[ |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2089 |
p := '' |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2090 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2091 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2092 |
fileNames do:[:aFile | aBlock value:(p , aFile)]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2093 |
dirNames do:[:dN | |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2094 |
aBlock value:(p , dN). |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2095 |
(self construct:dN) |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2096 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN) |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2097 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2098 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2099 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2100 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2101 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2102 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2103 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2104 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2105 |
withAllDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2106 |
"evaluate aBlock for myself and all (recursive) directories contained in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2107 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2108 |
The enumerations order within a directory is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2109 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2110 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2111 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2112 |
may be changed in the near future, to raise an exception instead. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2113 |
So users of this method better test for existing directory before." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2114 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2115 |
self isDirectory ifTrue:[ |
9453 | 2116 |
aBlock value:self. |
2117 |
self allDirectoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2118 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2119 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2120 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2121 |
'.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2122 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2123 |
! ! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2124 |
|
542 | 2125 |
!Filename methodsFor:'error handling'! |
2126 |
||
615 | 2127 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2128 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2129 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2130 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2131 |
|
4820 | 2132 |
|errNo errString| |
2133 |
||
2134 |
errNo := OperatingSystem lastErrorNumber. |
|
2135 |
errString := OperatingSystem lastErrorString. |
|
2136 |
errString size == 0 ifTrue:[ |
|
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2137 |
errString := ''. |
4820 | 2138 |
] ifFalse:[ |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2139 |
errString := ' (' , errString , ')' |
4820 | 2140 |
]. |
2141 |
||
615 | 2142 |
^ OperatingSystem accessDeniedErrorSignal |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2143 |
raiseRequestWith:filename |
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2144 |
errorString:(' : ' , filename asString , errString) |
4820 | 2145 |
|
2146 |
"Modified: / 26.9.1999 / 16:11:44 / cg" |
|
615 | 2147 |
! |
2148 |
||
2149 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2150 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2151 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2152 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2153 |
|
615 | 2154 |
^ OperatingSystem accessDeniedErrorSignal |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2155 |
raiseRequestWith:filename |
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2156 |
errorString:(' - cannot create/write file: ' , filename asString) |
542 | 2157 |
! |
2158 |
||
2159 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2160 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2161 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2162 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2163 |
|
542 | 2164 |
^ OperatingSystem fileNotFoundErrorSignal |
9453 | 2165 |
raiseRequestWith:filename |
2166 |
errorString:('file not found: ' , filename asString) |
|
542 | 2167 |
! |
2168 |
||
2169 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2170 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2171 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2172 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2173 |
|
542 | 2174 |
^ OperatingSystem accessDeniedErrorSignal |
9453 | 2175 |
raiseRequestWith:filename |
2176 |
errorString:('cannot remove: ' , filename asString) |
|
615 | 2177 |
! |
2178 |
||
2179 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2180 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2181 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2182 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2183 |
|
615 | 2184 |
^ OperatingSystem errorSignal |
9453 | 2185 |
raiseRequestWith:filename |
2186 |
errorString:string |
|
615 | 2187 |
! ! |
2188 |
||
2189 |
!Filename methodsFor:'file access'! |
|
2190 |
||
3015 | 2191 |
appendStream |
2192 |
"return a stream for appending to the file represented by the receiver. |
|
2193 |
If the file does not already exist, it is created. |
|
2194 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
2195 |
||
2196 |
^ self appendingWriteStream |
|
2197 |
! |
|
2198 |
||
615 | 2199 |
appendingWriteStream |
2200 |
"return a stream for appending to the file represented by the receiver. |
|
5720 | 2201 |
If the file does not already exist, it is created; |
2202 |
if it does exist, writes are appended at the end." |
|
615 | 2203 |
|
2947 | 2204 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
5720 | 2205 |
|
2206 |
" |
|
2207 |
|s| |
|
2208 |
||
2209 |
s := '/tmp/foo' asFilename writeStream. |
|
2210 |
s nextPutAll:'1234567890'. |
|
2211 |
s close. |
|
2212 |
||
2213 |
s := '/tmp/foo' asFilename appendingWriteStream. |
|
2214 |
s nextPutAll:'abcdef'. |
|
2215 |
s close. |
|
2216 |
||
2217 |
'/tmp/foo' asFilename contents |
|
2218 |
" |
|
615 | 2219 |
! |
2220 |
||
2221 |
newReadWriteStream |
|
2222 |
"return a stream for read/write the file represented by the receiver. |
|
5720 | 2223 |
If the file does not already exist, it is created; |
2224 |
if it does exist, it is truncated." |
|
615 | 2225 |
|
2947 | 2226 |
^ FileStream newFileNamed:(self osNameForAccess) |
5720 | 2227 |
|
2228 |
" |
|
2229 |
|s| |
|
2230 |
||
2231 |
s := '/tmp/foo' asFilename writeStream. |
|
2232 |
s nextPutAll:'1234567890'. |
|
2233 |
s close. |
|
2234 |
||
2235 |
s := '/tmp/foo' asFilename newReadWriteStream. |
|
2236 |
s nextPutAll:'12345'. |
|
2237 |
s close. |
|
2238 |
||
2239 |
'/tmp/foo' asFilename contents |
|
2240 |
" |
|
615 | 2241 |
! |
2242 |
||
2243 |
readStream |
|
2244 |
"return a stream for reading from the file represented by the receiver. |
|
7828 | 2245 |
Raises an error if the file does not exist." |
615 | 2246 |
|
2947 | 2247 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 2248 |
|
2249 |
" |
|
2250 |
'/tmp/foo' asFilename readStream |
|
2251 |
" |
|
2252 |
! |
|
2253 |
||
2254 |
readWriteStream |
|
2255 |
"return a stream for read/write the file represented by the receiver. |
|
7828 | 2256 |
If the file does not already exist, it is created. |
2257 |
If the file does exist, it is NOT truncated, but rewritten at the beginning." |
|
615 | 2258 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2259 |
^ FileStream fileNamed:(self osNameForAccess) |
5720 | 2260 |
|
2261 |
" |
|
2262 |
|s| |
|
2263 |
||
2264 |
s := '/tmp/foo' asFilename writeStream. |
|
2265 |
s nextPutAll:'1234567890'. |
|
2266 |
s close. |
|
2267 |
||
7828 | 2268 |
s := '/tmp/foo' asFilename readWriteStream. |
5720 | 2269 |
s nextPutAll:'abcdef'. |
2270 |
s close. |
|
2271 |
||
2272 |
'/tmp/foo' asFilename contents |
|
7828 | 2273 |
'/tmp/foo' asFilename remove |
5720 | 2274 |
" |
615 | 2275 |
! |
2276 |
||
2277 |
writeStream |
|
2278 |
"return a stream for writing to the file represented by the receiver. |
|
5720 | 2279 |
If the file does not already exist, it is created; |
2280 |
if it does exist, it is truncated." |
|
615 | 2281 |
|
2947 | 2282 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 2283 |
|
2284 |
" |
|
2285 |
'/tmp/foo' asFilename writeStream |
|
2286 |
" |
|
5720 | 2287 |
|
2288 |
" |
|
2289 |
|s| |
|
2290 |
||
2291 |
s := '/tmp/foo' asFilename writeStream. |
|
2292 |
s nextPutAll:'1234567890'. |
|
2293 |
s close. |
|
2294 |
||
2295 |
s := '/tmp/foo' asFilename writeStream. |
|
2296 |
s nextPutAll:'12345'. |
|
2297 |
s close. |
|
2298 |
||
2299 |
'/tmp/foo' asFilename contents |
|
2300 |
" |
|
615 | 2301 |
! ! |
2302 |
||
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2303 |
!Filename methodsFor:'file access - migration'! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2304 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2305 |
appendingWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2306 |
"return a stream for appending to the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2307 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2308 |
if it does exist, writes are appended at the end. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2309 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2310 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2311 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2312 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2313 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2314 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2315 |
FileStream appendingOldFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2316 |
] on:FileStream openErrorSignal do:[:ex| nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2317 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2318 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2319 |
newReadWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2320 |
"return a stream for read/write the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2321 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2322 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2323 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2324 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2325 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2326 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2327 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2328 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2329 |
FileStream newFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2330 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2331 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2332 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2333 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2334 |
"return a stream for reading from the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2335 |
If the file does not already exist, nil is returned. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2336 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2337 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2338 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2339 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2340 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2341 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2342 |
FileStream readonlyFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2343 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2344 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2345 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2346 |
'/tmp/foo' asFilename readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2347 |
'/tmp/foo' asFilename readStream |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2348 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2349 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2350 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2351 |
readWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2352 |
"return a stream for read/write the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2353 |
If the file does not already exist, it is created. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2354 |
If the file does exist, it is NOT truncated, but rewritten at the beginning |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2355 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2356 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2357 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2358 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2359 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2360 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2361 |
FileStream fileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2362 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2363 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2364 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2365 |
writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2366 |
"return a stream for writing to the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2367 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2368 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2369 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2370 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2371 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2372 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2373 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2374 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2375 |
FileStream newFileForWritingNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2376 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2377 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2378 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2379 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2380 |
'/etc/foo' asFilename writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2381 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2382 |
! ! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2383 |
|
6223 | 2384 |
!Filename methodsFor:'file accessRights'! |
615 | 2385 |
|
2386 |
addAccessRights:aCollection |
|
2387 |
"add the access rights as specified in aCollection for the file represented |
|
2388 |
by the receiver. The argument must be a collection of symbols, |
|
2389 |
such as #readUser, #writeGroup etc." |
|
2390 |
||
2922 | 2391 |
|access osName| |
2392 |
||
2947 | 2393 |
osName := self osNameForFile. |
2922 | 2394 |
access := OperatingSystem accessModeOf:osName. |
615 | 2395 |
aCollection do:[:accessSymbol | |
9453 | 2396 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
615 | 2397 |
]. |
2922 | 2398 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
9453 | 2399 |
^ self accessDeniedError:self |
615 | 2400 |
] |
2401 |
||
2402 |
" |
|
2403 |
'foo' asFilename writeStream close. |
|
2404 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
2405 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
2406 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
2407 |
" |
|
2408 |
! |
|
2409 |
||
6223 | 2410 |
makeExecutable |
2411 |
"make the file executable - you must have permission to do so. |
|
2412 |
For directories, execution means: 'allow changing into it'" |
|
2413 |
||
2414 |
^ self addAccessRights:#(executeUser) |
|
2415 |
||
2416 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
2417 |
! |
|
2418 |
||
2419 |
makeExecutableForAll |
|
2420 |
"make the file executable for all - you must have permission to do so. |
|
2421 |
For directories, execution means: 'allow changing into it'" |
|
2422 |
||
2423 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
2424 |
||
2425 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
2426 |
! |
|
2427 |
||
2428 |
makeExecutableForGroup |
|
2429 |
"make the file executable for the group - you must have permission to do so. |
|
2430 |
For directories, execution means: 'allow changing into it'" |
|
2431 |
||
2432 |
^ self addAccessRights:#(executeGroup) |
|
2433 |
||
2434 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
2435 |
! |
|
2436 |
||
2437 |
makeReadable |
|
2438 |
"make the file readable for the owner - you must have permission to do so." |
|
2439 |
||
2440 |
^ self addAccessRights:#(readUser) |
|
2441 |
! |
|
2442 |
||
2443 |
makeReadableForAll |
|
2444 |
"make the file readable for all - you must have permission to do so." |
|
2445 |
||
2446 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
2447 |
! |
|
2448 |
||
2449 |
makeReadableForGroup |
|
2450 |
"make the file readable for the group - you must have permission to do so." |
|
2451 |
||
2452 |
^ self addAccessRights:#(readGroup) |
|
2453 |
! |
|
2454 |
||
2455 |
makeUnwritable |
|
2456 |
"make the file unwritable for all - you must have permission to do so." |
|
2457 |
||
2458 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
2459 |
! |
|
2460 |
||
2461 |
makeWritable |
|
2462 |
"make the file writableable for all - you must have permission to do so." |
|
2463 |
||
2464 |
^ self addAccessRights:#(writeUser) |
|
2465 |
! |
|
2466 |
||
2467 |
makeWritableForAll |
|
2468 |
"make the file writable for all - you must have permission to do so." |
|
2469 |
||
2470 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
2471 |
! |
|
2472 |
||
2473 |
makeWritableForGroup |
|
2474 |
"make the file writable for the group - you must have permission to do so." |
|
2475 |
||
2476 |
^ self addAccessRights:#(writeGroup) |
|
2477 |
! |
|
2478 |
||
2479 |
removeAccessRights:aCollection |
|
2480 |
"remove the access rights as specified in aCollection for the file represented |
|
2481 |
by the receiver. The argument must be a collection of symbols, |
|
2482 |
such as #readUser, #writeGroup etc. |
|
2483 |
Raises an exception if not successful." |
|
2484 |
||
2485 |
|access osName| |
|
2486 |
||
2487 |
osName := self osNameForFile. |
|
2488 |
access := OperatingSystem accessModeOf:osName. |
|
2489 |
aCollection do:[:accessSymbol | |
|
9453 | 2490 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
6223 | 2491 |
]. |
2492 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
|
9453 | 2493 |
^ self accessDeniedError:self |
6223 | 2494 |
]. |
2495 |
||
2496 |
" |
|
2497 |
'foo' asFilename writeStream close. |
|
2498 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
2499 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
2500 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
2501 |
" |
|
2502 |
||
2503 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2504 |
! |
|
2505 |
||
2506 |
symbolicAccessRights |
|
2507 |
"return the access rights of the file as a aCollection of access symbols. |
|
2508 |
The returned collection consists of symbols like: |
|
2509 |
#readUser, #writeGroup etc." |
|
2510 |
||
2511 |
|access osName| |
|
2512 |
||
2513 |
osName := self osNameForFile. |
|
2514 |
access := OperatingSystem accessModeOf:osName. |
|
2515 |
||
2516 |
^ |
|
2517 |
#( readUser writeUser executeUser |
|
2518 |
readGroup writeGroup executeGroup |
|
2519 |
readOthers writeOthers executeOthers |
|
2520 |
) select:[:eachSymbolicAccessSymbol | |
|
2521 |
access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol). |
|
2522 |
]. |
|
2523 |
||
2524 |
" |
|
2525 |
'Makefile' asFilename symbolicAccessRights |
|
2526 |
" |
|
2527 |
||
2528 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2529 |
! |
|
2530 |
||
2531 |
symbolicAccessRights:aCollectionOfSymbols |
|
2532 |
"set the access rights of the file given a aCollection of access symbols. |
|
2533 |
The collection must consist of symbols like: |
|
2534 |
#readUser, #writeGroup etc." |
|
2535 |
||
2536 |
|access osName| |
|
2537 |
||
2538 |
osName := self osNameForFile. |
|
2539 |
access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol | |
|
2540 |
bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol) |
|
2541 |
]. |
|
2542 |
||
2543 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
|
2544 |
^ self accessDeniedError:self |
|
2545 |
]. |
|
2546 |
||
2547 |
" |
|
2548 |
|rights| |
|
2549 |
||
2550 |
rights := 'Makefile' asFilename symbolicAccessRights. |
|
2551 |
'Makefile' asFilename symbolicAccessRights:(rights , #(executeOthers)). |
|
2552 |
" |
|
2553 |
||
2554 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2555 |
! ! |
|
2556 |
||
2557 |
!Filename methodsFor:'file operations'! |
|
2558 |
||
7329 | 2559 |
appendTo:newNameOrStream |
2560 |
"append the file - the argument must be convertable to a filename. |
|
2561 |
Raises an exception, if an error occurs." |
|
2562 |
||
2563 |
|inStream outStream outStreamToClose| |
|
2564 |
||
2565 |
inStream := self readStream. |
|
8769 | 2566 |
inStream isNil ifTrue:[ |
2567 |
^ self fileNotFoundError:self |
|
2568 |
]. |
|
2569 |
||
7329 | 2570 |
[ |
2571 |
newNameOrStream isStream ifTrue:[ |
|
2572 |
outStream := newNameOrStream. |
|
2573 |
] ifFalse:[ |
|
2574 |
outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream. |
|
2575 |
]. |
|
2576 |
||
8769 | 2577 |
inStream binary. |
2578 |
outStream binary. |
|
2579 |
||
7329 | 2580 |
[ |
2581 |
inStream copyToEndInto:outStream. |
|
2582 |
] on:OperatingSystem errorSignal do:[:ex| |
|
2583 |
^ self fileCreationError:newNameOrStream |
|
2584 |
] |
|
2585 |
] ensure:[ |
|
2586 |
inStream close. |
|
2587 |
outStreamToClose notNil ifTrue:[outStreamToClose close]. |
|
2588 |
]. |
|
2589 |
||
2590 |
" |
|
2591 |
'/etc/group' asFilename appendTo:'/tmp/Makefile.foo'. |
|
2592 |
'Makefile' asFilename appendTo:'/tmp/Makefile.foo' |
|
2593 |
'Makefile' asFilename copyTo:'/' |
|
2594 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
2595 |
" |
|
2596 |
||
2597 |
"Modified: / 23.12.1999 / 21:52:36 / cg" |
|
2598 |
! |
|
2599 |
||
2982 | 2600 |
basicMakeDirectory |
2601 |
"create a directory with the receivers name. |
|
2602 |
Return true if successful, false if not." |
|
2603 |
||
2604 |
^ OperatingSystem createDirectory:(self osNameForDirectory) |
|
2605 |
! |
|
2606 |
||
10020 | 2607 |
copyTo:newNameArg |
9235 | 2608 |
"Copy the files contents into another file. |
2609 |
The argument must be convertable to a filename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2610 |
Raises an exception, if an error occurs." |
615 | 2611 |
|
10020 | 2612 |
|newName inStream outStream| |
2613 |
||
2614 |
newName := newNameArg asFilename. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2615 |
|
8535 | 2616 |
"Contents is not copied if newName represent same file as me." |
10020 | 2617 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
8535 | 2618 |
|
615 | 2619 |
inStream := self readStream. |
8535 | 2620 |
inStream isNil ifTrue:[ |
2621 |
^ self fileNotFoundError:self |
|
2622 |
]. |
|
8769 | 2623 |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2624 |
[ |
10020 | 2625 |
outStream := newName writeStream. |
8535 | 2626 |
outStream isNil ifTrue:[ |
10020 | 2627 |
^ self fileCreationError:newName |
8535 | 2628 |
]. |
8769 | 2629 |
inStream binary. |
2630 |
outStream binary. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2631 |
|
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2632 |
[ |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2633 |
inStream copyToEndInto:outStream. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2634 |
] on:OperatingSystem errorSignal do:[:ex| |
10020 | 2635 |
^ self fileCreationError:newName |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2636 |
] |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2637 |
] ensure:[ |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2638 |
inStream close. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2639 |
outStream notNil ifTrue:[outStream close]. |
615 | 2640 |
]. |
2641 |
||
2642 |
" |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2643 |
'Makefile' asFilename copyTo:'/tmp/Makefile.foo' |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2644 |
'Makefile' asFilename copyTo:'/' |
615 | 2645 |
'smalltalk' asFilename copyTo:'/dev/null' |
2646 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2647 |
|
10020 | 2648 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
2649 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
615 | 2650 |
! |
2651 |
||
6983 | 2652 |
createAsEmptyFile |
2653 |
"create an empty file with the receivers name. |
|
2654 |
Raises an exception if not successful |
|
2655 |
(either already existing or creation not possible)" |
|
2656 |
||
2657 |
|writeStream| |
|
2658 |
||
2659 |
self exists ifTrue:[ |
|
2660 |
OperatingSystem accessDeniedErrorSignal |
|
2661 |
raiseRequestWith:self |
|
2662 |
errorString:(' - file exists: ' , self asString). |
|
2663 |
^ self |
|
2664 |
]. |
|
2665 |
||
2666 |
FileStream openErrorSignal handle:[:ex| |
|
2667 |
self fileCreationError:self. |
|
2668 |
^ self |
|
2669 |
] do:[ |
|
2670 |
writeStream := self newReadWriteStream. |
|
2671 |
]. |
|
2672 |
writeStream close. |
|
2673 |
! |
|
2674 |
||
615 | 2675 |
delete |
2676 |
"remove the file - same as remove, for ST-80 compatibility" |
|
2677 |
||
2678 |
self remove |
|
2679 |
! |
|
2680 |
||
2681 |
makeDirectory |
|
2682 |
"create a directory with the receivers name. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2683 |
Raises an exception if not successful" |
615 | 2684 |
|
2982 | 2685 |
(self basicMakeDirectory) ifFalse:[ |
9453 | 2686 |
"/ |
2687 |
"/ could have existed before ... |
|
2688 |
"/ |
|
2689 |
(self exists and:[self isDirectory]) ifFalse:[ |
|
2690 |
self fileCreationError:self. |
|
2691 |
^ false |
|
2692 |
] |
|
2982 | 2693 |
]. |
2694 |
^ true |
|
1970 | 2695 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2696 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 2697 |
! |
2698 |
||
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2699 |
moveFileTo:newName |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2700 |
"copy the file represented by the receiver, then delete it. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2701 |
This is different to renaming in case of cross device moves. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2702 |
Raise an exception if not successful. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2703 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2704 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2705 |
[self renameTo:newName] |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2706 |
on:(OperatingSystem errorSignal) |
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2707 |
do:[:ex | |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2708 |
ex signal == OperatingSystem fileNotFoundErrorSignal ifTrue:[ |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2709 |
ex reject |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2710 |
]. |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2711 |
self copyTo:newName. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2712 |
self remove |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2713 |
]. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2714 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2715 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2716 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2717 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2718 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2719 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2720 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2721 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2722 |
f renameTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2723 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2724 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2725 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2726 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2727 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2728 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2729 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2730 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2731 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2732 |
f moveTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2733 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2734 |
! |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2735 |
|
615 | 2736 |
moveTo:newName |
2737 |
"copy the file represented by the receiver, then delete it. |
|
2738 |
This is different to renaming in case of cross device moves. |
|
5594
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
2739 |
Raise an exception if not successful. |
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
2740 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
615 | 2741 |
|
6771 | 2742 |
[self renameTo:newName] |
2743 |
on:(OperatingSystem errorSignal) |
|
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2744 |
do:[:ex | |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2745 |
ex signal == OperatingSystem fileNotFoundErrorSignal ifTrue:[ |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2746 |
ex reject |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2747 |
]. |
10836
861c0030d55b
dont try to copy-delete if the rename failed due to accessdenied
sr
parents:
10813
diff
changeset
|
2748 |
ex signal == OperatingSystem accessDeniedErrorSignal ifTrue:[ |
861c0030d55b
dont try to copy-delete if the rename failed due to accessdenied
sr
parents:
10813
diff
changeset
|
2749 |
ex reject |
861c0030d55b
dont try to copy-delete if the rename failed due to accessdenied
sr
parents:
10813
diff
changeset
|
2750 |
]. |
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
2751 |
|
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
2752 |
self isDirectory ifTrue:[ |
6997 | 2753 |
self recursiveMoveDirectoryTo:newName. |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
2754 |
] ifFalse:[ |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2755 |
self moveFileTo:newName. |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
2756 |
]. |
6771 | 2757 |
]. |
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2758 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2759 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2760 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2761 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2762 |
f := '/tmp/foo' asFilename. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2763 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2764 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2765 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2766 |
f renameTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2767 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2768 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2769 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2770 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2771 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2772 |
f := '/tmp/foo' asFilename. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2773 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2774 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2775 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2776 |
f moveTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
2777 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2778 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2779 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2780 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2781 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2782 |
Otherwise, copy the directory and recursively |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2783 |
and recursively all of its subfiles/subdirectories. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2784 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2785 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2786 |
|ok d| |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2787 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2788 |
self isDirectory ifFalse:[ |
9453 | 2789 |
d := destination asFilename. |
2790 |
(d exists and:[d isDirectory]) ifTrue:[ |
|
2791 |
d := d construct:self baseName. |
|
2792 |
]. |
|
2793 |
^ self copyTo:d |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2794 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2795 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2796 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2797 |
"/ however, if the command fails (or the OS does not support it), |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2798 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2799 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2800 |
ok := OperatingSystem |
9453 | 2801 |
recursiveCopyDirectory:(self osNameForDirectory) |
2802 |
to:(destination asFilename osNameForDirectory). |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2803 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2804 |
ok ifFalse:[ |
9453 | 2805 |
self recursiveCopyWithoutOSCommandTo:destination |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2806 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2807 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2808 |
"Created: / 5.5.1999 / 13:35:01 / cg" |
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2809 |
"Modified: / 31.5.1999 / 13:11:34 / cg" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2810 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2811 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2812 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2813 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2814 |
Otherwise, copy the directory and all of its subfiles/subdirectories. |
11192
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2815 |
This one walks down the directory hierarchy, not using any OS command to do the copy. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2816 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2817 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2818 |
|destinationFilename d| |
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2819 |
|
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
2820 |
d := destination asFilename. |
4246 | 2821 |
"/ (d exists and:[d isDirectory]) ifTrue:[ |
2822 |
"/ d := d construct:self baseName. |
|
2823 |
"/ ]. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2824 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2825 |
self isDirectory ifTrue:[ |
11192
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2826 |
d asFilename exists ifFalse:[ |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2827 |
destinationFilename := d asFilename. |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2828 |
] ifTrue:[ |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2829 |
destinationFilename := d asFilename construct:self baseName. |
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
2830 |
]. |
9453 | 2831 |
destinationFilename makeDirectory. |
2832 |
self directoryContents do:[:aFilenameString | |
|
2833 |
|src dst| |
|
2834 |
||
2835 |
src := self construct:aFilenameString. |
|
2836 |
src isDirectory ifTrue:[ |
|
2837 |
src recursiveCopyWithoutOSCommandTo:destinationFilename |
|
2838 |
] ifFalse:[ |
|
2839 |
src copyTo:(destinationFilename construct:aFilenameString) |
|
2840 |
]. |
|
2841 |
] |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2842 |
] ifFalse:[ |
9453 | 2843 |
self copyTo:d |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2844 |
] |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2845 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2846 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2847 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2848 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2849 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2850 |
|
4246 | 2851 |
"Modified: / 31.5.1999 / 18:12:31 / cg" |
615 | 2852 |
! |
2853 |
||
659 | 2854 |
recursiveMakeDirectory |
2855 |
"create a directory with the receivers name and all required intermediate |
|
2856 |
directories. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2857 |
Raises an exception if not successful." |
659 | 2858 |
|
2922 | 2859 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
9453 | 2860 |
^ self fileCreationError:self |
659 | 2861 |
] |
2862 |
||
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2863 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2864 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
659 | 2865 |
! |
2866 |
||
6997 | 2867 |
recursiveMoveDirectoryTo:newName |
2868 |
"recursively copy the directory represented by the receiver, then delete it. |
|
2869 |
This is different to renaming in case of cross device moves. |
|
2870 |
Raise an exception if not successful. |
|
2871 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
|
2872 |
||
2873 |
[self renameTo:newName] |
|
2874 |
on:(OperatingSystem errorSignal) |
|
2875 |
do:[ |
|
2876 |
self recursiveCopyTo:newName. |
|
2877 |
self recursiveRemove |
|
2878 |
]. |
|
2879 |
! |
|
2880 |
||
615 | 2881 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2882 |
"if I represent a regular file, remove it. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2883 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2884 |
Raise an exception if not successful." |
615 | 2885 |
|
2886 |
|ok| |
|
2887 |
||
3302 | 2888 |
"/ typically, an 'rm -rf' is faster and removes better; |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2889 |
"/ however, if the command fails (or the OS does not support it), |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2890 |
"/ fallBack doing a manual directory walk. |
3302 | 2891 |
|
2892 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
2893 |
ok ifFalse:[ |
|
9453 | 2894 |
self recursiveRemoveWithoutOSCommand |
3302 | 2895 |
]. |
2896 |
||
2897 |
" |
|
2898 |
'foo' asFilename makeDirectory. |
|
2899 |
'foo/bar' asFilename writeStream close. |
|
2900 |
('foo' asFilename remove) ifFalse:[ |
|
9453 | 2901 |
Transcript showCR:'could not remove foo' |
3302 | 2902 |
] |
2903 |
" |
|
2904 |
" |
|
2905 |
'foo' asFilename makeDirectory. |
|
2906 |
'foo/bar' asFilename writeStream close. |
|
2907 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
9453 | 2908 |
Transcript showCR:'could not remove foo' |
3302 | 2909 |
] |
2910 |
" |
|
2911 |
||
2912 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2913 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 2914 |
! |
2915 |
||
2916 |
recursiveRemoveWithoutOSCommand |
|
2917 |
"if I represent a regular file, remove it. |
|
2918 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
2919 |
Raise an error if not successful. |
|
2920 |
This one walks down the directory hierarchy, not using any OS |
|
2921 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2922 |
|
4939 | 2923 |
|files| |
2924 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2925 |
self isDirectory ifTrue:[ |
9453 | 2926 |
(files := self directoryContents) size > 0 ifTrue:[ |
2927 |
files do:[:aFilenameString | |
|
2928 |
|f| |
|
2929 |
||
2930 |
f := self construct:aFilenameString. |
|
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2931 |
Error handle:[:ex | |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2932 |
f isDirectory ifFalse:[ ex reject ]. |
9453 | 2933 |
f recursiveRemoveWithoutOSCommand |
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2934 |
] do:[ |
9453 | 2935 |
f remove |
2936 |
]. |
|
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2937 |
|
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2938 |
"/ f isDirectory ifTrue:[ |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2939 |
"/ f recursiveRemoveWithoutOSCommand |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2940 |
"/ ] ifFalse:[ |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2941 |
"/ f remove |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
2942 |
"/ ]. |
9453 | 2943 |
]. |
2944 |
] |
|
615 | 2945 |
]. |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
2946 |
self remove |
615 | 2947 |
|
2948 |
" |
|
2949 |
'foo' asFilename makeDirectory. |
|
2950 |
'foo/bar' asFilename writeStream close. |
|
4940 | 2951 |
'foo' asFilename remove |
615 | 2952 |
" |
2953 |
" |
|
2954 |
'foo' asFilename makeDirectory. |
|
2955 |
'foo/bar' asFilename writeStream close. |
|
4940 | 2956 |
'foo' asFilename recursiveRemove |
615 | 2957 |
" |
2958 |
||
3302 | 2959 |
"Created: / 25.2.1998 / 19:50:40 / cg" |
2960 |
"Modified: / 25.2.1998 / 19:52:08 / cg" |
|
615 | 2961 |
! |
2962 |
||
2963 |
remove |
|
845 | 2964 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2965 |
Raises an exception if not successful. |
845 | 2966 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 2967 |
|
8741 | 2968 |
|linkInfo osName ok| |
2969 |
||
2970 |
osName := self osNameForFile. |
|
2971 |
linkInfo := self linkInfo. |
|
2972 |
(linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[ |
|
2973 |
ok := OperatingSystem removeDirectory:osName |
|
615 | 2974 |
] ifFalse:[ |
8741 | 2975 |
ok := OperatingSystem removeFile:osName |
615 | 2976 |
]. |
2977 |
ok ifFalse:[ |
|
6392
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
2978 |
self exists ifTrue:[ |
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
2979 |
self removeError:self |
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
2980 |
] |
615 | 2981 |
]. |
2982 |
||
2983 |
" |
|
2984 |
(FileStream newFileNamed:'foo') close. |
|
2985 |
'foo' asFilename remove |
|
2986 |
" |
|
2987 |
||
2988 |
" |
|
2989 |
'foo' asFilename makeDirectory. |
|
2990 |
'foo/bar' asFilename writeStream close. |
|
8738 | 2991 |
'foo' asFilename remove. 'expect an exception' |
2992 |
'foo' asFilename recursiveRemove. |
|
615 | 2993 |
" |
2994 |
||
3113
43e75ed892cf
Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents:
3077
diff
changeset
|
2995 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2996 |
"Modified: / 5.5.1999 / 13:41:12 / cg" |
615 | 2997 |
! |
2998 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
2999 |
removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3000 |
"remove the directory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3001 |
Raises an exception if not successful (or if its not a directory). |
5596 | 3002 |
Use #remove if it is not known if the receiver is a directory or file. |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3003 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3004 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3005 |
|ok| |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3006 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3007 |
ok := OperatingSystem removeDirectory:(self osNameForFile). |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3008 |
ok ifFalse:[ |
9453 | 3009 |
self exists ifFalse:[ ^ self]. |
3010 |
self removeError:self |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3011 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3012 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3013 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3014 |
(FileStream newFileNamed:'foo') close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3015 |
'foo' asFilename removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3016 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3017 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3018 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3019 |
'foo' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3020 |
'foo' asFilename removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3021 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3022 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3023 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3024 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3025 |
'foo/bar' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3026 |
('foo' asFilename remove) ifFalse:[ |
9453 | 3027 |
Transcript showCR:'could not remove foo' |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3028 |
] |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3029 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3030 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3031 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3032 |
"Modified: / 5.5.1999 / 13:41:12 / cg" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3033 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3034 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3035 |
removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3036 |
"remove the file. |
5596 | 3037 |
Raises an exception if not successful (or if its not a file). |
3038 |
Use #remove if it is not known if the receiver is a directory or file. |
|
3039 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3040 |
|
8738 | 3041 |
(OperatingSystem removeFile:self osNameForFile) ifFalse:[ |
3042 |
self exists ifTrue:[ |
|
3043 |
self removeError:self |
|
3044 |
]. |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3045 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3046 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3047 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3048 |
(FileStream newFileNamed:'foo') close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3049 |
'foo' asFilename removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3050 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3051 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3052 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3053 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3054 |
'foo' asFilename removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3055 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3056 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3057 |
|
5086 | 3058 |
renameOrCopyTo:newName |
3059 |
"rename or copy the file - the argument must be convertable to a String. |
|
3060 |
Raises an exception if not successful. |
|
3061 |
This does basically the same as #renameTo:, with one exception: |
|
3062 |
if, under unix, the new fileName is on another device, a rename operation |
|
3063 |
fails, and #renameTo: raises an exception; |
|
3064 |
in contrast, this method falls back to copying the file." |
|
3065 |
||
3066 |
|newFilename| |
|
3067 |
||
3068 |
newFilename := newName asFilename. |
|
3069 |
||
3070 |
(OperatingSystem |
|
9453 | 3071 |
renameFile:(self osNameForFile) |
3072 |
to:(newFilename osNameForFile) |
|
5086 | 3073 |
) ifFalse:[ |
9453 | 3074 |
self exists ifFalse:[ |
3075 |
^ self fileNotFoundError:self |
|
3076 |
]. |
|
3077 |
||
3078 |
OperatingSystem isUNIXlike ifTrue:[ |
|
3079 |
OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[ |
|
3080 |
"/ try to copy - and remove the original |
|
3081 |
"/ this helps with cross-device renames. |
|
3082 |
||
3083 |
self copyTo:newName. |
|
3084 |
^ self |
|
3085 |
]. |
|
3086 |
]. |
|
3087 |
^ self accessDeniedError:newName asFilename. |
|
5086 | 3088 |
]. |
3089 |
||
3090 |
" |
|
3091 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
3092 |
" |
|
3093 |
||
3094 |
"Modified: / 5.5.1999 / 13:41:27 / cg" |
|
3095 |
! |
|
3096 |
||
615 | 3097 |
renameTo:newName |
671 | 3098 |
"rename the file - the argument must be convertable to a String. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3099 |
Raises an exception if not successful." |
615 | 3100 |
|
12318 | 3101 |
|errno| |
3102 |
||
2922 | 3103 |
(OperatingSystem |
9453 | 3104 |
renameFile:(self osNameForFile) |
3105 |
to:(newName asFilename osNameForFile) |
|
2922 | 3106 |
) ifFalse:[ |
12318 | 3107 |
errno := OperatingSystem lastErrorNumber. |
3108 |
||
9453 | 3109 |
self exists ifFalse:[ |
3110 |
^ self fileNotFoundError:self |
|
3111 |
]. |
|
3112 |
^ self accessDeniedError:newName asFilename. |
|
615 | 3113 |
]. |
3114 |
||
3115 |
" |
|
3116 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
3117 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3118 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3119 |
"Modified: / 5.5.1999 / 13:41:27 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3120 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3121 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3122 |
truncateTo:newSize |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3123 |
"change the files size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3124 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3125 |
(raises an exception, if not)" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3126 |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3127 |
(OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3128 |
^ 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
|
3129 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3130 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3131 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3132 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3133 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3134 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3135 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3136 |
s close. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3137 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3138 |
'test' asFilename truncateTo:100. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3139 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3140 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3141 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3142 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 3143 |
! ! |
3144 |
||
3145 |
!Filename methodsFor:'file queries'! |
|
3146 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3147 |
accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3148 |
"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
|
3149 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3150 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3151 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3152 |
(i := self info) isNil ifTrue:[^ nil]. |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3153 |
^ i accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3154 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3155 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3156 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3157 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3158 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3159 |
"Created: / 9.7.1996 / 10:19:15 / cg" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3160 |
"Modified: / 26.9.1997 / 13:05:51 / stefan" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3161 |
"Modified: / 17.8.1998 / 10:23:44 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3162 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3163 |
|
6977 | 3164 |
creationTime |
3165 |
"return a timeStamp containing the files creation time. |
|
3166 |
NOTICE: only windoof distinguishes creation from modification; |
|
6978 | 3167 |
under unix, nil is returned (callers should fall back and use mod-time then" |
6977 | 3168 |
|
3169 |
|i| |
|
3170 |
||
3171 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
|
6978 | 3172 |
^ i creationTime |
3173 |
||
3174 |
" |
|
3175 |
Filename currentDirectory creationTime |
|
6977 | 3176 |
" |
3177 |
||
3178 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
|
3179 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
|
3180 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
|
3181 |
! |
|
3182 |
||
615 | 3183 |
dates |
3184 |
"return the files modification and access times as an object (currently a dictionary) |
|
3185 |
that responds to the at: message with arguments |
|
3186 |
#modified, #accessed or #statusChanged." |
|
3187 |
||
2922 | 3188 |
|info dates osName| |
3189 |
||
2947 | 3190 |
osName := self osNameForAccess. |
2922 | 3191 |
info := OperatingSystem infoOf:osName. |
615 | 3192 |
info isNil ifTrue:[ |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3193 |
"maybe this is a symbolic link with a broken link target. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3194 |
Answer the dates of the link itself" |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3195 |
info := OperatingSystem linkInfoOf:osName. |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3196 |
info isNil ifTrue:[ |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3197 |
^ nil |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3198 |
] |
615 | 3199 |
]. |
3200 |
dates := IdentityDictionary new. |
|
6978 | 3201 |
dates at:#created put:(info creationTime). |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3202 |
dates at:#modified put:(info modificationTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3203 |
dates at:#accessed put:(info accessTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3204 |
dates at:#statusChanged put:(info statusChangeTime). |
615 | 3205 |
^ dates |
3206 |
||
3207 |
" |
|
6978 | 3208 |
Filename currentDirectory dates |
615 | 3209 |
'../regression' asFilename dates |
3210 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3211 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3212 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 3213 |
! |
3214 |
||
3215 |
fileSize |
|
3216 |
"return the size of the file in bytes" |
|
3217 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3218 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3219 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3220 |
(i := self info) isNil ifTrue:[^ nil]. |
6794
498d85323172
use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents:
6793
diff
changeset
|
3221 |
^ i fileSize |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3222 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3223 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 3224 |
! |
3225 |
||
3226 |
fileType |
|
3227 |
"this returns a string describing the type of contents of |
|
3228 |
the file. This is done using the unix 'file' command, |
|
3229 |
(which usually is configurable by /etc/magic). |
|
3665 | 3230 |
On non-unix systems, this may simply return 'file', |
2922 | 3231 |
not knowning about the contents. |
3232 |
Warning: |
|
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3233 |
Since the returned string differs among systems (and language settings), |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3234 |
it is only useful for user-information; |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3235 |
NOT as a tag to be used by a program." |
3665 | 3236 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3237 |
|buffer s n suffix idx baseNm info| |
3665 | 3238 |
|
3239 |
"/ since we cannot depend on a 'file' command being available, |
|
3240 |
"/ do the most obvious ones here. |
|
3241 |
"/ (also useful since the 'file' command takes some time, and the code |
|
3242 |
"/ below is faster for common things like directories) |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3243 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3244 |
info := self linkInfo. |
9060 | 3245 |
info isNil ifTrue:[ |
3246 |
^ 'removed' "/ could happen, when coming from a snapshot image |
|
3247 |
]. |
|
3248 |
||
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3249 |
info isSymbolicLink ifTrue:[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3250 |
^ 'symbolic link to ' , info path |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3251 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3252 |
info isDirectory ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3253 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3254 |
self isExecutable ifFalse:[^ 'directory, locked']. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3255 |
^ 'directory' |
2573 | 3256 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3257 |
info isCharacterSpecial ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3258 |
^ 'character device special file' |
3665 | 3259 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3260 |
info isBlockSpecial ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3261 |
^ 'block device special file' |
3665 | 3262 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3263 |
info isSocket ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3264 |
^ 'socket' |
3665 | 3265 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3266 |
info isFifo ifTrue:[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3267 |
^ 'fifo' |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3268 |
]. |
3665 | 3269 |
|
1602 | 3270 |
self isReadable ifFalse:[^ 'unreadable']. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3271 |
info fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 3272 |
|
2922 | 3273 |
suffix := self suffix asLowercase. |
3274 |
baseNm := self withoutSuffix baseName asLowercase. |
|
3275 |
||
6826 | 3276 |
((#('st' 'rc' 'chg' 'htm' 'html' 'ps' 'cls' 'pac') includes:suffix) |
2922 | 3277 |
or:[#('makefile') includes:baseNm]) ifTrue:[ |
3278 |
||
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
3279 |
buffer := String new:2048. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
3280 |
s := self readStreamOrNil. |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3281 |
s notNil ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3282 |
n := s nextBytes:buffer size into:buffer. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3283 |
s close. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3284 |
buffer := buffer asLowercase. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3285 |
(#('st' 'cls') includes:suffix) ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3286 |
#( |
6826 | 3287 |
('from squeak' 'smalltalk source (Squeak)') |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3288 |
('from dolphin' 'smalltalk source (Dolphin)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3289 |
('from visualworks' 'smalltalk source (VisualWorks)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3290 |
('categoriesforclass' 'smalltalk source (Dolphin)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3291 |
('methodsfor!!' 'smalltalk source (Dolphin, ST/V or V''age)') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3292 |
('subclass:' 'smalltalk source') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3293 |
('methodsfor:' 'smalltalk source') |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3294 |
) pairsDo:[:pattern :what | |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3295 |
(buffer findString:pattern) ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3296 |
^ what |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3297 |
] |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3298 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3299 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3300 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3301 |
(buffer findString:'methodsfor:') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3302 |
^ 'smalltalk changes / method source' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3303 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3304 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3305 |
(suffix = 'rc') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3306 |
(buffer findString:'st/x startup') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3307 |
^ 'smalltalk startup script' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3308 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3309 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3310 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3311 |
(suffix = 'htm' or:[suffix = 'html']) ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3312 |
(idx := buffer findString:'<h') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3313 |
((buffer continuesWith:'<head' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3314 |
or:[(buffer continuesWith:'<html' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3315 |
or:[(buffer continuesWith:'<h1' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3316 |
or:[(buffer continuesWith:'<h2' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3317 |
or:[(buffer continuesWith:'<h3' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3318 |
or:[(buffer continuesWith:'<h4' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3319 |
or:[(buffer continuesWith:'<h5' startingAt:idx) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3320 |
or:[(buffer continuesWith:'<h6' startingAt:idx)]]]]]]]) |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3321 |
ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3322 |
^ 'HTML document text' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3323 |
] |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3324 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3325 |
]. |
1614
4e1a64b19247
inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents:
1612
diff
changeset
|
3326 |
|
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3327 |
(suffix = 'ps') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3328 |
(buffer findString:'%!!ps-adobe') ~~ 0 ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3329 |
^ 'PostScript document' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3330 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3331 |
]. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3332 |
|
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3333 |
(baseNm = 'makefile') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3334 |
(buffer startsWith:'#') ifTrue:[ |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3335 |
^ 'make rules' |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3336 |
] |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3337 |
] |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3338 |
] |
1602 | 3339 |
]. |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3340 |
|
2906 | 3341 |
^ 'file' |
615 | 3342 |
|
3343 |
" |
|
3344 |
'Makefile' asFilename fileType |
|
3345 |
'.' asFilename fileType |
|
3665 | 3346 |
'/dev/null' asFilename fileType |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3347 |
'/usr/tmp' asFilename fileType |
3665 | 3348 |
'/tmp/.X11-unix/X0' asFilename fileType |
615 | 3349 |
'smalltalk.rc' asFilename fileType |
3350 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3351 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3352 |
|
3665 | 3353 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 3354 |
! |
3355 |
||
2836 | 3356 |
id |
3357 |
"return the files/directories file-id (inode number)" |
|
3358 |
||
2947 | 3359 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 3360 |
|
3361 |
" |
|
3362 |
Filename currentDirectory id |
|
3363 |
" |
|
3364 |
||
3365 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
3366 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
3367 |
! |
|
3368 |
||
615 | 3369 |
info |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3370 |
"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
|
3371 |
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
|
3372 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3373 |
|
9453 | 3374 |
type - a symbol giving the files fileType |
3375 |
mode - numeric access mode |
|
3376 |
uid - owners user id |
|
3377 |
gid - owners group id |
|
3378 |
size - files size |
|
3379 |
id - files number (i.e. inode number) |
|
3380 |
accessed - last access time (as osTime-stamp) |
|
3381 |
modified - last modification time (as osTime-stamp) |
|
3382 |
statusChanged - last staus change (as osTime-stamp) |
|
615 | 3383 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3384 |
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
|
3385 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3386 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
9453 | 3387 |
modified |
3388 |
size |
|
3389 |
type |
|
615 | 3390 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3391 |
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
|
3392 |
to either handle nil values, |
615 | 3393 |
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
|
3394 |
(i.e. instead of: |
9453 | 3395 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3396 |
use |
9453 | 3397 |
someFilename isDirectory |
615 | 3398 |
" |
3399 |
||
2947 | 3400 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 3401 |
|
3402 |
" |
|
3403 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3404 |
'/dev/null' asFilename info |
615 | 3405 |
'Make.proto' asFilename info |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3406 |
'source/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3407 |
'source/Point.st' asFilename linkInfo |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3408 |
'../../libbasic/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3409 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3410 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3411 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3412 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3413 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3414 |
'c:\' asFilename info |
615 | 3415 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3416 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3417 |
"Modified: / 17.8.1998 / 10:24:10 / cg" |
615 | 3418 |
! |
3419 |
||
3420 |
linkInfo |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3421 |
"return the files info. If it is a symbolic link return the info of the link itself |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3422 |
instead of the link's target. |
615 | 3423 |
The information is the same as returned by #info, except that if the |
3424 |
receiver represents a symbolic link, the links information |
|
3425 |
is returned |
|
3426 |
(while in this case, #info returns the info of the target file, |
|
3427 |
which is accessed via the symbolic link). |
|
3428 |
||
3429 |
In addition to the normal entries, Unix returns an additional entry: |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3430 |
path -> the target files pathname |
615 | 3431 |
|
3432 |
See the comment in #info for more details." |
|
3433 |
||
2947 | 3434 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 3435 |
|
3436 |
" |
|
3437 |
Filename currentDirectory linkInfo |
|
3438 |
'/dev/null' asFilename linkInfo |
|
3439 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3440 |
'Make.proto' asFilename linkInfo path |
615 | 3441 |
'source/Point.st' asFilename linkInfo |
3442 |
'../../libbasic/Point.st' asFilename linkInfo |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3443 |
'/usr/tmp' asFilename linkInfo |
615 | 3444 |
" |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3445 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3446 |
"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
|
3447 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3448 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3449 |
modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3450 |
"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
|
3451 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3452 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3453 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3454 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3455 |
^ i modificationTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3456 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3457 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3458 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3459 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3460 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3461 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3462 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3463 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 3464 |
! |
3465 |
||
3466 |
type |
|
3467 |
"return the symbolic type of the file" |
|
3468 |
||
2947 | 3469 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 3470 |
|
3471 |
" |
|
3472 |
Filename currentDirectory type |
|
3473 |
" |
|
3474 |
||
3475 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
3476 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 3477 |
! ! |
3478 |
||
3479 |
!Filename methodsFor:'file utilities'! |
|
3480 |
||
3481 |
edit |
|
3482 |
"start an editView on the file represented by the receiver" |
|
3483 |
||
3484 |
EditTextView openOn:self asString |
|
3485 |
||
3486 |
" |
|
3487 |
'smalltalk.rc' asFilename edit |
|
3488 |
" |
|
3489 |
! |
|
3490 |
||
3491 |
fileIn |
|
3492 |
"load smalltalk code from the file" |
|
3493 |
||
5200 | 3494 |
|s rslt| |
3495 |
||
3496 |
s := self readStream. |
|
3497 |
[ |
|
6422
d91c6082c200
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6402
diff
changeset
|
3498 |
rslt := s fileIn. |
d91c6082c200
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6402
diff
changeset
|
3499 |
] ensure:[ |
d91c6082c200
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
6402
diff
changeset
|
3500 |
s close. |
5200 | 3501 |
]. |
3502 |
^ rslt. |
|
542 | 3503 |
! ! |
3504 |
||
2 | 3505 |
!Filename methodsFor:'instance creation'! |
3506 |
||
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3507 |
/ subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3508 |
"Same as construct: Taking the receiver as a directory name, construct a new |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3509 |
filename for an entry within this directory |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3510 |
(i.e. for a file or a subdirectory in that directory). |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3511 |
The argument may not specify an absolute path name. |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3512 |
Please do not use this to create filenames with suffixes, |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3513 |
since some systems require special naming conventions. |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3514 |
See also: #withSuffix: (which is different, but often needed). |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3515 |
Thanks to Jan Vrany for this idea." |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3516 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3517 |
^ self construct:subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3518 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3519 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3520 |
'/tmp' asFilename / 'foo' |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3521 |
'/' asFilename / 'foo' / 'bar' / 'baz' |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3522 |
'/foo/bar' asFilename / ('baz' asFilename) |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3523 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3524 |
Bad example; works on UNIX, but may not on others: |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3525 |
'foo/bar.baz' / '.suff' |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3526 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3527 |
! |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3528 |
|
615 | 3529 |
construct:subname |
3530 |
"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
|
3531 |
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
|
3532 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 3533 |
The argument may not specify an absolute path name. |
3534 |
Please do not use this to create filenames with suffixes, |
|
3535 |
since some systems require special naming conventions. |
|
3536 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 3537 |
|
11784 | 3538 |
|constructedName| |
3539 |
||
3540 |
constructedName := self constructString:subname. |
|
3541 |
^ self class named:constructedName. |
|
615 | 3542 |
|
3543 |
" |
|
3544 |
'/tmp' asFilename construct:'foo' |
|
3545 |
'/' asFilename construct:'foo' |
|
3546 |
'/usr/tmp' asFilename construct:'foo' |
|
3547 |
'/foo/bar' asFilename construct:'baz' |
|
6670 | 3548 |
'/foo/bar' asFilename construct:'baz' asFilename |
2922 | 3549 |
|
3550 |
Bad example; works on UNIX, but may not on others: |
|
11784 | 3551 |
'foo/bar.baz' asFilename construct:'.suff' |
615 | 3552 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3553 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3554 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 3555 |
! |
3556 |
||
2922 | 3557 |
constructDirectory:subname |
3558 |
"same as #construct: on most systems. |
|
3559 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
3560 |
||
3561 |
^ self class named:(self constructDirectoryString:subname) |
|
3562 |
! |
|
3563 |
||
3564 |
constructDirectoryString:subName |
|
3565 |
"same as #constructString: on most systems. |
|
3566 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
3567 |
||
3568 |
^ self constructString:subName |
|
3569 |
! |
|
3570 |
||
3571 |
constructString:subName |
|
2911 | 3572 |
"taking the receiver as a directory name, construct a new |
3573 |
filename-string for an entry within this directory |
|
2922 | 3574 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 3575 |
The argument may not specify an absolute path name. |
3576 |
The code below works for UNIX & MSDOS; |
|
3577 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3578 |
||
3579 |
|sepString sub| |
|
3580 |
||
3581 |
sub := subName asString. |
|
8243 | 3582 |
sepString := self class separatorString. |
3583 |
nameString size == 0 ifTrue:[ |
|
3584 |
^ sub |
|
2911 | 3585 |
]. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3586 |
(nameString endsWith:sepString) ifTrue:[ |
6247 | 3587 |
^ nameString , sub |
3588 |
]. |
|
2960 | 3589 |
^ nameString , sepString , sub |
2911 | 3590 |
|
3591 |
" |
|
3592 |
'/tmp' asFilename constructString:'foo' |
|
3593 |
'/' asFilename constructString:'foo' |
|
3594 |
'/usr/tmp' asFilename constructString:'foo' |
|
3595 |
'/foo/bar' asFilename constructString:'baz' |
|
6247 | 3596 |
'' asFilename constructString:'baz' |
2911 | 3597 |
" |
3598 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3599 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3600 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3601 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3602 |
"Modified: / 27.7.1998 / 19:47:51 / cg" |
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3603 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3604 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3605 |
filenameFor:fileName |
6973 | 3606 |
"return a filename representing the argument, fileName |
3607 |
either in myself (if the arg is a releative path) or absolute otherwise." |
|
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3608 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3609 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3610 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3611 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3612 |
f isAbsolute ifTrue:[^ f]. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3613 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3614 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3615 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3616 |
'/tmp' asFilename filenameFor:'foo' |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3617 |
'/tmp' asFilename filenameFor:'/foo' |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3618 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3619 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3620 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
9263 | 3621 |
! |
3622 |
||
3623 |
secureConstruct:subname |
|
3624 |
"taking the receiver as a directory name, construct a new |
|
3625 |
filename for an entry within this directory |
|
3626 |
(i.e. for a file or a subdirectory in that directory). |
|
3627 |
The argument may not specify an absolute path name. |
|
3628 |
Please do not use this to create filenames with suffixes, |
|
3629 |
since some systems require special naming conventions. |
|
3630 |
See also: #withSuffix: (which is different, but often needed). |
|
3631 |
||
3632 |
This method differs from #construct:, by not permitting subName |
|
3633 |
to navigate above (via ..) the current filename." |
|
3634 |
||
3635 |
^ self class named:(self secureConstructString:subname) |
|
3636 |
||
3637 |
" |
|
3638 |
'/tmp' asFilename secureConstruct:'foo' |
|
3639 |
'/tmp' asFilename secureConstruct:'../foo' |
|
3640 |
'/tmp' asFilename secureConstruct:'/./foo' |
|
3641 |
'/tmp' asFilename secureConstruct:'foo/../bar' |
|
3642 |
'/' asFilename secureConstruct:'foo' |
|
3643 |
'/usr/tmp' asFilename secureConstruct:'foo' |
|
3644 |
'/foo/bar' asFilename secureConstruct:'baz' |
|
3645 |
'/foo/bar' asFilename secureConstruct:'baz' asFilename |
|
3646 |
||
3647 |
Bad example; works on UNIX, but may not on others: |
|
3648 |
'foo/bar.baz' secureConstruct:'.suff' |
|
3649 |
" |
|
3650 |
||
3651 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
|
3652 |
! |
|
3653 |
||
3654 |
secureConstructString:subName |
|
3655 |
"taking the receiver as a directory name, construct a new |
|
3656 |
filename-string for an entry within this directory |
|
3657 |
(i.e. for a file or a subdirectory in that directory). |
|
3658 |
||
3659 |
This method differs from #constructString, by not permitting subName |
|
3660 |
to navigate above (via ..) the current filename. |
|
3661 |
||
3662 |
The code below works for UNIX & MSDOS; |
|
3663 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3664 |
||
3665 |
|sepString sub normalizedPath pathStream| |
|
3666 |
||
3667 |
sepString := self class separatorString. |
|
3668 |
sub := subName asString. |
|
3669 |
||
3670 |
sub := sub asCollectionOfSubstringsSeparatedByAll:sepString. |
|
3671 |
normalizedPath := OrderedCollection new:sub size. |
|
3672 |
sub do:[:eachPathComponent| |
|
3673 |
eachPathComponent = '..' ifTrue:[ |
|
3674 |
normalizedPath isEmpty ifTrue:[ |
|
3675 |
self error:'secureConstruct: - trying to escape from: ', nameString. |
|
3676 |
]. |
|
3677 |
normalizedPath removeLast. |
|
3678 |
] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[ |
|
3679 |
normalizedPath add:eachPathComponent. |
|
3680 |
]] |
|
3681 |
]. |
|
3682 |
pathStream := WriteStream with:nameString. |
|
3683 |
(nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[ |
|
3684 |
pathStream nextPutAll:sepString. |
|
3685 |
]. |
|
3686 |
normalizedPath do:[:eachPathComponent| |
|
3687 |
pathStream nextPutAll:eachPathComponent. |
|
3688 |
] separatedBy:[ |
|
3689 |
pathStream nextPutAll:sepString. |
|
3690 |
]. |
|
3691 |
||
3692 |
^ pathStream contents. |
|
3693 |
||
3694 |
" |
|
3695 |
'/tmp' asFilename secureConstructString:'foo' |
|
3696 |
'/tmp' asFilename secureConstructString:'../foo' |
|
3697 |
'/tmp' asFilename secureConstructString:'foo/../bla' |
|
3698 |
'/tmp' asFilename secureConstructString:'foo/./bla' |
|
3699 |
'/tmp' asFilename secureConstructString:'/bla/foo/../../foo' |
|
3700 |
'/' asFilename secureConstructString:'foo' |
|
3701 |
'/usr/tmp' asFilename secureConstructString:'foo' |
|
3702 |
'/foo/bar' asFilename secureConstructString:'baz' |
|
3703 |
'' asFilename secureConstructString:'baz' |
|
3704 |
'' asFilename secureConstructString:'/baz' |
|
3705 |
" |
|
2 | 3706 |
! ! |
3707 |
||
195 | 3708 |
!Filename methodsFor:'misc'! |
3709 |
||
3710 |
, aString |
|
3711 |
"this allows filenames to understand how names are concatenated. |
|
308 | 3712 |
Returns a string consisting of the receivers name, concatenated |
195 | 3713 |
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
|
3714 |
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
|
3715 |
See also: #withSuffix: which is new and better." |
195 | 3716 |
|
5866 | 3717 |
<resource:#obsolete> |
3718 |
||
2906 | 3719 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 3720 |
^ (nameString , aString asString) |
195 | 3721 |
|
3722 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3723 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3724 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3725 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3726 |
'Makefile' asFilename construct:'.bak' |
195 | 3727 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3728 |
|
2906 | 3729 |
"Modified: 7.9.1997 / 23:45:36 / cg" |
9263 | 3730 |
! |
3731 |
||
3732 |
canonicalize |
|
3733 |
"normalize a filename by removing all empty path components or dots, |
|
3734 |
and by resolving parent directory '..' references. |
|
3735 |
||
3736 |
The code below works for UNIX & MSDOS; |
|
3737 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3738 |
||
3739 |
nameString := self class canonicalize:nameString. |
|
3740 |
||
3741 |
" |
|
3742 |
'/tmp/bla' asFilename canonicalize. |
|
3743 |
'/tmp/bla/../fasel' asFilename canonicalize. |
|
3744 |
'/tmp/bla/.././/fasel' asFilename canonicalize. |
|
3745 |
'..' asFilename canonicalize. |
|
3746 |
'bla/../fasel' asFilename canonicalize. |
|
3747 |
'//bla/../fasel' asFilename canonicalize. |
|
3748 |
" |
|
195 | 3749 |
! ! |
3750 |
||
615 | 3751 |
!Filename methodsFor:'printing & storing'! |
174 | 3752 |
|
615 | 3753 |
printOn:aStream |
4392 | 3754 |
"append a user printed representation of the receiver to aStream. |
3755 |
The format is suitable for a human - not meant to be read back." |
|
174 | 3756 |
|
2906 | 3757 |
aStream nextPutAll:(self class name). |
3758 |
aStream nextPutAll:'('''. |
|
615 | 3759 |
nameString printOn:aStream. |
3760 |
aStream nextPutAll:''')' |
|
2906 | 3761 |
|
3762 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 3763 |
! |
3764 |
||
615 | 3765 |
storeOn:aStream |
3766 |
"append a printed representation of the receiver to aStream, |
|
3767 |
which allows reconstructing it via readFrom:" |
|
328 | 3768 |
|
615 | 3769 |
aStream nextPut:$(. |
3770 |
nameString storeOn:aStream. |
|
3771 |
aStream nextPutAll:' asFilename)' |
|
1 | 3772 |
! ! |
3773 |
||
7258 | 3774 |
!Filename methodsFor:'private-accessing'! |
1 | 3775 |
|
6227 | 3776 |
getName |
3777 |
"get the raw filename" |
|
3778 |
||
3779 |
^ nameString |
|
3780 |
! |
|
3781 |
||
68 | 3782 |
setName:aString |
38 | 3783 |
"set the filename" |
3784 |
||
3666 | 3785 |
nameString := self nameWithSpecialExpansions:aString. |
3786 |
||
3787 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 3788 |
! ! |
3789 |
||
2 | 3790 |
!Filename methodsFor:'queries'! |
3791 |
||
68 | 3792 |
exists |
92 | 3793 |
"return true, if such a file exists." |
68 | 3794 |
|
2947 | 3795 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 3796 |
|
85 | 3797 |
" |
92 | 3798 |
'/foo/bar' asFilename exists |
3799 |
'/tmp' asFilename exists |
|
3800 |
'Makefile' asFilename exists |
|
85 | 3801 |
" |
77 | 3802 |
! |
3803 |
||
5928 | 3804 |
filenamesMatching:aPattern |
3805 |
"VW compatibility" |
|
3806 |
||
3807 |
^ (self filesMatching:aPattern) asOrderedCollection |
|
9453 | 3808 |
collect:[:eachName | self construct:eachName] |
5928 | 3809 |
|
3810 |
" |
|
3811 |
'/etc' asFilename filenamesMatching:'a*;c*' |
|
3812 |
" |
|
3813 |
||
3814 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
3815 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
3816 |
! |
|
3817 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3818 |
filesMatching:aPattern |
2550 | 3819 |
"given the receiver, representing a directory; |
3820 |
return a collection of files matching a pattern. |
|
3821 |
The pattern may be a simple matchPattern, or a set of |
|
3822 |
multiple patterns separated by semicolons." |
|
3823 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3824 |
|matchers notCaseSensitive| |
2550 | 3825 |
|
3826 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3827 |
notCaseSensitive := self class isCaseSensitive not. |
2550 | 3828 |
^ self directoryContents |
9453 | 3829 |
select:[:name | |
3830 |
(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0 |
|
3831 |
] |
|
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3832 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3833 |
" |
2550 | 3834 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3835 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3836 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3837 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3838 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 3839 |
! |
3840 |
||
3841 |
filesMatchingWithoutDotDirs:aPattern |
|
3842 |
"given the receiver, representing a directory; |
|
3843 |
return a collection of files matching a pattern. |
|
3844 |
Exclude '.' and '..' from the returned list. |
|
3845 |
The pattern may be a simple matchPattern, or a set of |
|
3846 |
multiple patterns separated by semicolons." |
|
3847 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3848 |
|matchers notCaseSensitive| |
2550 | 3849 |
|
3850 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3851 |
notCaseSensitive := self class isCaseSensitive not. |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3852 |
|
2550 | 3853 |
^ self directoryContents |
9453 | 3854 |
select:[:name | |
3855 |
name ~= '.' |
|
3856 |
and:[name ~= '..' |
|
3857 |
and:[(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0]] |
|
2550 | 3858 |
] |
3859 |
||
3860 |
" |
|
3861 |
Filename currentDirectory filesMatching:'M*' |
|
3862 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
3863 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
3864 |
" |
|
3865 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3866 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
3867 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3868 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
3869 |
|
9206 | 3870 |
fullAlternativePathName |
3871 |
^ nameString |
|
3872 |
! |
|
3873 |
||
615 | 3874 |
isExecutable |
3875 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
3876 |
For directories, true is returned if the directory can be entered. |
|
3877 |
See isExecutableProgram for a related check." |
|
3878 |
||
2947 | 3879 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 3880 |
|
3881 |
" |
|
3882 |
'/foo/bar' asFilename isExecutable |
|
3883 |
'/tmp' asFilename isExecutable |
|
3884 |
'Makefile' asFilename isExecutable |
|
3885 |
'/bin/ls' asFilename isExecutable |
|
356 | 3886 |
" |
3887 |
! |
|
3888 |
||
615 | 3889 |
isExecutableProgram |
3890 |
"return true, if such a file exists and is an executable program. |
|
3891 |
(i.e. for directories, false is returned.)" |
|
356 | 3892 |
|
2922 | 3893 |
|osName| |
3894 |
||
2947 | 3895 |
osName := self osNameForAccess. |
2922 | 3896 |
^ (OperatingSystem isExecutable:osName) |
3897 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 3898 |
|
3899 |
" |
|
615 | 3900 |
'/tmp' asFilename isExecutable |
3901 |
'/bin/ls' asFilename isExecutable |
|
3902 |
'/tmp' asFilename isExecutableProgram |
|
3903 |
'/bin/ls' asFilename isExecutableProgram |
|
3904 |
" |
|
3905 |
! |
|
3906 |
||
2922 | 3907 |
isHidden |
3908 |
"return true, if the receiver represents a hidden file. |
|
3909 |
The definitions of hidden files depends on the OS used; |
|
3910 |
on UNIX, a name starting with a period is considered hidden; |
|
12388 | 3911 |
on MSDOS, the files hidden attribute is also used. |
2922 | 3912 |
VMS has no concept of hidden files." |
3913 |
||
3914 |
^ false |
|
3915 |
! |
|
3916 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3917 |
isMountPoint:aPathName |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3918 |
"return true, if I represent a mount-point. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3919 |
Warning: |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3920 |
the receiver must be an absolute pathname, |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3921 |
because a realPath is not used/generated for the query (to avoid automounting). |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3922 |
Aka: do not ask: '../../' asFilename isMountPoint; |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3923 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3924 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3925 |
self isAbsolute ifFalse:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3926 |
self error:'this query must be done on an absolute pathname'. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3927 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3928 |
^ OperatingSystem isMountPoint:(self name) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3929 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
3930 |
|
615 | 3931 |
isReadable |
3932 |
"return true, if such a file exists and is readable." |
|
3933 |
||
2947 | 3934 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 3935 |
|
3936 |
" |
|
3937 |
'/foo/bar' asFilename isReadable |
|
3938 |
'/tmp' asFilename isReadable |
|
3939 |
'Makefile' asFilename isReadable |
|
328 | 3940 |
" |
3941 |
! |
|
3942 |
||
11529 | 3943 |
isSharedLibrary |
3944 |
"return true, if such a file exists and is a shared library." |
|
3945 |
||
3946 |
ObjectFileLoader isNil ifTrue:[ |
|
3947 |
"we cannot handle shared libraries, so there are no shared libraries" |
|
3948 |
^ false. |
|
3949 |
]. |
|
3950 |
self isRegularFile ifFalse:[ |
|
3951 |
^ false. |
|
3952 |
]. |
|
3953 |
^ ObjectFileLoader validBinaryExtensions includes:self suffix. |
|
3954 |
||
3955 |
" |
|
3956 |
'libstx_libbasic.so' asFilename isSharedLibrary |
|
3957 |
'libstx_libbasic.dll' asFilename isSharedLibrary |
|
3958 |
'/tmp' asFilename isSharedLibrary |
|
3959 |
" |
|
3960 |
! |
|
3961 |
||
615 | 3962 |
isWritable |
3963 |
"return true, if such a file exists and is writable." |
|
3964 |
||
2947 | 3965 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 3966 |
|
3967 |
" |
|
3968 |
'/foo/bar' asFilename isWritable |
|
3969 |
'/tmp' asFilename isWritable |
|
3970 |
'Makefile' asFilename isWritable |
|
328 | 3971 |
" |
174 | 3972 |
! |
3973 |
||
8946
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3974 |
nameWithSpecialExpansions:aString |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3975 |
"return the nameString, expanding any OS specific macros. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3976 |
Here, a ~\ prefix is expanded to the users home dir (as in csh)" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3977 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3978 |
|dir user cutIdx idx userInfo| |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3979 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3980 |
(aString startsWith:'~') ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3981 |
dir := OperatingSystem getHomeDirectory. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3982 |
cutIdx := 2. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3983 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3984 |
(aString size > 1) ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3985 |
idx := aString indexOf:(self separator). |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3986 |
idx == 0 ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3987 |
user := aString copyFrom:2. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3988 |
cutIdx := aString size + 1. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3989 |
] ifFalse:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3990 |
user := aString copyFrom:2 to:(idx - 1). |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3991 |
cutIdx := idx. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3992 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3993 |
user size > 0 ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3994 |
userInfo := OperatingSystem userInfoOf:user. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3995 |
(userInfo notNil and:[userInfo includesKey:#dir]) ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3996 |
dir := userInfo at:#dir |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3997 |
] ifFalse:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3998 |
dir := nil |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
3999 |
] |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4000 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4001 |
dir isNil ifTrue:[ |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4002 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4003 |
^ aString |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4004 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4005 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4006 |
^ dir , (aString copyFrom:cutIdx) |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4007 |
]. |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4008 |
^ aString |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4009 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4010 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4011 |
Filename new nameWithSpecialExpansions:'~' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4012 |
Filename new nameWithSpecialExpansions:'~\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4013 |
Filename new nameWithSpecialExpansions:'~sv' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4014 |
Filename new nameWithSpecialExpansions:'~sv\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4015 |
Filename new nameWithSpecialExpansions:'~foo' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4016 |
Filename new nameWithSpecialExpansions:'~foo\bar' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4017 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4018 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4019 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4020 |
UnixFilename new nameWithSpecialExpansions:'~' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4021 |
UnixFilename new nameWithSpecialExpansions:'~/work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4022 |
UnixFilename new nameWithSpecialExpansions:'~sv' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4023 |
UnixFilename new nameWithSpecialExpansions:'~sv/work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4024 |
UnixFilename new nameWithSpecialExpansions:'~foo' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4025 |
UnixFilename new nameWithSpecialExpansions:'~foo/bar' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4026 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4027 |
|
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4028 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4029 |
PCFilename new nameWithSpecialExpansions:'~' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4030 |
PCFilename new nameWithSpecialExpansions:'~\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4031 |
PCFilename new nameWithSpecialExpansions:'~sv' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4032 |
PCFilename new nameWithSpecialExpansions:'~sv\work' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4033 |
PCFilename new nameWithSpecialExpansions:'~foo' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4034 |
PCFilename new nameWithSpecialExpansions:'~foo\bar' |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4035 |
" |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4036 |
! |
49e64eef0a55
nameWithSpecialExpansions: now also for windows.
Claus Gittinger <cg@exept.de>
parents:
8836
diff
changeset
|
4037 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4038 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4039 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4040 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4041 |
^ self class separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4042 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4043 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
8947 | 4044 |
! |
4045 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4046 |
species |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4047 |
^ Filename concreteClass |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4048 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4049 |
|
8947 | 4050 |
withSpecialExpansions |
4051 |
"return a new filename, expanding any OS specific macros. |
|
4052 |
Here, a ~\ prefix is expanded to the users home dir (as in csh)" |
|
4053 |
||
4054 |
|newName| |
|
4055 |
||
4056 |
newName := self nameWithSpecialExpansions:nameString. |
|
4057 |
newName ~= nameString ifTrue:[ |
|
4058 |
^ newName asFilename. |
|
4059 |
]. |
|
4060 |
^ self. |
|
4061 |
||
4062 |
" |
|
4063 |
'~' asFilename withSpecialExpansions |
|
4064 |
'~\work' asFilename withSpecialExpansions |
|
4065 |
'~sv'asFilename withSpecialExpansions |
|
4066 |
'~sv\work' asFilename withSpecialExpansions |
|
4067 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4068 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4069 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4070 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4071 |
|
7291 | 4072 |
mimeTypeFromName |
4073 |
"return the mimeType as guessed from the files name/and or extension. |
|
4074 |
This could be less accurate than mimeTypeOfContents, but avoids |
|
4075 |
reading the file (is therefore much faster). |
|
4076 |
Also it works with non-existing files. |
|
4077 |
Returns nil for directories and other non-regular files." |
|
4078 |
||
4079 |
^ MIMETypes mimeTypeForFilename:(self name) |
|
4080 |
||
4081 |
" |
|
4082 |
'Makefile' asFilename mimeTypeFromName |
|
4083 |
'.' asFilename mimeTypeFromName |
|
4084 |
'/dev/null' asFilename mimeTypeFromName |
|
4085 |
'/tmp/.X11-unix/X0' asFilename mimeTypeFromName |
|
4086 |
'smalltalk.rc' asFilename mimeTypeFromName |
|
4087 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName |
|
4088 |
'../../rules/stmkmf' asFilename mimeTypeFromName |
|
4089 |
'/bläh' asFilename mimeTypeFromName |
|
10902 | 4090 |
'/x.zip' asFilename mimeTypeFromName |
4091 |
'/x.gz' asFilename mimeTypeFromName |
|
7291 | 4092 |
" |
4093 |
! |
|
4094 |
||
5011 | 4095 |
mimeTypeOfContents |
4096 |
"this tries to guess the mime type of contents of |
|
4097 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
4098 |
or the contents is unknown. |
|
4099 |
This is done using some heuristics, and may need some improvement" |
|
4100 |
||
10153 | 4101 |
|type buffer lcBuffer s size idx idx2| |
5011 | 4102 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4103 |
type := self type. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4104 |
type isNil ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4105 |
type == #directory ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4106 |
type == #characterSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4107 |
type == #blockSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4108 |
type == #socket ifTrue:[ ^ nil ]. |
5011 | 4109 |
self fileSize == 0 ifTrue:[^ nil]. |
4110 |
||
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4111 |
s := self readStreamOrNil. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4112 |
s isNil ifTrue:[^ nil]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4113 |
|
5011 | 4114 |
"/ read some data from the file ... |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
4115 |
buffer := String new:2048. |
5011 | 4116 |
|
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4117 |
s errorSignal handle:[:ex | |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4118 |
size := 0. |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4119 |
] do:[ |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4120 |
size := s nextBytes:buffer size into:buffer. |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4121 |
]. |
5011 | 4122 |
s close. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4123 |
|
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4124 |
^ MIMETypes mimeTypeOfData:buffer |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4125 |
|
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4126 |
"/ lcBuffer := buffer asLowercase. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4127 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4128 |
"/ (idx := lcBuffer findString:'mimetype:') ~~ 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4129 |
"/ idx := idx + 'mimetype:' size. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4130 |
"/ idx := lcBuffer indexOfNonSeparatorStartingAt:idx. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4131 |
"/ idx2 := lcBuffer indexOfSeparatorStartingAt:idx. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4132 |
"/ idx2 > idx ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4133 |
"/ ^ lcBuffer copyFrom:idx to:idx2-1 |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4134 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4135 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4136 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4137 |
"/ #( |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4138 |
"/ ( 'lnk' #[16r4C 16r00 16r00 16r00 16r01 16r14 16r02 16r00 16r00 16r00 16r00 16r00 16rC0 16r00 16r00 16r00 16r00 16r00 16r00 16r46] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4139 |
"/ #'application/x-ms-shortcut' ) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4140 |
"/ ( 'top' 'WALTOP' |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4141 |
"/ #'application/x-waltop-digital-notepad' ) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4142 |
"/ ) triplesDo:[:suffixMatch :pattern :what | |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4143 |
"/ |patternString| |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4144 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4145 |
"/ (suffixMatch isNil or:[suffixMatch match:self suffix ignoreCase:true]) ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4146 |
"/ patternString := pattern asString. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4147 |
"/ (buffer startsWith:patternString) ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4148 |
"/ ^ what |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4149 |
"/ ] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4150 |
"/ ] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4151 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4152 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4153 |
"/ #( |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4154 |
"/ ('<body:' #'text/html') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4155 |
"/ ('%!!ps-adobe' #'application/postscript') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4156 |
"/ ('%PDF-' #'application/pdf') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4157 |
"/ ('#!! /bin/sh' #'application/x-sh') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4158 |
"/ ('#!!/bin/sh' #'application/x-sh') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4159 |
"/ "/ ('#!! /bin/bash' 'application/x-bash') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4160 |
"/ "/ ('#!!/bin/bash' 'application/x-bash') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4161 |
"/ ('<?xml version=' #'text/xml') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4162 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4163 |
"/ ('from dolphin' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4164 |
"/ ('from visualworks' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4165 |
"/ ('categoriesforclass' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4166 |
"/ ('methodsfor!!' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4167 |
"/ ('subclass:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4168 |
"/ ('methodsfor:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4169 |
"/ ('interchangeversion:' #'application/x-smalltalk-source-sif') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4170 |
"/ ('subclass:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4171 |
"/ ('methodsfor:' #'application/x-smalltalk-source') |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4172 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4173 |
"/ ) pairsDo:[:pattern :what | |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4174 |
"/ (lcBuffer findString:pattern) ~~ 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4175 |
"/ ^ what |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4176 |
"/ ] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4177 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4178 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4179 |
"/ (idx := lcBuffer findString:'<h') ~~ 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4180 |
"/ ((lcBuffer continuesWith:'<head' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4181 |
"/ or:[(lcBuffer continuesWith:'<html' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4182 |
"/ or:[(lcBuffer continuesWith:'<h1' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4183 |
"/ or:[(lcBuffer continuesWith:'<h2' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4184 |
"/ or:[(lcBuffer continuesWith:'<h3' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4185 |
"/ or:[(lcBuffer continuesWith:'<h4' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4186 |
"/ or:[(lcBuffer continuesWith:'<h5' startingAt:idx) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4187 |
"/ or:[(lcBuffer continuesWith:'<h6' startingAt:idx)]]]]]]]) |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4188 |
"/ ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4189 |
"/ ^ #'text/html' |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4190 |
"/ ] |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4191 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4192 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4193 |
"/ [size ~~ 0 and:[(buffer at:size) isPrintable]] whileTrue:[size := size - 1]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4194 |
"/ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4195 |
"/ size == 0 ifTrue:[ |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4196 |
"/ ^ #'text/plain' |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4197 |
"/ ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4198 |
"/ ^ nil |
5011 | 4199 |
|
4200 |
" |
|
6753
1a4a541850f2
add search for unprintable characters on mimeTypeContents
penk
parents:
6729
diff
changeset
|
4201 |
'Makefile' asFilename mimeTypeOfContents |
1a4a541850f2
add search for unprintable characters on mimeTypeContents
penk
parents:
6729
diff
changeset
|
4202 |
'.' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4203 |
'/dev/null' asFilename mimeTypeOfContents |
10153 | 4204 |
'/tmp/.X11-unix/X0' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4205 |
'smalltalk.rc' asFilename mimeTypeOfContents |
5011 | 4206 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents |
10153 | 4207 |
'../../rules/stmkmf' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4208 |
'/bläh' asFilename mimeTypeOfContents |
10153 | 4209 |
'C:\Dokumente und Einstellungen\cg\Favoriten\languages.lnk' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4210 |
'G:\A\A01.TOP' asFilename mimeTypeOfContents |
10153 | 4211 |
" |
4212 |
||
4213 |
"Modified: / 06-11-2006 / 11:44:58 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4214 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4215 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4216 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4217 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4218 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4219 |
"return my baseName as a string. |
2012 | 4220 |
- thats the file/directory name without leading parent-dirs. |
2922 | 4221 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
4222 |
and '/usr/lib' asFilename baseName -> lib). |
|
7075 | 4223 |
This method does not check if the path is valid. |
4224 |
The code here should work for Unix and MSDOS, but needs to be redefined |
|
4225 |
for VMS (and maybe others as well). |
|
2911 | 4226 |
See also: #pathName, #directoryName and #directoryPathName. |
4227 |
Compatibility note: use #tail for ST-80 compatibility." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4228 |
|
2922 | 4229 |
|len index sep endIdx| |
4230 |
||
4231 |
sep := self separator. |
|
4232 |
len := nameString size. |
|
4233 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
7075 | 4234 |
^ nameString |
2922 | 4235 |
]. |
4236 |
||
4237 |
endIdx := len. |
|
4238 |
len > 1 ifTrue:[ |
|
7075 | 4239 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
2922 | 4240 |
]. |
4241 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
4242 |
^ nameString copyFrom:(index+1) to:endIdx |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4243 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4244 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4245 |
'/foo/bar' asFilename baseName |
4903 | 4246 |
'/foo/bar.cc' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4247 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4248 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4249 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4250 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4251 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4252 |
'../../libbasic/Object.st' asFilename baseName |
3851 | 4253 |
'/' asFilename baseName |
4254 |
'\' asFilename baseName |
|
4255 |
'c:\' asFilename baseName |
|
4256 |
'\\idefix' asFilename baseName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4257 |
" |
2012 | 4258 |
|
3851 | 4259 |
"Modified: / 24.9.1998 / 13:06:23 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4260 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4261 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4262 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4263 |
"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
|
4264 |
- 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
|
4265 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4266 |
(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
|
4267 |
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
|
4268 |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
4269 |
^ self class named:(self directoryName) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4270 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4271 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4272 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4273 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4274 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4275 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4276 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4277 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4278 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4279 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4280 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4281 |
"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
|
4282 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4283 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4284 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4285 |
"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
|
4286 |
- 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
|
4287 |
the receiver is contained in. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4288 |
This method does not check if the path is valid. |
2922 | 4289 |
|
4290 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
4291 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
4292 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4293 |
(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
|
4294 |
a string instead of a Filename instance). |
2922 | 4295 |
|
2012 | 4296 |
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
|
4297 |
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
|
4298 |
|
3954 | 4299 |
|index sep sepString p rest| |
2922 | 4300 |
|
4301 |
sep := self separator. |
|
4302 |
sepString := sep asString. |
|
4303 |
(nameString = sepString) ifTrue:[ |
|
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4304 |
"/ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4305 |
"/ the trivial '/' case |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4306 |
"/ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4307 |
^ nameString |
2922 | 4308 |
]. |
4309 |
||
4310 |
"/ |
|
3893 | 4311 |
"/ strip off multiple trailing slashes |
2922 | 4312 |
"/ |
4313 |
p := nameString. |
|
4314 |
[p endsWith:sepString] whileTrue:[ |
|
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4315 |
(p = sepString) ifTrue:[ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4316 |
^ p |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4317 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4318 |
p := p copyWithoutLast:1 |
2922 | 4319 |
]. |
4320 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4321 |
"/ strip off trailing components |
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4322 |
|
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4323 |
index := p lastIndexOf:sep startingAt:p size. |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4324 |
index == 0 ifTrue:[ |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4325 |
"/ no separator found |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4326 |
p = '.' ifTrue:[ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4327 |
^ '..' |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4328 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4329 |
p = '..' ifTrue:[ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4330 |
^ '../..' |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4331 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4332 |
^ '.' |
2922 | 4333 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4334 |
rest := p copyFrom:(index+1). |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4335 |
(rest = '.') ifTrue:[ |
7519
0cfe202e7e3e
#directoryName returned a Filename
Stefan Vogel <sv@exept.de>
parents:
7473
diff
changeset
|
4336 |
^ p copyTo:index-1. |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4337 |
]. |
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4338 |
(rest = '..') ifTrue:[ |
7343 | 4339 |
^ (self class named:(p copyTo:(index-1))) directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4340 |
]. |
3893 | 4341 |
index == 1 ifTrue:[ |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4342 |
^ '/' |
3893 | 4343 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4344 |
^ p copyTo:(index - 1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4345 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4346 |
" |
3893 | 4347 |
'/home' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4348 |
'/foo/bar/' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4349 |
'/foo/bar/' asFilename directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4350 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4351 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4352 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4353 |
'bitmaps' asFilename directoryPathName |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4354 |
'.' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4355 |
'.' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4356 |
'..' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4357 |
'..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4358 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4359 |
'../..' asFilename directoryPathName |
7343 | 4360 |
'/foo/bar/baz/..' asFilename directoryName |
4361 |
'/foo/bar/baz/.' asFilename directoryName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4362 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4363 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4364 |
"Modified: / 7.9.1995 / 10:42:03 / claus" |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4365 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 4366 |
"Modified: / 27.10.1998 / 13:19:26 / ps" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4367 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4368 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4369 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4370 |
"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
|
4371 |
- 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
|
4372 |
the receiver is contained in. |
2012 | 4373 |
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
|
4374 |
|
4373
87d2d048e232
return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents:
4324
diff
changeset
|
4375 |
^ (self class named:self pathName) directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4376 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4377 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4378 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4379 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4380 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4381 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4382 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4383 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4384 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4385 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4386 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4387 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4388 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4389 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4390 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4391 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4392 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 4393 |
"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
|
4394 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4395 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4396 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4397 |
"try to complete the receiver filename. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4398 |
BAD DESIGN: has side effect on the receiver. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4399 |
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
|
4400 |
it returns a collection of matching filename objects, |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4401 |
and changes the receivers filename-string to the longest common |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4402 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4403 |
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
|
4404 |
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
|
4405 |
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
|
4406 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4407 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4408 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4409 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4410 |
'mak' asFilename filenameCompletion |
1517 | 4411 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4412 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4413 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4414 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4415 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4416 |
|
1517 | 4417 |
"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
|
4418 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4419 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4420 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4421 |
"try to complete the receiver filename. |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4422 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4423 |
BAD DESIGN: has side effect on the receiver. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4424 |
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
|
4425 |
it returns a collection of matching filename objects, |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4426 |
and changes the receiver's filename-string to the longest common match. |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4427 |
If none matches, the returned collection is empty and the receiver is unchanged. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4428 |
If there is only one match, the size of the returned collection is exactly 1, |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4429 |
containing the fully expanded filename and the receiver's name is changed to it. |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4430 |
An empty baseName pattern (i.e. giving the name of a directory) will also return an empty matchset." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4431 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4432 |
|dir baseName matching matchLen try allMatching |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4433 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 4434 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4435 |
caseless := self class isCaseSensitive not. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4436 |
matching := OrderedCollection new. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4437 |
|
3666 | 4438 |
nm := self nameWithSpecialExpansions:nameString. |
6803 | 4439 |
nm := self class canonicalize:nm. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4440 |
|
8243 | 4441 |
sepString := self class separatorString. |
3666 | 4442 |
(nm endsWith:sepString) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4443 |
"/ two exceptions here: |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4444 |
"/ if there is only one file in the directory, that one must be it. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4445 |
"/ otherwise, return the longest common prefix of all files. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4446 |
self isDirectory ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4447 |
|first longest| |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4448 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4449 |
first := nil. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4450 |
self directoryContentsDo:[:fileName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4451 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4452 |
matching add:fileName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4453 |
first isNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4454 |
first := longest := fileName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4455 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4456 |
"/ more than one file |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4457 |
longest := longest commonPrefixWith:fileName ignoreCase:caseless. |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4458 |
longest isEmpty ifTrue:[ |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4459 |
^ #() |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4460 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4461 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4462 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4463 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4464 |
longest notNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4465 |
nameString := (self constructString:longest). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4466 |
^ matching |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4467 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4468 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4469 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4470 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4471 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4472 |
parentString := self class parentDirectoryName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4473 |
baseName := self baseName. |
3666 | 4474 |
baseName ~= nm ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4475 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4476 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4477 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4478 |
self isAbsolute ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4479 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4480 |
] ifFalse:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4481 |
aDirectory isNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4482 |
dir := self directory |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4483 |
] ifFalse:[ |
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4484 |
dir := (aDirectory asFilename construct:nm) directory |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4485 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4486 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4487 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4488 |
caseless ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4489 |
lcBaseName := baseName asLowercase |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4490 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4491 |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
4492 |
dir class errorReporter openErrorSignal handle:[:ex| |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4493 |
^ #(). |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
4494 |
] do:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4495 |
dir directoryContents do:[:fileName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4496 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4497 |
((caseless and:[fileName asLowercase startsWith:lcBaseName]) |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4498 |
or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4499 |
matching add:fileName |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4500 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4501 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4502 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4503 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4504 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4505 |
(nMatch := matching size) > 1 ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4506 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4507 |
find the longest common prefix |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4508 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4509 |
matchLen := baseName size. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4510 |
matchLen > matching first size ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4511 |
try := baseName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4512 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4513 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4514 |
try := matching first copyTo:matchLen. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4515 |
allMatching := true. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4516 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4517 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4518 |
[allMatching] whileTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4519 |
matching do:[:aName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4520 |
((caseless and:[aName asLowercase startsWith:try asLowercase]) |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4521 |
or:[caseless not and:[aName startsWith:try]]) ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4522 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4523 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4524 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4525 |
allMatching ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4526 |
matchLen < matching first size ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4527 |
matchLen := matchLen + 1. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4528 |
try := matching first copyTo:matchLen. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4529 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4530 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4531 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4532 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4533 |
try := matching first copyTo:matchLen - 1. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4534 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4535 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4536 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4537 |
and set my name to the last full match |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4538 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4539 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4540 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4541 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4542 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4543 |
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
|
4544 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4545 |
prefix notNil ifTrue:[ |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4546 |
(prefix endsWith:sepString) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4547 |
"/ avoid introducing double slashes |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4548 |
prefix := prefix copyWithoutLast:(sepString size). |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4549 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4550 |
matching := matching collect:[:n | prefix , sepString , n]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4551 |
nMatch == 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4552 |
nameString := nm := matching first |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4553 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4554 |
nMatch > 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4555 |
nameString := nm := prefix , sepString , nm |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4556 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4557 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4558 |
] ifFalse:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4559 |
nMatch == 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4560 |
nameString := nm := matching first |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4561 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4562 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4563 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4564 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4565 |
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
|
4566 |
(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
|
4567 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4568 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4569 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4570 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4571 |
|
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4572 |
'../' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4573 |
'/' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4574 |
'/usr/' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4575 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4576 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4577 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4578 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4579 |
'/u' asFilename filenameCompletion |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4580 |
'../../libpr' asFilename filenameCompletion |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4581 |
'/etc/mail/auth/xx' asFilename filenameCompletion |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4582 |
|
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4583 |
'c:\pr' asFilename filenameCompletion -> matching names |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4584 |
'c:\pr' asFilename filenameCompletion; yourself -> side effect: name changed to longest match |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4585 |
'c:\p' asFilename filenameCompletion |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4586 |
'c:\' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4587 |
'c:' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4588 |
'\' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4589 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4590 |
|
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4591 |
"Modified: / 22-09-1997 / 18:03:33 / stefan" |
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4592 |
"Modified: / 17-11-2007 / 14:31:08 / cg" |
2903 | 4593 |
! |
4594 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4595 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4596 |
"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
|
4597 |
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
|
4598 |
(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
|
4599 |
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
|
4600 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4601 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4602 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4603 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4604 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4605 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4606 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4607 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4608 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4609 |
"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
|
4610 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4611 |
|
7120 | 4612 |
isAbsolute |
4613 |
"return true, if the receiver represents an absolute pathname |
|
4614 |
(in contrast to one relative to the current directory)." |
|
4615 |
||
4616 |
(nameString startsWith:self class separator) ifTrue:[^ true]. |
|
4617 |
^ self isVolumeAbsolute |
|
4618 |
||
4619 |
" |
|
4620 |
'/foo/bar' asFilename isAbsolute |
|
4621 |
'..' asFilename isAbsolute |
|
4622 |
'..' asAbsoluteFilename isAbsolute |
|
4623 |
'source/SBrowser.st' asFilename isAbsolute |
|
4624 |
" |
|
4625 |
! |
|
4626 |
||
4627 |
isExplicitRelative |
|
4628 |
"return true, if this name is an explicit relative name |
|
4629 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
4630 |
||
4631 |
^ false |
|
4632 |
! |
|
4633 |
||
4634 |
isImplicit |
|
4635 |
"return true, if the receiver represents a builtin file. |
|
4636 |
The definitions of builtin files depends on the OS used; |
|
4637 |
on UNIX, '.' and '..' are builtin names." |
|
4638 |
||
4639 |
^ false |
|
4640 |
||
4641 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
|
4642 |
! |
|
4643 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4644 |
isParentDirectoryOf:aFilenameOrString |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4645 |
"warning: may lead to automounting" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4646 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4647 |
|filenameArg otherName myName| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4648 |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4649 |
filenameArg := aFilenameOrString asFilename. |
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4650 |
filenameArg isDirectory ifFalse:[ |
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4651 |
filenameArg := filenameArg directory. |
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4652 |
]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4653 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4654 |
otherName := filenameArg name. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4655 |
myName := self name. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4656 |
(otherName startsWith:myName ) ifTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4657 |
^ (otherName ~= myName) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4658 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4659 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4660 |
otherName := filenameArg pathName. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4661 |
myName := self pathName. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4662 |
(otherName startsWith:myName ) ifTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4663 |
^ (otherName ~= myName) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4664 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4665 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4666 |
filenameArg allParentDirectoriesDo:[:parent | |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4667 |
parent pathName = myName ifTrue:[^ true]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4668 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4669 |
^ false. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4670 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4671 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4672 |
'/etc' asFilename isParentDirectoryOf:'/etc/passwd' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4673 |
'/etc' asFilename isParentDirectoryOf:'/etc/' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4674 |
'/etc' asFilename isParentDirectoryOf:'/etc' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4675 |
'/home' asFilename isParentDirectoryOf:Filename currentDirectory |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4676 |
'/' asFilename isParentDirectoryOf:'/phys/qnx' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4677 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4678 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4679 |
|
7120 | 4680 |
isRelative |
4681 |
"return true, if this name is interpreted relative to some |
|
4682 |
directory (opposite of absolute)" |
|
4683 |
||
4684 |
^ self isAbsolute not |
|
4685 |
||
4686 |
" |
|
4687 |
'./foo/bar' asFilename isRelative |
|
4688 |
'../../foo/bar' asFilename isRelative |
|
4689 |
'/foo/bar' asFilename isRelative |
|
4690 |
'bar' asFilename isRelative |
|
4691 |
" |
|
4692 |
||
4693 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
4694 |
! |
|
4695 |
||
4696 |
isRootDirectory |
|
4697 |
"return true, if I represent the root directory |
|
4698 |
(i.e. I have no parentDir)" |
|
4699 |
||
4700 |
"/ mhmh - should we use: |
|
4701 |
"/ |
|
4702 |
"/ parentDir := self construct:'..'. |
|
4703 |
"/ (parentDir exists |
|
4704 |
"/ and:[parentDir isDirectory |
|
4705 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
|
4706 |
"/ ^ false |
|
4707 |
"/ ]. |
|
4708 |
"/ ^ true |
|
4709 |
"/ |
|
4710 |
||
4711 |
^ self pathName = Filename rootDirectory pathName |
|
4712 |
||
4713 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
4714 |
! |
|
4715 |
||
4716 |
isVolumeAbsolute |
|
4717 |
"return true, if the receiver represents an absolute pathname |
|
4718 |
on some disk volume (MSDOS only)" |
|
4719 |
||
4720 |
^ false |
|
4721 |
||
4722 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
4723 |
! |
|
4724 |
||
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4725 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4726 |
"return the full pathname of the file represented by the receiver, |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4727 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4728 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4729 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4730 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4731 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
4732 |
|
615 | 4733 |
name |
4734 |
"return the name of the file represented by the receiver as a string. |
|
883 | 4735 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 4736 |
See also: pathName" |
174 | 4737 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4738 |
"/ self isAbsolute ifTrue:[^ self pathName]. |
615 | 4739 |
^ nameString |
174 | 4740 |
|
4741 |
" |
|
615 | 4742 |
'/foo/bar' asFilename name |
4743 |
'/foo/bar' asFilename pathName |
|
4744 |
'.' asFilename name |
|
4745 |
'.' asFilename pathName |
|
4746 |
'../..' asFilename name |
|
883 | 4747 |
'../..' asFilename pathName |
615 | 4748 |
'bitmaps' asFilename name |
4749 |
'bitmaps' asFilename pathName |
|
4750 |
'/tmp/../usr' asFilename name |
|
883 | 4751 |
'/tmp/../usr' asFilename pathName |
4752 |
'source/..' asFilename name |
|
4753 |
'source/..' asFilename pathName |
|
4754 |
'/tmp/..' asFilename name |
|
4755 |
'/tmp/..' asFilename pathName |
|
92 | 4756 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4757 |
|
883 | 4758 |
"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
|
4759 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4760 |
|
7308 | 4761 |
nameString |
4762 |
"raw access to nameString - req'd for xml-store/reload" |
|
4763 |
||
4764 |
^ nameString |
|
4765 |
! |
|
4766 |
||
4767 |
nameString:aString |
|
4768 |
"raw access to nameString - req'd for xml-store/reload" |
|
4769 |
||
4770 |
nameString := aString |
|
4771 |
! |
|
4772 |
||
615 | 4773 |
pathName |
4774 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 4775 |
as a string. This will not include ..'s. |
4776 |
If the path represented by the receiver does NOT represent a valid path, |
|
4777 |
no compression will be done (for now; this may change). |
|
4778 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4779 |
|
1317 | 4780 |
|p| |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
4781 |
|
1317 | 4782 |
"/ sep := self class separator. |
4783 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
4784 |
"/ parentName := self class parentDirectoryName. |
|
4785 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
4786 |
"/ ^ nameString |
|
4787 |
"/ ] |
|
4788 |
"/ ]. |
|
4789 |
p := OperatingSystem pathNameOf:nameString. |
|
4790 |
^ p |
|
2 | 4791 |
|
92 | 4792 |
" |
1317 | 4793 |
'/foo/bar' asFilename pathName |
4794 |
'.' asFilename pathName |
|
4795 |
'../..' asFilename pathName |
|
4796 |
'../..' asFilename name |
|
4797 |
'/tmp/../usr' asFilename pathName |
|
4798 |
'/././usr' asFilename pathName |
|
92 | 4799 |
" |
159 | 4800 |
|
1317 | 4801 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 4802 |
! |
4803 |
||
11658 | 4804 |
physicalFilename |
4805 |
"return the fileName representing the physical file as represented by the receiver, |
|
4806 |
If the receiver represents a symbolic link, thats the fileName of the |
|
4807 |
final target. Otherwise, its the receivers pathName itself. |
|
4808 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
|
4809 |
nil is returned." |
|
4810 |
||
4811 |
|pathOrNil| |
|
4812 |
||
4813 |
pathOrNil := self physicalPathName. |
|
4814 |
pathOrNil isNil ifTrue:[ |
|
4815 |
^ nil |
|
4816 |
]. |
|
4817 |
^ pathOrNil asFilename |
|
4818 |
||
4819 |
" |
|
4820 |
'/foo/bar' asFilename physicalFileName |
|
4821 |
" |
|
4822 |
! |
|
4823 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4824 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4825 |
"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
|
4826 |
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
|
4827 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4828 |
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
|
4829 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4830 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4831 |
|t path info| |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4832 |
|
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4833 |
info := self linkInfo. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4834 |
info isNil ifTrue:[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4835 |
" I do not exist" |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4836 |
^ nil. |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4837 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4838 |
info isSymbolicLink ifFalse:[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4839 |
^ self pathName |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4840 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4841 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4842 |
t := self. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4843 |
[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4844 |
path := info path. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4845 |
path isNil ifTrue:[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4846 |
"/ cannot happen |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4847 |
^ nil |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4848 |
]. |
11657 | 4849 |
path asFilename isAbsolute ifTrue:[ |
4850 |
t := path asFilename |
|
4851 |
] ifFalse:[ |
|
4852 |
t := (self class named:t directoryName) construct:path. |
|
4853 |
]. |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4854 |
info := t linkInfo. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4855 |
info isNil ifTrue:[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4856 |
"t does not exist" |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4857 |
^ nil |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4858 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4859 |
] doWhile:[info isSymbolicLink]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4860 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4861 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4862 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4863 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4864 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4865 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4866 |
'../..' asFilename physicalPathName |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4867 |
'/usr/tmp' asFilename physicalPathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4868 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4869 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4870 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4871 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
4872 |
|
615 | 4873 |
tail |
4874 |
"the files name without directory prefix as a string. |
|
4875 |
An alias for baseName, for ST-80 compatiblity." |
|
174 | 4876 |
|
615 | 4877 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4878 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4879 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4880 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4881 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4882 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4883 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4884 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4885 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 4886 |
! |
4887 |
||
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4888 |
tail:nComponents |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4889 |
"return the last n components of myself. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4890 |
- thats the file/directory name without leading parent-dirs. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4891 |
(i.e. '/usr/lib/st/file' asFilename tail:2 -> 'st/file' |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4892 |
and '/usr/lib' asFilename tail:1 -> lib). |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4893 |
This method does not check if the path is valid. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4894 |
The code here should work for Unix and MSDOS, but needs to be redefined |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4895 |
for VMS (and maybe others as well). |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4896 |
See also: #pathName, #directoryName and #directoryPathName." |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4897 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4898 |
|sep components tail start| |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4899 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4900 |
sep := self class separator. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4901 |
components := self components. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4902 |
start := components size - nComponents + 1. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4903 |
start < 1 ifTrue:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4904 |
start := 1. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4905 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4906 |
start = 1 ifTrue:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4907 |
tail := '' |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4908 |
] ifFalse:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4909 |
tail := components at:start. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4910 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4911 |
start+1 to:components size do:[:i| |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4912 |
tail := tail, sep, (components at:i). |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4913 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4914 |
^ tail. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4915 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4916 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4917 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4918 |
'/foo/bar' asFilename tail:1 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4919 |
'/foo/bar' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4920 |
'/foo/bar' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4921 |
'/foo/bar.cc' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4922 |
'.' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4923 |
'..' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4924 |
'../..' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4925 |
'../../libbasic' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4926 |
'../../libbasic' asFilename asCanonicalizedFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4927 |
'../../libpr' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4928 |
'../../libbasic/Object.st' asFilename asCanonicalizedFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4929 |
'/' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4930 |
'\' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4931 |
'c:\' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4932 |
'\\idefix' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4933 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4934 |
! |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
4935 |
|
2629 | 4936 |
volume |
4937 |
"return the disc volume part of the name or an empty string. |
|
2906 | 4938 |
This is only used with MSDOS and VMS filenames |
4939 |
- by default (and on unix), an empty string is returned" |
|
4940 |
||
2629 | 4941 |
^ '' |
2906 | 4942 |
|
4943 |
"Modified: 8.9.1997 / 00:37:33 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4944 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4945 |
|
7120 | 4946 |
!Filename methodsFor:'queries-type'! |
4947 |
||
4948 |
isDirectory |
|
4949 |
"return true, if the receiver represents an existing, |
|
4950 |
readable directories pathname." |
|
4951 |
||
4952 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
|
4953 |
||
4954 |
" |
|
4955 |
'/foo/bar' asFilename isDirectory |
|
4956 |
'/tmp' asFilename isDirectory |
|
4957 |
'Makefile' asFilename isDirectory |
|
4958 |
'c:\' asFilename isDirectory |
|
4959 |
'd:\' asFilename isDirectory |
|
4960 |
" |
|
4961 |
||
4962 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
4963 |
! |
|
4964 |
||
4965 |
isNonEmptyDirectory |
|
4966 |
"return true, if the receiver represents an existing, |
|
4967 |
readable directories pathname, and the directory is not empty." |
|
4968 |
||
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4969 |
FileStream openErrorSignal |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4970 |
handle:[:ex ] |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4971 |
do:[ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4972 |
self directoryContentsDo:[:pathString|^ true]. |
7120 | 4973 |
]. |
4974 |
^ false. |
|
4975 |
||
4976 |
" |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
4977 |
'/foo/bar' asFilename isNonEmptyDirectory |
7120 | 4978 |
'/tmp' asFilename isNonEmptyDirectory |
4979 |
'/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory. |
|
4980 |
'/tmp/empty' asFilename removeDirectory. |
|
4981 |
'Makefile' asFilename isNonEmptyDirectory |
|
4982 |
'c:\' asFilename isNonEmptyDirectory |
|
4983 |
'd:\' asFilename isNonEmptyDirectory |
|
4984 |
" |
|
4985 |
||
4986 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
4987 |
! |
|
4988 |
||
8836 | 4989 |
isRegularFile |
4990 |
"return true, if the receiver represents a plain, regular file" |
|
4991 |
||
4992 |
^ self type == #regular |
|
4993 |
||
4994 |
" |
|
4995 |
'/foo/bar' asFilename isRegularFile |
|
4996 |
'/tmp' asFilename isRegularFile |
|
4997 |
'Makefile' asFilename isRegularFile |
|
4998 |
'c:\' asFilename isRegularFile |
|
4999 |
'd:\' asFilename isRegularFile |
|
5000 |
'/dev/null' asFilename isRegularFile |
|
5001 |
" |
|
5002 |
! |
|
5003 |
||
7120 | 5004 |
isSpecialFile |
5005 |
"return true, if the receiver represents a socket, named pipe, fifo |
|
5006 |
or device special file (i.e. anything non regular and non-directory)" |
|
5007 |
||
5008 |
|t| |
|
5009 |
||
5010 |
t := self type. |
|
5011 |
^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]]) |
|
5012 |
||
5013 |
" |
|
5014 |
'/foo/bar' asFilename isSpecialFile |
|
5015 |
'/tmp' asFilename isSpecialFile |
|
5016 |
'Makefile' asFilename isSpecialFile |
|
5017 |
'c:\' asFilename isSpecialFile |
|
5018 |
'd:\' asFilename isSpecialFile |
|
5019 |
'/dev/null' asFilename isSpecialFile |
|
5020 |
" |
|
5021 |
! |
|
5022 |
||
5023 |
isSymbolicLink |
|
5024 |
"return true, if the file represented by the receiver is a symbolic |
|
5025 |
link. Notice that not all OS's support symbolic links; those that do |
|
5026 |
not will always return false." |
|
5027 |
||
5028 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
|
5029 |
||
5030 |
" |
|
5031 |
'Make.proto' asFilename isSymbolicLink |
|
5032 |
'Makefile' asFilename isSymbolicLink |
|
5033 |
" |
|
5034 |
! ! |
|
5035 |
||
6529 | 5036 |
!Filename methodsFor:'reading-directories'! |
5037 |
||
5038 |
directoryContents |
|
5039 |
"return the contents of the directory as a collection of strings. |
|
5040 |
This excludes any entries for '.' or '..'. |
|
5041 |
Returns nil for non-existing directories; however, this behavior |
|
5042 |
may be changed in the near future, to raise an exception instead. |
|
5043 |
So users of this method better test for existing directory before. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5044 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5045 |
this returns the file-names as strings; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5046 |
see also #directoryContentsAsFilenames, which returns fileName instances." |
6529 | 5047 |
|
5048 |
|s contents| |
|
5049 |
||
5050 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
|
5051 |
s isNil ifTrue:[^nil]. |
|
5052 |
||
5053 |
[ |
|
5054 |
contents := s contents. |
|
5055 |
] ensure:[ |
|
5056 |
s close |
|
5057 |
]. |
|
5058 |
||
5059 |
contents remove:'.' ifAbsent:nil. |
|
5060 |
contents remove:'..' ifAbsent:nil. |
|
5061 |
^ contents. |
|
5062 |
||
5063 |
" |
|
5064 |
'.' asFilename directoryContents |
|
5065 |
'/XXXdoesNotExist' asFilename directoryContents |
|
5066 |
" |
|
5067 |
||
5068 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
5069 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
|
5070 |
! |
|
5071 |
||
5072 |
directoryContentsAsFilenames |
|
5073 |
"return the contents of the directory as a collection of filenames. |
|
5074 |
This excludes any entries for '.' or '..'. |
|
5075 |
Returns nil for non-existing directories; however, this behavior |
|
5076 |
may be changed in the near future, to raise an exception instead. |
|
5077 |
So users of this method better test for existing directory before. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5078 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5079 |
this returns the file-names as fileName instances; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5080 |
see also #directoryContents, which returns strings." |
6529 | 5081 |
|
5082 |
|names| |
|
5083 |
||
5084 |
names := self directoryContents. |
|
5085 |
names isNil ifTrue:[^ nil]. |
|
5086 |
^ names asOrderedCollection collect:[:entry | self construct:entry]. |
|
5087 |
||
5088 |
" |
|
5089 |
'.' asFilename directoryContentsAsFilenames |
|
5090 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
|
5091 |
" |
|
5092 |
! |
|
5093 |
||
5094 |
fullDirectoryContents |
|
5095 |
"return the full contents of the directory as a collection of strings. |
|
5096 |
This is much like #directoryContents, but includes an entry for the |
|
5097 |
parent directory, if there is one. |
|
5098 |
Returns nil for non-existing directories; however, this behavior |
|
5099 |
may be changed in the near future, to raise an exception instead. |
|
5100 |
So users of this method better test for existing directory before." |
|
5101 |
||
5102 |
|files| |
|
5103 |
||
5104 |
files := self directoryContents. |
|
5105 |
files isNil ifTrue:[ |
|
9453 | 5106 |
"/ mhmh - that one does not exist |
5107 |
^ files |
|
6529 | 5108 |
]. |
5109 |
||
5110 |
"/ add/remove parentDirectory if there is one/none |
|
5111 |
||
5112 |
files remove:'.' ifAbsent:nil. |
|
5113 |
self isRootDirectory ifTrue:[ |
|
9453 | 5114 |
files remove:'..' ifAbsent:nil. |
6529 | 5115 |
] ifFalse:[ |
9453 | 5116 |
(files includes:'..') ifFalse:[ |
5117 |
files addFirst:'..'. |
|
5118 |
] |
|
6529 | 5119 |
]. |
5120 |
^ files |
|
5121 |
||
5122 |
" |
|
5123 |
'.' asFilename fullDirectoryContents |
|
5124 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
5125 |
'd:\FET' asFilename fullDirectoryContents |
|
5126 |
" |
|
5127 |
||
5128 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
|
5129 |
! |
|
5130 |
||
5131 |
recursiveDirectoryContents |
|
5132 |
"return the contents of the directory and all subdirectories |
|
5133 |
as a collection of strings. |
|
5134 |
This excludes any entries for '.' or '..'. |
|
5135 |
Subdirectory files are included with a relative pathname. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5136 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5137 |
this returns the file-names as strings; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5138 |
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5139 |
|
6529 | 5140 |
Warning: this may take a long time to execute." |
5141 |
||
5142 |
|fileNames dirNames| |
|
5143 |
||
5144 |
fileNames := OrderedCollection new. |
|
5145 |
dirNames := OrderedCollection new. |
|
5146 |
self directoryContents do:[:f | |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5147 |
(self construct:f) isDirectory ifTrue:[ |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5148 |
dirNames add:f |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5149 |
] ifFalse:[ |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5150 |
fileNames add:f |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5151 |
] |
6529 | 5152 |
]. |
5153 |
||
5154 |
dirNames do:[:dN | |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5155 |
|dd subFiles| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5156 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5157 |
dd := dN asFilename. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5158 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5159 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
6529 | 5160 |
]. |
5161 |
^ fileNames. |
|
5162 |
||
5163 |
" |
|
5164 |
'.' asFilename recursiveDirectoryContents |
|
5165 |
'../../clients' asFilename recursiveDirectoryContents |
|
5166 |
" |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5167 |
! |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5168 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5169 |
recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5170 |
"return the contents of the directory and all subdirectories |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5171 |
as a collection of filenames. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5172 |
This excludes any entries for '.' or '..'. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5173 |
Returns nil for non-existing directories; however, this behavior |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5174 |
may be changed in the near future, to raise an exception instead. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5175 |
So users of this method better test for existing directory before. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5176 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5177 |
this returns the file-names as fileName instances; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5178 |
see also #recursiveDirectoryContents, which returns strings. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5179 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5180 |
Warning: this may take a long time to execute." |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5181 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5182 |
|names| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5183 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5184 |
names := self recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5185 |
names isNil ifTrue:[^ nil]. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5186 |
^ names asOrderedCollection collect:[:entry | self construct:entry]. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5187 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5188 |
" |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5189 |
'.' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5190 |
'/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5191 |
" |
6529 | 5192 |
! ! |
5193 |
||
5194 |
!Filename methodsFor:'reading-files'! |
|
5195 |
||
5196 |
binaryContentsOfEntireFile |
|
5197 |
"return the binary contents of the file (as a byteArray); |
|
7680 | 5198 |
Raises an error, if the file is unreadable/non-existing." |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5199 |
|
7680 | 5200 |
^ self |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5201 |
readingFileDo:[:s | |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5202 |
|nBytes bytes n| |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5203 |
|
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5204 |
s binary. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5205 |
nBytes := self fileSize. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5206 |
(nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5207 |
bytes := ByteArray uninitializedNew:nBytes. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5208 |
n := s |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5209 |
nextBytes:nBytes |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5210 |
into:bytes |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5211 |
startingAt:1. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5212 |
n == nBytes ifTrue:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5213 |
bytes |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5214 |
] ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5215 |
bytes copyTo:n |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5216 |
] |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5217 |
] ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5218 |
s contentsOfEntireFile |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5219 |
] |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5220 |
] |
6529 | 5221 |
|
5222 |
" |
|
5223 |
'Makefile' asFilename binaryContentsOfEntireFile |
|
5224 |
'foobar' asFilename binaryContentsOfEntireFile |
|
5225 |
" |
|
5226 |
! |
|
5227 |
||
5228 |
contents |
|
5229 |
"return the contents of the file as a collection of lines; |
|
7680 | 5230 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 5231 |
See also #contentsOfEntireFile, which returns a string for textFiles. |
5232 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
5233 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5234 |
^ self readingFileDo:[:s | s contents]. |
6529 | 5235 |
|
5236 |
" |
|
5237 |
'Makefile' asFilename contents |
|
5238 |
'foobar' asFilename contents |
|
5239 |
" |
|
5240 |
||
5241 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
5242 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
5243 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
5244 |
! |
|
5245 |
||
10780 | 5246 |
contentsAsString |
5247 |
"to compensate for the bad naming, use this to make things explicit. |
|
5248 |
See also #contents, which returns the lines as stringCollection for textFiles." |
|
5249 |
||
11397
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5250 |
^ self contentsOfEntireFile |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5251 |
|
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5252 |
" |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5253 |
'Makefile' asFilename contentsAsString |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5254 |
'foobar' asFilename contentsAsString |
10780 | 5255 |
" |
5256 |
||
5257 |
"Modified: / 02-07-1996 / 12:49:45 / stefan" |
|
5258 |
"Created: / 08-11-2007 / 13:29:59 / cg" |
|
5259 |
! |
|
5260 |
||
6529 | 5261 |
contentsOfEntireFile |
5262 |
"return the contents of the file as a string; |
|
7680 | 5263 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 5264 |
See also #contents, which returns the lines as stringCollection for textFiles. |
5265 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
5266 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5267 |
^ self readingFileDo:[:s | s contentsOfEntireFile]. |
6529 | 5268 |
|
5269 |
" |
|
5270 |
'Makefile' asFilename contentsOfEntireFile |
|
5271 |
'foobar' asFilename contentsOfEntireFile |
|
5272 |
" |
|
5273 |
||
5274 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
5275 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
5276 |
! |
|
5277 |
||
5278 |
readingFileDo:aBlock |
|
5279 |
"create a read-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
5280 |
and return the blocks value. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5281 |
If the file cannot be opened, an exception is raised or |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5282 |
(old behavior, will vanish:)the block is evaluated with a nil argument. |
6529 | 5283 |
Ensures that the stream is closed." |
5284 |
||
5285 |
|stream result| |
|
5286 |
||
5287 |
stream := self readStream. |
|
5288 |
[ |
|
5289 |
result := aBlock value:stream |
|
5290 |
] ensure:[ |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5291 |
stream close |
6529 | 5292 |
]. |
5293 |
^ result |
|
5294 |
||
5295 |
" |
|
5296 |
read the first line from some file: |
|
5297 |
||
5298 |
|rslt| |
|
5299 |
||
5300 |
rslt := |
|
5301 |
'/etc/passwd' asFilename |
|
5302 |
readingFileDo:[:s | |
|
5303 |
s nextLine |
|
5304 |
]. |
|
5305 |
Transcript showCR:rslt. |
|
5306 |
" |
|
5307 |
||
5308 |
" |
|
5309 |
find all used shells in /etc/passwd and count their usage: |
|
5310 |
||
5311 |
|rslt| |
|
5312 |
||
5313 |
rslt := |
|
5314 |
'/etc/passwd' asFilename |
|
5315 |
readingFileDo: |
|
5316 |
[:s | |
|
5317 |
|shells| |
|
5318 |
||
5319 |
shells := Bag new. |
|
5320 |
s linesDo: |
|
5321 |
[:line | |
|
5322 |
|parts| |
|
5323 |
||
5324 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
5325 |
shells add:(parts seventh). |
|
5326 |
]. |
|
5327 |
shells contents |
|
5328 |
]. |
|
5329 |
Transcript showCR:rslt. |
|
5330 |
" |
|
6771 | 5331 |
! |
5332 |
||
5333 |
readingLinesDo:aBlock |
|
5334 |
"create a read-stream on the receiver file, |
|
5335 |
evaluate aBlock for each line read from the stream. |
|
5336 |
If the file cannot be opened, an error is raised. |
|
5337 |
Ensures that the stream is closed." |
|
5338 |
||
5339 |
self readingFileDo:[:stream | |
|
5340 |
stream linesDo:aBlock |
|
5341 |
]. |
|
5342 |
||
5343 |
" |
|
5344 |
'/etc/passwd' asFilename |
|
5345 |
readingLinesDo:[:eachLine | |
|
5346 |
Transcript showCR:eachLine. |
|
5347 |
]. |
|
5348 |
" |
|
5349 |
||
5350 |
" |
|
5351 |
'/etc/xxxxx' asFilename |
|
5352 |
readingLinesDo:[:eachLine | |
|
5353 |
Transcript showCR:eachLine. |
|
5354 |
]. |
|
5355 |
" |
|
6529 | 5356 |
! ! |
5357 |
||
2922 | 5358 |
!Filename methodsFor:'special accessing'! |
5359 |
||
5360 |
osName |
|
5361 |
"special - return the OS's name for the receiver." |
|
5362 |
||
5363 |
self isDirectory ifTrue:[ |
|
9453 | 5364 |
^ self osNameForDirectory |
2922 | 5365 |
]. |
5366 |
^ self osNameForFile |
|
5367 |
! |
|
5368 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5369 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5370 |
"internal - return the OS's name for the receiver to |
3665 | 5371 |
access its fileInfo. |
5372 |
This may be redefined for systems, where a special suffix must be |
|
5373 |
added in order to access directories (or others) as a file. |
|
5374 |
(i.e. under VMS, a '.dir' suffix is added to access directories)" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5375 |
|
7064 | 5376 |
^ self osNameForFile |
3665 | 5377 |
|
5378 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5379 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5380 |
|
2922 | 5381 |
osNameForDirectory |
3753 | 5382 |
"internal - return the OS's name for the receiver to |
2922 | 5383 |
access it as a directory." |
5384 |
||
5385 |
^ nameString |
|
3753 | 5386 |
|
5387 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 5388 |
! |
5389 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5390 |
osNameForDirectoryContents |
3753 | 5391 |
"internal - return the OS's name for the receiver to |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5392 |
access it as a directory when reading its contents." |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5393 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5394 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5395 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5396 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 5397 |
"Modified: / 12.8.1998 / 14:44:34 / cg" |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5398 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5399 |
|
2922 | 5400 |
osNameForFile |
5401 |
"internal - return the OS's name for the receiver to |
|
5402 |
access it as a file." |
|
5403 |
||
5404 |
^ nameString |
|
5405 |
! ! |
|
5406 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5407 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5408 |
|
11748 | 5409 |
addSuffix:aSuffix |
5410 |
"return a new filename for the receivers name with a different suffix. |
|
5411 |
If the name already has a suffix, the new suffix replaces it; |
|
5412 |
otherwise, the new suffix is simply appended to the name." |
|
5413 |
||
5414 |
|prefixName| |
|
5415 |
||
5416 |
prefixName := self name. |
|
5417 |
aSuffix isEmptyOrNil ifTrue:[ |
|
5418 |
^ self class named:prefixName |
|
5419 |
]. |
|
5420 |
||
5421 |
^ self class named: |
|
5422 |
(prefixName |
|
5423 |
, self class suffixSeparator asString |
|
5424 |
, aSuffix asString) |
|
5425 |
||
5426 |
" |
|
5427 |
'abc.st' asFilename addSuffix:nil |
|
5428 |
'a.b.c' asFilename addSuffix:nil |
|
5429 |
'.b.c.' asFilename addSuffix:nil |
|
5430 |
'.b.c' asFilename addSuffix:nil |
|
5431 |
'.c.' asFilename addSuffix:nil |
|
5432 |
'.c' asFilename addSuffix:nil |
|
5433 |
'c.' asFilename addSuffix:nil |
|
5434 |
'.' asFilename addSuffix:nil |
|
5435 |
||
5436 |
'abc.st' asFilename addSuffix:'o' |
|
5437 |
'abc' asFilename addSuffix:'o' |
|
5438 |
'a.b.c' asFilename addSuffix:'o' |
|
5439 |
'a.b.c.' asFilename addSuffix:'o' |
|
5440 |
'.b.c.' asFilename addSuffix:'o' |
|
5441 |
'.c.' asFilename addSuffix:'o' |
|
5442 |
'.c' asFilename addSuffix:'o' |
|
5443 |
'c.' asFilename addSuffix:'o' |
|
5444 |
'.' asFilename addSuffix:'o' |
|
5445 |
'/foo/bar/baz.st' asFilename addSuffix:'c' |
|
5446 |
'/foo/bar/baz.c' asFilename addSuffix:'st' |
|
5447 |
'/foo/bar.c/baz.c' asFilename addSuffix:'st' |
|
5448 |
'/foo/bar.c/baz' asFilename addSuffix:'st' |
|
5449 |
" |
|
5450 |
! |
|
5451 |
||
2906 | 5452 |
hasSuffix:aSuffixString |
5453 |
"return true if my suffix is the same as aString. |
|
5454 |
This cares for systems, where case is ignored in filenames" |
|
5455 |
||
5456 |
|mySuffix| |
|
5457 |
||
5458 |
mySuffix := self suffix. |
|
5459 |
self class isCaseSensitive ifTrue:[ |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5460 |
^ mySuffix = aSuffixString |
2906 | 5461 |
]. |
5462 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
5463 |
||
5464 |
" |
|
5465 |
'abc.st' asFilename hasSuffix:'st' |
|
5466 |
'abc.ST' asFilename hasSuffix:'st' |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5467 |
'.ST' asFilename hasSuffix:'st' -- false expected here |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5468 |
'.foorc' asFilename hasSuffix:'foorc' -- false expected here |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5469 |
'.foorc.sav' asFilename hasSuffix:'sav' |
2906 | 5470 |
" |
5471 |
||
5472 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
5473 |
! |
|
5474 |
||
10155 | 5475 |
nameWithoutSuffix |
5476 |
"return the receivers name without the suffix. |
|
5477 |
If the name has no suffix, the original name is returned." |
|
5478 |
||
5479 |
|nm idx idxFromEnd| |
|
5480 |
||
5481 |
nm := self baseName. |
|
5482 |
idx := nm lastIndexOf:(self class suffixSeparator). |
|
5483 |
(idx == 0) ifTrue:[^ nameString]. |
|
5484 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
|
5485 |
"/ the suffix is considered empty. |
|
5486 |
(idx == 1) ifTrue:[^ nameString]. |
|
5487 |
||
5488 |
idxFromEnd := nm size - idx. |
|
5489 |
idx := nameString size - idxFromEnd. |
|
5490 |
||
5491 |
^ nameString copyTo:(idx - 1) |
|
5492 |
||
5493 |
" |
|
5494 |
'abc.st' asFilename nameWithoutSuffix |
|
5495 |
'abc' asFilename nameWithoutSuffix |
|
5496 |
'/abc' asFilename nameWithoutSuffix |
|
5497 |
'/abc.d' asFilename nameWithoutSuffix |
|
5498 |
'./abc' asFilename nameWithoutSuffix |
|
5499 |
'./abc.d' asFilename nameWithoutSuffix |
|
5500 |
'./.abc' asFilename nameWithoutSuffix |
|
5501 |
'a.b.c' asFilename nameWithoutSuffix |
|
5502 |
'a.b.' asFilename nameWithoutSuffix |
|
5503 |
'.b.c' asFilename nameWithoutSuffix |
|
5504 |
'.b.' asFilename nameWithoutSuffix |
|
5505 |
'.b' asFilename nameWithoutSuffix |
|
5506 |
'/foo/bar/baz.c' asFilename nameWithoutSuffix |
|
5507 |
'/foo/bar.x/baz.c' asFilename nameWithoutSuffix |
|
5508 |
'/foo/bar.x/baz' asFilename nameWithoutSuffix |
|
5509 |
'/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix |
|
5510 |
'/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix |
|
5511 |
" |
|
5512 |
||
5513 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
|
5514 |
"Created: / 07-11-2006 / 13:55:18 / cg" |
|
5515 |
! |
|
5516 |
||
9453 | 5517 |
prefix |
5518 |
"return my prefix. |
|
5519 |
The suffix is the namepart after the final period character, |
|
5520 |
or the empty string, if the name does not contain a period." |
|
5521 |
||
5522 |
^ self prefixAndSuffix at:1 |
|
5523 |
||
5524 |
" |
|
5525 |
'abc.st' asFilename prefix |
|
5526 |
'abc' asFilename prefix |
|
5527 |
'a.b.c' asFilename prefix |
|
5528 |
'a.b.c' asFilename prefix |
|
5529 |
'a.' asFilename prefix |
|
5530 |
'.a' asFilename prefix |
|
5531 |
" |
|
5532 |
||
5533 |
"Modified: / 07-09-1995 / 11:09:03 / claus" |
|
5534 |
"Created: / 13-07-2006 / 10:27:19 / fm" |
|
5535 |
! |
|
5536 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5537 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5538 |
"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
|
5539 |
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
|
5540 |
the prefix everything before, except for the period. |
1517 | 5541 |
The directory name part is stripped off (i.e. the returned prefix |
5542 |
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
|
5543 |
(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
|
5544 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5545 |
An exception to the above: if the name starts with the suffixCharacter, |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5546 |
that part is NOT considered a suffix. Thus, '.foorc' has no suffix and a prefix of |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5547 |
'.foorc'. |
1517 | 5548 |
See also: #withoutSuffix and #withSuffix |
5549 |
Notice: |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5550 |
there is currently no known system which uses other than |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5551 |
the period character as suffixCharacter." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5552 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5553 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5554 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5555 |
nm := self baseName. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5556 |
idx := nm lastIndexOf:(self class suffixSeparator). |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5557 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5558 |
"/ the suffix is considered empty. |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5559 |
((idx == 1) or:[ idx == 0 ]) ifTrue:[ |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5560 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5561 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5562 |
^ Array |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5563 |
with:(nm copyTo:idx-1) |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5564 |
with:(nm copyFrom:idx+1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5565 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5566 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5567 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5568 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5569 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 5570 |
'/foo/bar.c/baz.c' asFilename prefixAndSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5571 |
'a.' asFilename prefixAndSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5572 |
'.a' asFilename prefixAndSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5573 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5574 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5575 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 5576 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5577 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5578 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5579 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 5580 |
"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
|
5581 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5582 |
|
2906 | 5583 |
suffix |
5584 |
"return my suffix. |
|
5585 |
The suffix is the namepart after the final period character, |
|
5586 |
or the empty string, if the name does not contain a period." |
|
5587 |
||
5588 |
^ self prefixAndSuffix at:2 |
|
5589 |
||
5590 |
" |
|
5591 |
'abc.st' asFilename suffix |
|
5592 |
'abc' asFilename suffix |
|
5593 |
'a.b.c' asFilename suffix |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5594 |
'a.b.c' asFilename suffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5595 |
'a.' asFilename suffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5596 |
'.a' asFilename suffix |
2906 | 5597 |
" |
5598 |
||
5599 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
5600 |
! |
|
5601 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5602 |
withSuffix:aSuffix |
2922 | 5603 |
"return a new filename for the receivers name with a different suffix. |
6256 | 5604 |
If the name already has a suffix, the new suffix replaces it; |
1993 | 5605 |
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
|
5606 |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5607 |
|prefixName| |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5608 |
|
10155 | 5609 |
prefixName := self nameWithoutSuffix. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5610 |
aSuffix isEmptyOrNil ifTrue:[ |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5611 |
^ self class named:prefixName |
6262 | 5612 |
]. |
5613 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5614 |
^ self class named: |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5615 |
(prefixName |
6256 | 5616 |
, self class suffixSeparator asString |
5617 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5618 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5619 |
" |
6262 | 5620 |
'abc.st' asFilename withSuffix:nil |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5621 |
'a.b.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5622 |
'.b.c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5623 |
'.b.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5624 |
'.c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5625 |
'.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5626 |
'c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5627 |
'.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5628 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5629 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5630 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5631 |
'a.b.c' asFilename withSuffix:'o' |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5632 |
'a.b.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5633 |
'.b.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5634 |
'.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5635 |
'.c' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5636 |
'c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5637 |
'.' asFilename withSuffix:'o' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5638 |
'/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
|
5639 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 5640 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 5641 |
'/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
|
5642 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5643 |
|
10155 | 5644 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
5645 |
"Modified: / 07-11-2006 / 13:58:45 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5646 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5647 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5648 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5649 |
"return a new filename for the receivers name without the suffix. |
10155 | 5650 |
If the name has no suffix, a filename representing the same file as the receiver is returned." |
5651 |
||
5652 |
|n| |
|
5653 |
||
5654 |
n := self nameWithoutSuffix. |
|
5655 |
n = nameString ifTrue:[^ self]. |
|
5656 |
^ self class named:n |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5657 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5658 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5659 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5660 |
'abc' asFilename withoutSuffix |
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
5661 |
'/abc' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
5662 |
'/abc.d' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
5663 |
'./abc' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
5664 |
'./abc.d' asFilename withoutSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5665 |
'./.abc' asFilename withoutSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5666 |
'a.b.c' asFilename withoutSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5667 |
'a.b.' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5668 |
'.b.c' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5669 |
'.b.' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5670 |
'.b' asFilename withoutSuffix |
1516 | 5671 |
'/foo/bar/baz.c' asFilename withoutSuffix |
3958
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
5672 |
'/foo/bar.x/baz.c' asFilename withoutSuffix |
e5e1b16f33b6
fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents:
3954
diff
changeset
|
5673 |
'/foo/bar.x/baz' asFilename withoutSuffix |
1516 | 5674 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
5675 |
'/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
|
5676 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5677 |
|
10155 | 5678 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
5679 |
"Modified: / 07-11-2006 / 13:57:45 / cg" |
|
174 | 5680 |
! ! |
5681 |
||
5597 | 5682 |
!Filename methodsFor:'testing'! |
5683 |
||
5684 |
isFilename |
|
5685 |
"return true, if the receiver is some kind of filename; |
|
5686 |
false is returned here - the method is redefined from Object." |
|
5687 |
||
5688 |
^true |
|
5689 |
||
5690 |
||
5691 |
! ! |
|
5692 |
||
10271 | 5693 |
!Filename methodsFor:'writing-files'! |
5694 |
||
10779 | 5695 |
contents:aStringOrCollectionOfLines |
10271 | 5696 |
"create (or overwrite) a file given its contents as a collection of lines. |
5697 |
Raises an error, if the file is unwritable." |
|
5698 |
||
10779 | 5699 |
^ self |
5700 |
writingFileDo:[:s | |
|
11748 | 5701 |
aStringOrCollectionOfLines isNonByteCollection ifTrue:[ |
5702 |
"a StringCollection or a collection of lines" |
|
5703 |
aStringOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')] |
|
5704 |
] ifFalse:[ |
|
5705 |
"something string-like" |
|
11877 | 5706 |
aStringOrCollectionOfLines isString ifFalse:[ |
5707 |
s binary |
|
5708 |
]. |
|
10779 | 5709 |
s nextPutAll:aStringOrCollectionOfLines |
5710 |
] |
|
5711 |
]. |
|
5712 |
||
5713 |
" |
|
5714 |
'foo1' asFilename contents:#('one' 'two' 'three') |
|
5715 |
'foo2' asFilename contents:'Hello world' |
|
10271 | 5716 |
" |
5717 |
||
5718 |
"Created: / 11-12-2006 / 14:11:21 / cg" |
|
10779 | 5719 |
"Modified: / 08-11-2007 / 13:28:41 / cg" |
10271 | 5720 |
! |
5721 |
||
5722 |
writingFileDo:aBlock |
|
5723 |
"create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
5724 |
and return the blocks value. |
|
5725 |
If the file cannot be opened, an exception is raised. |
|
5726 |
Ensures that the stream is closed." |
|
5727 |
||
5728 |
|stream result| |
|
5729 |
||
5730 |
stream := self writeStream. |
|
5731 |
[ |
|
5732 |
result := aBlock value:stream |
|
5733 |
] ensure:[ |
|
5734 |
stream close |
|
5735 |
]. |
|
5736 |
^ result |
|
5737 |
||
5738 |
" |
|
5739 |
'ttt' asFilename writingFileDo:[:s | |
|
5740 |
s nextPutLine:'hello'. |
|
5741 |
s nextPutLine:'world'. |
|
5742 |
] |
|
5743 |
" |
|
5744 |
||
5745 |
"Created: / 11-12-2006 / 14:09:39 / cg" |
|
5746 |
! ! |
|
5747 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
5748 |
!Filename class methodsFor:'documentation'! |
630 | 5749 |
|
5750 |
version |
|
12388 | 5751 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.346 2009-10-28 13:59:52 cg Exp $' |
12318 | 5752 |
! |
5753 |
||
5754 |
version_CVS |
|
12388 | 5755 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.346 2009-10-28 13:59:52 cg Exp $' |
630 | 5756 |
! ! |
6771 | 5757 |
|
2906 | 5758 |
Filename initialize! |