author | Claus Gittinger <cg@exept.de> |
Sun, 23 Nov 2014 17:51:36 +0100 | |
changeset 17113 | a521179b677c |
parent 17112 | b9ec1d0b917a |
child 17143 | 5b1217eaafa7 |
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 |
14567 | 15 |
instanceVariableNames:'nameString' |
15459 | 16 |
classVariableNames:'TempDirectory DefaultTempDirectory ConcreteClass' |
14567 | 17 |
poolDictionaries:'' |
18 |
category:'System-Support' |
|
615 | 19 |
! |
1 | 20 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
21 |
!Filename class methodsFor:'documentation'! |
88 | 22 |
|
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
9453 | 26 |
All Rights Reserved |
1 | 27 |
|
88 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
Filenames; originally added for ST-80 compatibility, is |
|
40 |
taking over functionality from other classes (FileDirectory). |
|
92 | 41 |
|
42 |
Instances of Filename do not nescessarily represent valid or existing |
|
43 |
files - i.e. it is possible (and useful) to have instances for non-existing |
|
44 |
files around. In other words: the name-string is not checked automatically |
|
45 |
for being correct or existing. |
|
46 |
Thus, it is possible to do queries such as: |
|
47 |
||
8738 | 48 |
'/fee/foo/foe' asFilename exists |
49 |
'/not_existing' asFilename isDirectory |
|
50 |
'/foo/bar' asFilename isReadable |
|
92 | 51 |
|
195 | 52 |
(all of the above examples will probably return false on your machine ;-). |
276 | 53 |
|
54 |
examples: |
|
55 |
||
8738 | 56 |
'Makefile' asFilename readStream |
57 |
||
58 |
'newFile' asFilename writeStream |
|
59 |
||
60 |
Filename newTemporary writeStream |
|
276 | 61 |
|
1318 | 62 |
Beside lots of protocol to query for a files attributes, the class |
63 |
protocol offers methods for filename completion, to construct pathes |
|
64 |
(in an OS-independent way) and to create temporary files. |
|
2911 | 65 |
Especially the path-construction methods (i.e. #construct:) are highly |
1318 | 66 |
recommended in order to avoid having OS details (like directory separators |
67 |
being slash or backslash) spreaded in your application. |
|
68 |
||
8738 | 69 |
Since Filenames have different semantics under different operating systems, |
70 |
class methods are delegated to concrete implementations in various subclasses like |
|
71 |
UnixFilename, PCFilename, ... |
|
72 |
The delegation is implemented in a way, so that some methods of |
|
73 |
specific OS Filenames might be used, even if ST/X is currently running |
|
74 |
on a different OS (as long as the method does not depend on the OperatingSystem class). |
|
75 |
||
1286 | 76 |
[author:] |
8738 | 77 |
Claus Gittinger |
276 | 78 |
|
1286 | 79 |
[see also:] |
8738 | 80 |
String |
81 |
FileStream DirectoryStream PipeStream Socket |
|
82 |
OperatingSystem |
|
83 |
Date Time |
|
88 | 84 |
" |
360 | 85 |
! |
86 |
||
87 |
examples |
|
88 |
" |
|
89 |
does a file/directory exist ?: |
|
9453 | 90 |
[exBegin] |
91 |
|f| |
|
92 |
||
93 |
f := 'foobar' asFilename. |
|
94 |
^ f exists |
|
95 |
[exEnd] |
|
360 | 96 |
|
97 |
||
98 |
is it a directory ?: |
|
9453 | 99 |
[exBegin] |
100 |
|f| |
|
101 |
||
102 |
f := '/tmp' asFilename. |
|
103 |
^ f isDirectory. |
|
104 |
[exEnd] |
|
360 | 105 |
|
106 |
||
107 |
get the working directory: |
|
9453 | 108 |
[exBegin] |
109 |
^ Filename defaultDirectory |
|
110 |
[exEnd] |
|
360 | 111 |
|
112 |
||
113 |
get a files full pathname |
|
114 |
(caring for relative names or symbolic links): |
|
9453 | 115 |
[exBegin] |
116 |
|f| |
|
117 |
||
118 |
f := '..' asFilename. |
|
119 |
^ f pathName |
|
120 |
[exEnd] |
|
360 | 121 |
|
122 |
||
123 |
get a directories directory: |
|
9453 | 124 |
[exBegin] |
125 |
|f| |
|
126 |
||
127 |
f := Filename defaultDirectory. |
|
128 |
^ f directory |
|
129 |
[exEnd] |
|
360 | 130 |
|
131 |
||
132 |
get a files directory: |
|
9453 | 133 |
[exBegin] |
134 |
|f| |
|
135 |
||
136 |
f := './smalltalk' asFilename. |
|
137 |
^ f directory |
|
138 |
[exEnd] |
|
360 | 139 |
|
140 |
||
141 |
getting access & modification times: |
|
9453 | 142 |
[exBegin] |
143 |
|f| |
|
144 |
||
145 |
f := '/tmp' asFilename. |
|
146 |
^ f dates |
|
147 |
[exEnd] |
|
360 | 148 |
|
149 |
access time only: |
|
9453 | 150 |
[exBegin] |
151 |
|f| |
|
152 |
||
153 |
f := '/tmp' asFilename. |
|
154 |
^ f dates at:#accessed |
|
155 |
[exEnd] |
|
360 | 156 |
|
157 |
||
158 |
getting all information on a file/directory: |
|
9453 | 159 |
[exBegin] |
160 |
|f| |
|
161 |
||
162 |
f := '/tmp' asFilename. |
|
163 |
^ f info |
|
164 |
[exEnd] |
|
360 | 165 |
|
166 |
||
167 |
getting a temporary file (unique name): |
|
9453 | 168 |
[exBegin] |
169 |
|f| |
|
170 |
||
171 |
f := Filename newTemporary. |
|
172 |
^ f |
|
173 |
[exEnd] |
|
360 | 174 |
|
175 |
creating, writing, reading and removing a temporary file: |
|
9453 | 176 |
[exBegin] |
177 |
|f writeStream readStream| |
|
178 |
||
179 |
f := Filename newTemporary. |
|
180 |
writeStream := f writeStream. |
|
181 |
writeStream nextPutAll:'hello world'. |
|
182 |
writeStream cr. |
|
183 |
writeStream close. |
|
184 |
||
185 |
'contents (as seen by unix''s cat command:' printNL. |
|
186 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
187 |
||
188 |
readStream := f readStream. |
|
189 |
Transcript showCR:'contents as seen by smalltalk:'. |
|
190 |
Transcript showCR:(readStream upToEnd). |
|
191 |
readStream close. |
|
192 |
||
193 |
f delete. |
|
194 |
[exEnd] |
|
360 | 195 |
|
196 |
||
197 |
getting a directories contents: |
|
9453 | 198 |
[exBegin] |
199 |
|f files| |
|
200 |
||
201 |
f := Filename currentDirectory. |
|
202 |
files := f directoryContents. |
|
203 |
Transcript showCR:'the files are:'. |
|
204 |
Transcript showCR:(files printString). |
|
205 |
[exEnd] |
|
360 | 206 |
|
207 |
||
208 |
editing a file: |
|
9453 | 209 |
[exBegin] |
210 |
|f| |
|
211 |
||
212 |
f := Filename newTemporary. |
|
213 |
(f writeStream) nextPutAll:'hello world'; close. |
|
214 |
||
215 |
f edit |
|
216 |
[exEnd] |
|
360 | 217 |
" |
88 | 218 |
! ! |
1 | 219 |
|
2906 | 220 |
!Filename class methodsFor:'initialization'! |
221 |
||
222 |
initialize |
|
223 |
"initialize for the OS we are running on" |
|
224 |
||
8754 | 225 |
ConcreteClass isNil ifTrue:[ |
7702 | 226 |
self initializeConcreteClass |
227 |
]. |
|
2906 | 228 |
|
229 |
" |
|
230 |
self initialize |
|
231 |
" |
|
232 |
||
233 |
"Created: 7.9.1997 / 23:32:55 / cg" |
|
234 |
! |
|
235 |
||
236 |
initializeConcreteClass |
|
237 |
"initialize for the OS we are running on" |
|
238 |
||
8754 | 239 |
OperatingSystem isUNIXlike ifTrue:[ |
240 |
ConcreteClass := UnixFilename |
|
241 |
] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[ |
|
8738 | 242 |
ConcreteClass := PCFilename |
8754 | 243 |
] ifFalse:[OperatingSystem isVMSlike ifTrue:[ |
244 |
ConcreteClass := OpenVMSFilename |
|
2906 | 245 |
] ifFalse:[ |
8754 | 246 |
self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'. |
247 |
]]]. |
|
248 |
||
249 |
ConcreteClass isNil ifTrue:[ |
|
250 |
self error:'Filename: Missing concrete Filename class'. |
|
251 |
]. |
|
252 |
||
253 |
" |
|
254 |
self initializeConcreteClass |
|
2906 | 255 |
" |
256 |
||
257 |
"Modified: 7.9.1997 / 23:32:37 / cg" |
|
258 |
! |
|
259 |
||
260 |
reinitialize |
|
8738 | 261 |
"initialize for the OS we are running on (after a restart)" |
2906 | 262 |
|
9806 | 263 |
TempDirectory := nil. |
264 |
self initializeConcreteClass. |
|
2906 | 265 |
|
266 |
" |
|
8754 | 267 |
self reinitialize |
2906 | 268 |
" |
269 |
||
9806 | 270 |
"Created: / 07-09-1997 / 23:33:02 / cg" |
271 |
"Modified: / 29-08-2006 / 12:40:28 / cg" |
|
2906 | 272 |
! ! |
273 |
||
3959 | 274 |
!Filename class methodsFor:'instance creation'! |
275 |
||
12972 | 276 |
applicationDataDirectoryFor:appName |
277 |
"return the directory, where user-and-application-specific private files are to be |
|
278 |
located (ini-files, preferences etc.). |
|
279 |
Under windows, something like 'C:\Users\Administrator\AppData\Roaming\<appName>' |
|
12973 | 280 |
is returned, under unix, we use ~/.<appName> (but see details in UnixOS). |
12974 | 281 |
If the directory does not exist, it is created" |
282 |
||
283 |
|s dir| |
|
12972 | 284 |
|
285 |
s := OperatingSystem getApplicationDataDirectoryFor:appName. |
|
286 |
s isNil ifTrue:[ |
|
287 |
^ self homeDirectory |
|
288 |
]. |
|
12974 | 289 |
dir := self named:s. |
290 |
dir exists ifFalse:[ |
|
291 |
dir makeDirectory |
|
292 |
]. |
|
293 |
^ dir |
|
12972 | 294 |
|
295 |
" |
|
296 |
Filename applicationDataDirectoryFor:'expecco' |
|
297 |
" |
|
298 |
||
299 |
"Created: / 29-07-2010 / 12:05:35 / sr" |
|
300 |
! |
|
301 |
||
3959 | 302 |
currentDirectory |
303 |
"return a filename for the current directory" |
|
304 |
||
13109 | 305 |
^ self named:(OperatingSystem getCurrentDirectory). |
3959 | 306 |
|
307 |
" |
|
308 |
Filename currentDirectory |
|
309 |
" |
|
310 |
! |
|
311 |
||
312 |
defaultDirectory |
|
313 |
"ST80 compatibility: same as currentDirectory" |
|
314 |
||
315 |
^ self currentDirectory |
|
316 |
||
317 |
" |
|
318 |
Filename defaultDirectory |
|
319 |
" |
|
320 |
! |
|
321 |
||
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
322 |
defaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
323 |
"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
|
324 |
That is the same as TempDirectory, except that TempDirectory can be changed |
17048 | 325 |
from the outside (via tempDirectory:) whereas this is the OS's original default. |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
326 |
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
|
327 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
328 |
DefaultTempDirectory isNil ifTrue:[ |
17048 | 329 |
self tempDirectory. "/ actually sets DefaultTempDirectory as side effect |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
330 |
DefaultTempDirectory isNil ifTrue:[ |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
331 |
DefaultTempDirectory := TempDirectory |
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 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
335 |
DefaultTempDirectory exists ifFalse:[ |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
336 |
DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
337 |
makeDirectory; |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
338 |
addAccessRights:#(readUser readGroup readOthers |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
339 |
writeUser writeGroup writeOthers |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
340 |
executeUser executeGroup executeOthers |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
341 |
removeOnlyByOwner). |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
342 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
343 |
^ DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
344 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
345 |
" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
346 |
Filename tempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
347 |
Filename defaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
348 |
" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
349 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
350 |
"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
|
351 |
"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
|
352 |
! |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
353 |
|
10546 | 354 |
desktopDirectory |
355 |
"return your desktop directory. |
|
356 |
Under windows, thats the real desktop directory; |
|
357 |
under other OperatingSystems, the home directory is returned." |
|
358 |
||
359 |
|s| |
|
360 |
||
361 |
s := OperatingSystem getDesktopDirectory. |
|
362 |
s isNil ifTrue:[ |
|
363 |
^ self homeDirectory |
|
364 |
]. |
|
365 |
^ self named:s |
|
366 |
||
367 |
" |
|
368 |
Filename desktopDirectory |
|
369 |
" |
|
370 |
||
371 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
372 |
! |
|
373 |
||
11763 | 374 |
documentsDirectory |
375 |
"return your documents directory. |
|
376 |
Under windows, thats the real 'Documents' or 'My Documents'; |
|
377 |
under other OperatingSystems, the home directory is returned." |
|
378 |
||
379 |
|s| |
|
380 |
||
381 |
s := OperatingSystem getDocumentsDirectory. |
|
382 |
s isNil ifTrue:[ |
|
383 |
^ self homeDirectory |
|
384 |
]. |
|
385 |
^ self named:s |
|
386 |
||
387 |
" |
|
388 |
Filename documentsDirectory |
|
389 |
" |
|
390 |
||
391 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
392 |
! |
|
393 |
||
3959 | 394 |
findDefaultDirectory |
395 |
"same as #defaultDirectory for ST80 compatibility" |
|
396 |
||
397 |
^ self defaultDirectory |
|
398 |
||
399 |
"Created: 20.6.1997 / 17:00:29 / cg" |
|
400 |
! |
|
401 |
||
402 |
fromComponents:aCollectionOfDirectoryNames |
|
403 |
"create & return a new filename from components given in |
|
404 |
aCollectionOfDirectoryNames. If the first component is the name of the |
|
405 |
root directory (i.e. '/') an absolute path-filename is returned." |
|
406 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
407 |
self isAbstract ifTrue:[ |
6802 | 408 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
3959 | 409 |
]. |
410 |
||
6802 | 411 |
^ self named:(self nameFromComponents:aCollectionOfDirectoryNames) |
3959 | 412 |
|
413 |
" |
|
414 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
|
8754 | 415 |
PCFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
416 |
UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
|
417 |
OpenVMSFilename fromComponents:#('foo' 'bar' 'baz') |
|
418 |
||
3959 | 419 |
Filename fromComponents:#('foo' 'bar' 'baz') |
420 |
Filename fromComponents:#('/') |
|
421 |
||
422 |
Filename fromComponents: |
|
6802 | 423 |
(Filename components:('.' asFilename pathName)) |
3959 | 424 |
|
425 |
Filename fromComponents: |
|
6802 | 426 |
(Filename components:('.' asFilename name)) |
3959 | 427 |
" |
428 |
||
429 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
430 |
! |
|
431 |
||
432 |
fromUser |
|
433 |
"show a box to enter a filename. |
|
434 |
Return a filename instance or nil (if cancel was pressed)." |
|
435 |
||
436 |
|name| |
|
437 |
||
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
438 |
name := Dialog |
8738 | 439 |
requestFileName:'filename:' |
440 |
default:nil |
|
441 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory). |
|
442 |
||
443 |
name notEmptyOrNil ifTrue:[ |
|
444 |
^ self named:name |
|
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
445 |
]. |
3959 | 446 |
^ nil |
447 |
||
448 |
" |
|
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
449 |
Filename fromUser |
3959 | 450 |
" |
451 |
||
452 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
|
453 |
! |
|
454 |
||
455 |
homeDirectory |
|
456 |
"return your homeDirectory. |
|
457 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
|
17113 | 458 |
(which is the currentDirectory) is returned. |
459 |
Notice: services under windows also do not have a home directory." |
|
3959 | 460 |
|
461 |
|s| |
|
462 |
||
463 |
s := OperatingSystem getHomeDirectory. |
|
464 |
s isNil ifTrue:[ |
|
9453 | 465 |
^ self defaultDirectory |
3959 | 466 |
]. |
467 |
^ self named:s |
|
468 |
||
469 |
" |
|
470 |
Filename homeDirectory |
|
471 |
" |
|
472 |
||
473 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
|
474 |
! |
|
475 |
||
476 |
named:aString |
|
477 |
"return a filename for a directory named aString. |
|
478 |
This is the same as 'aString asFilename'." |
|
479 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
480 |
self isAbstract ifTrue:[ |
8738 | 481 |
^ ConcreteClass named:aString |
3959 | 482 |
]. |
8738 | 483 |
^ self basicNew setName:aString |
3959 | 484 |
|
485 |
" |
|
486 |
Filename named:'/tmp/fooBar' |
|
487 |
" |
|
488 |
||
489 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
490 |
! |
|
491 |
||
492 |
newTemporary |
|
493 |
"return a new unique filename - use this for temporary files. |
|
494 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
495 |
unix process id, and nn is a unique number, incremented with every |
|
496 |
call to this method. |
|
497 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
4757 | 498 |
its value defines the temp directory. |
499 |
Notice, that no file is created by this - only a unique name |
|
15459 | 500 |
is generated. |
501 |
||
16787 | 502 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporary |
503 |
(the insecurity is due to a small chance for some other program to open/create |
|
504 |
the file, as only a name is generated here. However, chances are small as the name |
|
505 |
is reasonably random - but for security relevant applications, this may be relevant) |
|
506 |
" |
|
3959 | 507 |
|
9912 | 508 |
^ self newTemporaryIn:(self tempDirectory) |
3959 | 509 |
|
510 |
" |
|
511 |
Filename newTemporary |
|
512 |
Filename newTemporary |
|
513 |
" |
|
514 |
||
515 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
516 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
|
517 |
! |
|
518 |
||
9912 | 519 |
newTemporaryDirectory |
520 |
"return a new unique temporary directory - use this for temporary files. |
|
521 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
522 |
unix process id, and nn is a unique number, incremented with every |
|
523 |
call to this method. |
|
524 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
525 |
its value defines the temp directory." |
|
526 |
||
527 |
^ self newTemporaryDirectoryIn:(self tempDirectory) |
|
528 |
! |
|
529 |
||
530 |
newTemporaryDirectoryIn:aDirectoryOrNil |
|
531 |
"return a new unique temporary directory in another directory, or the current dir. |
|
532 |
Use this for temporary files. |
|
533 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
534 |
unix process id, and nn is a unique number, incremented with every |
|
535 |
call to this method. |
|
536 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
|
537 |
its value defines the temp directory." |
|
538 |
||
539 |
|tempdir| |
|
540 |
||
15811 | 541 |
tempdir := self newTemporaryIn:aDirectoryOrNil. |
9912 | 542 |
tempdir exists ifTrue:[ |
543 |
tempdir recursiveRemove. |
|
544 |
]. |
|
545 |
tempdir makeDirectory. |
|
546 |
^ tempdir |
|
547 |
! |
|
548 |
||
549 |
newTemporaryIn:aDirectoryOrNil |
|
3959 | 550 |
"return a new unique filename - use this for temporary files. |
551 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
|
552 |
where xx is our unix process id, and nn is a unique number, incremented |
|
553 |
with every call to this method. |
|
554 |
Notice: only a unique filename object is created and returned - no physical |
|
555 |
file is created by this method (i.e. you have to send #writeStream or |
|
556 |
whatever to it in order to really create something). |
|
15459 | 557 |
See also: #newTemporary which looks for a good temp directory. |
558 |
||
559 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:" |
|
3959 | 560 |
|
12617 | 561 |
^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(self tempFileNameTemplate) |
3959 | 562 |
|
563 |
"temp files in '/tmp': |
|
564 |
||
565 |
Filename newTemporary |
|
566 |
" |
|
567 |
||
568 |
"temp files somewhere |
|
569 |
(not recommended - use above since it can be controlled via shell variables): |
|
570 |
||
571 |
UnixFilename newTemporaryIn:'/tmp' |
|
572 |
UnixFilename newTemporaryIn:'/tmp' |
|
573 |
UnixFilename newTemporaryIn:'/usr/tmp' |
|
574 |
UnixFilename newTemporaryIn:'/' |
|
575 |
" |
|
576 |
||
577 |
"a local temp file: |
|
578 |
||
579 |
Filename newTemporaryIn:'' |
|
580 |
Filename newTemporaryIn:nil |
|
581 |
Filename newTemporaryIn:'.' |
|
582 |
Filename newTemporaryIn:('source' asFilename) |
|
583 |
" |
|
584 |
||
585 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
|
586 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
|
587 |
! |
|
588 |
||
9912 | 589 |
newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
590 |
"return a new unique filename - use this for temporary files. |
9912 | 591 |
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
|
592 |
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
|
593 |
with every call to this method respectively. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
594 |
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
|
595 |
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
|
596 |
whatever to it in order to really create something). |
15459 | 597 |
See also: #newTemporary which looks for a good temp directory. |
598 |
||
599 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:nameTemplate:" |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
600 |
|
8738 | 601 |
|nameString newTempFilename| |
602 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
603 |
self isAbstract ifTrue:[ |
9912 | 604 |
^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template |
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 |
|
8738 | 607 |
"although the above allows things to be redefined in concrete classes, |
608 |
the following should work on all systems ..." |
|
609 |
||
610 |
[ |
|
15459 | 611 |
"Use random numbers in order to improve the security |
612 |
by making the generated names less predictable" |
|
613 |
nameString := template bindWith:(OperatingSystem getProcessId) with:RandomGenerator new nextInteger. |
|
614 |
||
615 |
aDirectoryOrNil isNil ifTrue:[ |
|
12918
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
616 |
newTempFilename := self named:nameString |
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
617 |
] ifFalse:[ |
9912 | 618 |
newTempFilename := aDirectoryOrNil asFilename construct:nameString |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
619 |
] |
8738 | 620 |
] doWhile:[ |
621 |
"care for existing leftOver tempFiles |
|
622 |
from a previous boot of the OS |
|
623 |
i.e. my pid could be the same as when executed |
|
624 |
the last time before system reboot ...)" |
|
625 |
||
626 |
newTempFilename exists |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
627 |
]. |
8738 | 628 |
^ newTempFilename |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
629 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
630 |
"temp files in '/tmp': |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
631 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
632 |
Filename newTemporary |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
633 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
634 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
635 |
"temp files somewhere |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
636 |
(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
|
637 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
638 |
UnixFilename newTemporaryIn:'/tmp' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
639 |
UnixFilename newTemporaryIn:'/tmp' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
640 |
UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
641 |
UnixFilename newTemporaryIn:'/' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
642 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
643 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
644 |
"a local temp file: |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
645 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
646 |
Filename newTemporaryIn:'' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
647 |
Filename newTemporaryIn:nil nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
648 |
Filename newTemporaryIn:'.' nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
649 |
Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
650 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
651 |
|
12918
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
652 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
653 |
"Modified: / 07-05-2010 / 11:46:05 / cg" |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
654 |
! |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
655 |
|
4199 | 656 |
nullDevice |
657 |
"return the filename of the nullDevice (if available). |
|
658 |
returns nil, if the OperatingSystem does not support this." |
|
659 |
||
660 |
|s| |
|
661 |
||
8754 | 662 |
s := self nullFilename. |
4199 | 663 |
s isNil ifTrue:[ |
8754 | 664 |
^ nil |
4199 | 665 |
]. |
666 |
^ self named:s |
|
667 |
||
668 |
" |
|
8754 | 669 |
Filename nullDevice |
670 |
UnixFilename nullDevice |
|
671 |
PCFilename nullDevice |
|
4199 | 672 |
" |
673 |
||
674 |
"Created: / 19.5.1999 / 12:24:26 / cg" |
|
675 |
! |
|
676 |
||
6256 | 677 |
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames |
678 |
"create & return a new filename from components given in |
|
679 |
aCollectionOfDirectoryNames on a host named remoteHostString. |
|
680 |
An absolute network-filename is returned." |
|
681 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
682 |
self isAbstract ifTrue:[ |
6256 | 683 |
^ ConcreteClass remoteHost:remoteHostString |
684 |
rootComponents:aCollectionOfDirectoryNames |
|
685 |
]. |
|
686 |
||
10390 | 687 |
remoteHostString notEmptyOrNil ifTrue:[ |
688 |
self error:'remote hosts are not supported by OS' |
|
689 |
]. |
|
690 |
||
691 |
^ self rootComponents:aCollectionOfDirectoryNames |
|
692 |
||
693 |
" |
|
694 |
'file:///tmp/test' asURI asFilename |
|
695 |
" |
|
6256 | 696 |
! |
697 |
||
698 |
rootComponents:aCollectionOfDirectoryNames |
|
699 |
"create & return a new filename from components given in |
|
700 |
aCollectionOfDirectoryNames. |
|
701 |
An absolute path-filename is returned." |
|
702 |
||
703 |
|sep s| |
|
704 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
705 |
self isAbstract ifTrue:[ |
6256 | 706 |
^ ConcreteClass rootComponents:aCollectionOfDirectoryNames |
707 |
]. |
|
708 |
||
709 |
"/ fallBack - works on Unix & MSDOS |
|
710 |
||
8243 | 711 |
sep := self separatorString. |
6256 | 712 |
s := WriteStream on:''. |
713 |
aCollectionOfDirectoryNames do:[:component | |
|
714 |
component ~= sep ifTrue:[ |
|
715 |
s nextPutAll:sep; nextPutAll:component |
|
716 |
] |
|
717 |
]. |
|
718 |
s := s contents. |
|
719 |
s size == 0 ifTrue:[s := sep]. |
|
720 |
^ self named:s |
|
721 |
||
722 |
" |
|
8754 | 723 |
Filename rootComponents:#('/' 'foo' 'bar' 'baz') |
724 |
||
6256 | 725 |
Filename rootComponents:#('foo' 'bar' 'baz') |
8754 | 726 |
PCFilename rootComponents:#('foo' 'bar' 'baz') |
727 |
UnixFilename rootComponents:#('foo' 'bar' 'baz') |
|
728 |
||
6256 | 729 |
Filename rootComponents:#('/') |
730 |
||
731 |
Filename rootComponents: |
|
732 |
(Filename components:('.' asFilename pathName)) |
|
733 |
||
734 |
Filename rootComponents: |
|
735 |
(Filename components:('.' asFilename name)) |
|
736 |
" |
|
737 |
||
738 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
739 |
! |
|
740 |
||
3959 | 741 |
rootDirectory |
742 |
"return a filename for the root directory" |
|
743 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
744 |
self isAbstract ifTrue:[ |
8243 | 745 |
^ ConcreteClass rootDirectory |
3959 | 746 |
]. |
747 |
||
748 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
749 |
||
8243 | 750 |
^ self named:(self separatorString) |
3959 | 751 |
|
752 |
" |
|
753 |
Filename rootDirectory |
|
754 |
" |
|
755 |
||
756 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
757 |
! |
|
758 |
||
759 |
rootDirectoryOnVolume:aVolumeName |
|
760 |
"return a filename for the root directory on some volume" |
|
761 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
762 |
self isAbstract ifTrue:[ |
8668 | 763 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
3959 | 764 |
]. |
765 |
||
766 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
|
767 |
||
768 |
^ self rootDirectory |
|
769 |
||
770 |
" |
|
771 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
|
772 |
Filename rootDirectoryOnVolume:'d:' |
|
773 |
" |
|
774 |
||
775 |
"Modified: / 5.10.1998 / 12:45:39 / cg" |
|
776 |
! |
|
777 |
||
778 |
tempDirectory |
|
779 |
"return the temp directory as a filename. |
|
780 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
|
781 |
TMPDIR or TEMPDIR is set, its value defines the name, |
|
782 |
otherwise, '/tmp' is used. (at least on unix ...). |
|
783 |
||
784 |
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
|
785 |
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
|
786 |
TMPDIR environment variable to have her temp files somewhere else." |
3959 | 787 |
|
788 |
|tempDir| |
|
789 |
||
9806 | 790 |
TempDirectory isNil ifTrue:[ |
17048 | 791 |
tempDir := self named:(self defaultTempDirectoryName pathName). |
792 |
tempDir exists ifFalse:[ |
|
793 |
tempDir |
|
794 |
makeDirectory; |
|
795 |
addAccessRights:#(readUser readGroup readOthers |
|
796 |
writeUser writeGroup writeOthers |
|
797 |
executeUser executeGroup executeOthers |
|
798 |
removeOnlyByOwner). |
|
9806 | 799 |
]. |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
800 |
TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'. |
3959 | 801 |
]. |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
802 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
803 |
"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
|
804 |
by a cleanup (cron) job. |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
805 |
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
|
806 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
807 |
TempDirectory exists ifFalse:[ |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
808 |
TempDirectory |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
809 |
makeDirectory; |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
810 |
addAccessRights:#(readUser readGroup readOthers |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
811 |
writeUser writeGroup writeOthers |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
812 |
executeUser executeGroup executeOthers |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
813 |
removeOnlyByOwner). |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
814 |
]. |
9806 | 815 |
^ TempDirectory |
3959 | 816 |
|
817 |
" |
|
818 |
Filename tempDirectory |
|
819 |
Filename tempDirectory pathName |
|
8660 | 820 |
Filename tempDirectory exists |
7836 | 821 |
Filename tempDirectory isWritable |
822 |
(Filename tempDirectory construct:'foo') makeDirectory |
|
8660 | 823 |
(Filename tempDirectory construct:'foo') remove |
3959 | 824 |
" |
825 |
||
9806 | 826 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
13781 | 827 |
"Modified: / 07-10-2011 / 18:39:25 / cg" |
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
828 |
! |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
829 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
830 |
tempDirectory:aFilename |
17048 | 831 |
"set the default temporary directory. |
832 |
This allows overwriting the automatically determined tmpDirectory |
|
833 |
by a knowledgable stand alone startup program. |
|
834 |
Do not use elsewhere (and only if absolutely requried)" |
|
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
835 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
836 |
|temp| |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
837 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
838 |
aFilename isNil ifTrue:[ |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
839 |
TempDirectory := nil. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
840 |
^ self. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
841 |
]. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
842 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
843 |
temp := aFilename asFilename. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
844 |
self assert:temp isDirectory. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
845 |
TempDirectory := temp. |
16382 | 846 |
! |
847 |
||
848 |
trashDirectoryOrNil |
|
849 |
"if the underlying OS uses/supports a trash folder, |
|
850 |
return it. Otherwise return nil. |
|
851 |
Asks the OS for the pathname; for example, on OSX, '~/.Trash' is returned." |
|
852 |
||
853 |
|s| |
|
854 |
||
855 |
s := OperatingSystem getTrashDirectory. |
|
856 |
s isNil ifTrue:[ |
|
857 |
^ nil |
|
858 |
]. |
|
859 |
^ self named:s |
|
860 |
||
861 |
" |
|
862 |
Filename desktopDirectory |
|
863 |
" |
|
864 |
||
865 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
16648 | 866 |
! |
867 |
||
868 |
usersPrivateSmalltalkDirectory |
|
869 |
^ Filename homeDirectory / '.smalltalk' |
|
870 |
||
871 |
" |
|
872 |
Filename usersPrivateSmalltalkDirectory |
|
873 |
" |
|
3959 | 874 |
! ! |
875 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
876 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
877 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
878 |
concreteClass |
6256 | 879 |
"different subclasses of Filename are used for different |
880 |
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
|
881 |
|
2906 | 882 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
883 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
884 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 885 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
886 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
887 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
888 |
defaultClass |
6256 | 889 |
"different subclasses of Filename are used for different |
890 |
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
|
891 |
|
2906 | 892 |
^ ConcreteClass |
893 |
||
894 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
7836 | 895 |
! |
896 |
||
897 |
defaultTempDirectoryName |
|
898 |
"return the default temp directory as a filename. |
|
899 |
This is used, if no special preferences were defined in |
|
900 |
any of the TEMP-environment variables (see tempDirectory)." |
|
901 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
902 |
self isAbstract ifTrue:[ |
8738 | 903 |
^ ConcreteClass defaultTempDirectoryName |
7836 | 904 |
]. |
905 |
||
10994
1a3776d0b845
always return a fileName from defaultTempDirectoryName
fm
parents:
10969
diff
changeset
|
906 |
^ '/tmp' asFilename |
7836 | 907 |
|
908 |
" |
|
909 |
Filename defaultTempDirectoryName |
|
910 |
" |
|
911 |
||
912 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
913 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
914 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
915 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
916 |
|
2922 | 917 |
!Filename class methodsFor:'misc'! |
918 |
||
3077 | 919 |
filterSeps:aFilenameString |
920 |
"ST80 compatibility: |
|
921 |
filter out (invalid) separators in aFilenameString. |
|
922 |
We recommend using #makeLegalFilename" |
|
923 |
||
16762 | 924 |
^ aFilenameString copyReplaceAll:(Character space) with:$_ ifNone:aFilenameString. |
3077 | 925 |
|
926 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 927 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 928 |
! |
929 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
930 |
nameWithSpecialExpansions:aString |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
931 |
"return the nameString, expanding any OS specific macros. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
932 |
Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
933 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
934 |
|dir user cutIdx idx userInfo| |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
935 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
936 |
(aString startsWith:'~') ifFalse:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
937 |
^ aString. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
938 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
939 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
940 |
aString size > 1 ifTrue:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
941 |
idx := aString indexOf:self separator. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
942 |
idx == 0 ifTrue:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
943 |
"aString is '~user'" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
944 |
user := aString copyFrom:2. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
945 |
cutIdx := aString size + 1. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
946 |
] ifFalse:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
947 |
"aString is '~user/something'" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
948 |
user := aString copyFrom:2 to:(idx - 1). |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
949 |
cutIdx := idx. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
950 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
951 |
user notEmpty ifTrue:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
952 |
userInfo := OperatingSystem userInfoOf:user. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
953 |
userInfo notNil ifTrue:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
954 |
dir := userInfo at:#dir ifAbsent:nil. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
955 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
956 |
dir isNil ifTrue:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
957 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
958 |
^ aString |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
959 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
960 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
961 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
962 |
dir isNil ifTrue:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
963 |
"aString is '~' or '~/'" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
964 |
dir := OperatingSystem getHomeDirectory. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
965 |
cutIdx := 2. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
966 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
967 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
968 |
^ dir , (aString copyFrom:cutIdx) |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
969 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
970 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
971 |
Filename new nameWithSpecialExpansions:'~' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
972 |
Filename new nameWithSpecialExpansions:'~\work' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
973 |
Filename new nameWithSpecialExpansions:'~stefan' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
974 |
Filename new nameWithSpecialExpansions:'~stefan\work' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
975 |
Filename new nameWithSpecialExpansions:'~foo' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
976 |
Filename new nameWithSpecialExpansions:'~foo\bar' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
977 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
978 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
979 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
980 |
UnixFilename new nameWithSpecialExpansions:'~' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
981 |
UnixFilename new nameWithSpecialExpansions:'~/work' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
982 |
UnixFilename new nameWithSpecialExpansions:'~stefan' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
983 |
UnixFilename new nameWithSpecialExpansions:'~stefan/work' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
984 |
UnixFilename new nameWithSpecialExpansions:'~foo' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
985 |
UnixFilename new nameWithSpecialExpansions:'~foo/bar' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
986 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
987 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
988 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
989 |
PCFilename new nameWithSpecialExpansions:'~' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
990 |
PCFilename new nameWithSpecialExpansions:'~\work' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
991 |
PCFilename new nameWithSpecialExpansions:'~stefan' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
992 |
PCFilename new nameWithSpecialExpansions:'~stefan\work' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
993 |
PCFilename new nameWithSpecialExpansions:'~foo' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
994 |
PCFilename new nameWithSpecialExpansions:'~foo\bar' |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
995 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
996 |
! |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
997 |
|
16999 | 998 |
possiblyQuotedPathname:aPath |
999 |
"return a filename path usable as command line argument, |
|
1000 |
by quoting in double quotes if there are any embedded special characters. |
|
1001 |
On Unix systems, special characters might also be prefixed by a backslash character." |
|
1002 |
||
1003 |
(aPath startsWith:'"') ifFalse:[ |
|
1004 |
(aPath includes:Character space) ifTrue:[ |
|
1005 |
^ '"',aPath,'"' |
|
1006 |
]. |
|
1007 |
]. |
|
1008 |
^ aPath |
|
1009 |
||
1010 |
||
1011 |
" |
|
1012 |
Filename possiblyQuotedPathname:'/tmp/bla' |
|
1013 |
Filename possiblyQuotedPathname:'/tmp directory/bla' |
|
1014 |
Filename possiblyQuotedPathname:'/tmp directory/bla file' |
|
1015 |
" |
|
1016 |
! |
|
1017 |
||
3077 | 1018 |
suggest:aFilenameString |
1019 |
"return a fileNamestring based on the argument, |
|
1020 |
which is legal on the current platform." |
|
1021 |
||
1022 |
^ self canonicalize:aFilenameString |
|
1023 |
||
1024 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 1025 |
! ! |
1026 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1027 |
!Filename class methodsFor:'queries'! |
2 | 1028 |
|
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1029 |
currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1030 |
"return a filename for the current directory" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1031 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1032 |
self isAbstract ifTrue:[ |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1033 |
^ ConcreteClass currentDirectoryName |
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 |
"/ 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
|
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 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1040 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1041 |
Filename currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1042 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1043 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1044 |
"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
|
1045 |
"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
|
1046 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1047 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1048 |
defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1049 |
"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
|
1050 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1051 |
^ self defaultDirectory name |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1052 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1053 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1054 |
Filename defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1055 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1056 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1057 |
|
2963 | 1058 |
directorySuffix |
1059 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
1060 |
The default is nil here, redefined for VMS" |
|
1061 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1062 |
self isAbstract ifTrue:[ |
8668 | 1063 |
^ ConcreteClass directorySuffix |
2963 | 1064 |
]. |
1065 |
||
1066 |
^ nil |
|
1067 |
! |
|
1068 |
||
1523 | 1069 |
errorReporter |
1070 |
"who knows the signals to report errors?" |
|
1071 |
||
1072 |
^ FileStream |
|
1073 |
||
1074 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
1075 |
! |
|
1076 |
||
440 | 1077 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
1078 |
"perform filename completion on aString in some directory; |
|
1079 |
return the longest matching filename prefix as a string. |
|
1318 | 1080 |
The boolean directoriesOnly and filesOnly control respectively, |
1081 |
if only directories or only regular files are to be considered for completion. |
|
1082 |
If multiple files match, the exception block aBlock is evaluated with a |
|
1083 |
filename representing the directory (where the match was done) as argument. |
|
440 | 1084 |
(this may be different from the inDirectory argument, if aString is absolute |
1085 |
or starts with ../)" |
|
1086 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1087 |
self isAbstract ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1088 |
^ ConcreteClass |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1089 |
filenameCompletionFor:aString |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1090 |
directory:inDirectory |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1091 |
directoriesOnly:directoriesOnly |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1092 |
filesOnly:filesOnly |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1093 |
ifMultiple:aBlock |
2906 | 1094 |
]. |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1095 |
^ 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
|
1096 |
! |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1097 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1098 |
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
|
1099 |
"perform filename completion on aString in some directory; |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1100 |
return the longest matching filename prefix as a string. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1101 |
The boolean directoriesOnly and filesOnly control respectively, |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1102 |
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
|
1103 |
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
|
1104 |
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
|
1105 |
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
|
1106 |
(list of matched filenames) as arguments. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1107 |
(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
|
1108 |
or starts with ../)" |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1109 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1110 |
|s f matchSet nMatch name dir isAbsolute sep| |
2906 | 1111 |
|
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1112 |
aString size == 0 ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1113 |
aBlock value:(self named:'.'). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1114 |
^ '' |
440 | 1115 |
]. |
1116 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1117 |
sep := self separator. |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1118 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1119 |
"/ 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
|
1120 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1121 |
f := self named:aString. |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
1122 |
isAbsolute := f isAbsolute. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1123 |
matchSet := f filenameCompletionIn:inDirectory. "/ BAD DESIGN: has side effect on f |
440 | 1124 |
dir := f directory. |
1125 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1126 |
matchSet := matchSet select:[:aFilename | |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1127 |
|f isDir| |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1128 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1129 |
isAbsolute ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1130 |
f := aFilename asFilename |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1131 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1132 |
f := (dir construct:aFilename). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1133 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1134 |
isDir := f isDirectory. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1135 |
directoriesOnly ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1136 |
isDir |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1137 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1138 |
filesOnly ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1139 |
isDir not |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1140 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1141 |
true |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1142 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1143 |
] |
440 | 1144 |
]. |
1145 |
||
6803 | 1146 |
f := f asCanonicalizedFilename. |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1147 |
(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
|
1148 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1149 |
more than one possible completion - |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1150 |
" |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1151 |
aMultipleBlock notNil ifTrue:[ |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1152 |
aMultipleBlock value:f value:matchSet. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1153 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1154 |
aBlock value:f |
440 | 1155 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1156 |
|
440 | 1157 |
" |
1158 |
even with more than one possible completion, |
|
1159 |
f's name is now the common prefix |
|
1160 |
" |
|
1161 |
name := f asString. |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1162 |
|
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1163 |
nMatch <= 1 ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1164 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1165 |
exactly one possible completion - |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1166 |
" |
3752 | 1167 |
"/ 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
|
1168 |
false "directoriesOnly" ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1169 |
(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
|
1170 |
(name endsWith:sep) ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1171 |
name := name , sep asString |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1172 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1173 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1174 |
] |
440 | 1175 |
]. |
1176 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1177 |
s := name. |
440 | 1178 |
|
1179 |
"/ special: if there was no change, and the string represented |
|
1180 |
"/ 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
|
1181 |
((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
|
1182 |
(s endsWith:sep) ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1183 |
(self named:s) isDirectory ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1184 |
^ s , sep asString |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1185 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1186 |
]. |
440 | 1187 |
]. |
1188 |
||
1189 |
^ s |
|
1318 | 1190 |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1191 |
"Modified: / 30.4.1999 / 09:40:13 / cg" |
615 | 1192 |
! |
1193 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1194 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1195 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1196 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1197 |
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
|
1198 |
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
|
1199 |
The returned strings are the expanded names, in the same form |
2550 | 1200 |
as given in pattern. |
1201 |
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
|
1202 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1203 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1204 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1205 |
self isAbstract ifTrue:[ |
8738 | 1206 |
^ ConcreteClass filesMatching:aPattern |
2906 | 1207 |
]. |
1208 |
||
1209 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1210 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1211 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1212 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1213 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1214 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1215 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1216 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1217 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1218 |
" |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1219 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1220 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1221 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1222 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1223 |
|
2906 | 1224 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 1225 |
! |
1226 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1227 |
isAbstract |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1228 |
"return true, if this is not a concrete class" |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1229 |
|
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1230 |
^ self == Filename |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1231 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1232 |
|
2903 | 1233 |
isBadCharacter:aCharacter |
1234 |
"return true, if aCharacter is unallowed in a filename." |
|
1235 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1236 |
self isAbstract ifTrue:[ |
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1237 |
^ ConcreteClass isBadCharacter:aCharacter |
2906 | 1238 |
]. |
1239 |
||
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1240 |
^ aCharacter isControlCharacter |
2903 | 1241 |
! |
1242 |
||
1243 |
isCaseSensitive |
|
1244 |
"return true, if filenames are case sensitive. |
|
1245 |
We ask the OS about this, to be independent here." |
|
1246 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1247 |
self isAbstract ifTrue:[ |
8668 | 1248 |
^ ConcreteClass isCaseSensitive |
2906 | 1249 |
]. |
1250 |
||
2903 | 1251 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 1252 |
|
1253 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 1254 |
! |
1255 |
||
615 | 1256 |
localNameStringFrom:aString |
1257 |
"ST-80 compatibility. |
|
1258 |
what does this do ? (used in FileNavigator-goody). |
|
2922 | 1259 |
GUESS: |
8243 | 1260 |
does it strip off any volume characters and make a path relative ?" |
2922 | 1261 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1262 |
self isAbstract ifTrue:[ |
8243 | 1263 |
^ ConcreteClass localNameStringFrom:aString |
2906 | 1264 |
]. |
1265 |
||
15227 | 1266 |
^ aString withoutPrefix:self separatorString |
615 | 1267 |
|
1268 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 1269 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 1270 |
! |
1271 |
||
2908 | 1272 |
maxComponentLength |
1273 |
"return the maximum number of characters a filename component may |
|
1274 |
be in size. This depends on the OperatingSystem." |
|
1275 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1276 |
self isAbstract ifTrue:[ |
8668 | 1277 |
^ ConcreteClass maxComponentLength |
2908 | 1278 |
]. |
1279 |
^ OperatingSystem maxFileNameLength |
|
1280 |
! |
|
1281 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1282 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1283 |
"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
|
1284 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1285 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1286 |
self isAbstract ifTrue:[ |
8668 | 1287 |
^ ConcreteClass maxLength |
2908 | 1288 |
]. |
1289 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1290 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1291 |
"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
|
1292 |
"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
|
1293 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1294 |
|
3171 | 1295 |
nullFilename |
1296 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
1297 |
The default is nil here" |
|
1298 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1299 |
self isAbstract ifTrue:[ |
8668 | 1300 |
^ ConcreteClass nullFilename |
3171 | 1301 |
]. |
1302 |
||
8754 | 1303 |
^ OperatingSystem getNullDevice |
3171 | 1304 |
|
1305 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1306 |
! |
|
1307 |
||
615 | 1308 |
parentDirectoryName |
1309 |
"return the name used for the parent directory. |
|
1310 |
This is '..' for unix and dos-like systems. |
|
1311 |
(there may be more in the future." |
|
1312 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1313 |
self isAbstract ifTrue:[ |
8668 | 1314 |
^ ConcreteClass parentDirectoryName |
2906 | 1315 |
]. |
1316 |
||
1317 |
^ OperatingSystem parentDirectoryName |
|
1318 |
||
1319 |
" |
|
1320 |
Filename parentDirectoryName |
|
1321 |
" |
|
1322 |
||
1323 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1324 |
! |
1325 |
||
1326 |
separator |
|
1327 |
"return the file/directory separator. |
|
15246 | 1328 |
This is to be redefined in concrete classes." |
1329 |
||
1330 |
^ ConcreteClass separator |
|
8243 | 1331 |
|
1332 |
" |
|
8754 | 1333 |
Filename separator |
1334 |
PCFilename separator |
|
8243 | 1335 |
" |
2906 | 1336 |
|
1337 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1338 |
! |
1339 |
||
8243 | 1340 |
separatorString |
1341 |
"return the file/directory separator as a string." |
|
1342 |
||
1343 |
^ self separator asString |
|
1344 |
||
1345 |
" |
|
1346 |
Filename separatorString |
|
1347 |
" |
|
1348 |
! |
|
1349 |
||
615 | 1350 |
suffixSeparator |
1351 |
"return the filename suffix separator. |
|
1352 |
Usually, this is $. for unix-like and msdos systems |
|
1318 | 1353 |
(there is currently no known system, where this differs)" |
615 | 1354 |
|
1355 |
^ $. |
|
1356 |
||
1357 |
" |
|
1358 |
Filename suffixSeparator |
|
1359 |
" |
|
1360 |
||
1361 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1362 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1363 |
! |
1364 |
||
2906 | 1365 |
tempFileNameTemplate |
1366 |
"return a template for temporary files. |
|
1367 |
This is expanded with the current processID and a sequenceNumber |
|
1368 |
to generate a unique filename." |
|
1369 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1370 |
self isAbstract ifTrue:[ |
8668 | 1371 |
^ ConcreteClass tempFileNameTemplate |
2906 | 1372 |
]. |
1373 |
||
1374 |
^ 'stxtmp_%1_%2' |
|
1375 |
||
1376 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1377 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1378 |
! |
|
1379 |
||
615 | 1380 |
volumes |
1381 |
"ST-80 compatibility. |
|
2896 | 1382 |
GUESS: does it return the available drives on MSDOS systems ? |
1383 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1384 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1385 |
self isAbstract ifTrue:[ |
8679 | 1386 |
^ ConcreteClass volumes |
2906 | 1387 |
]. |
1388 |
||
2896 | 1389 |
^ OperatingSystem getDriveList |
615 | 1390 |
|
8679 | 1391 |
" |
1392 |
Filename volumes |
|
1393 |
" |
|
615 | 1394 |
! ! |
1395 |
||
6383 | 1396 |
!Filename class methodsFor:'utilities'! |
1397 |
||
16389 | 1398 |
canonicalize:aPathString |
1399 |
"convert the argument, aPathString to a good format. |
|
1400 |
This should eliminate useless directory components (i.e. '././') |
|
1401 |
and useless tree walks (i.e. '../foo/..')." |
|
1402 |
||
1403 |
^ self nameFromComponents:(self canonicalizedNameComponents:aPathString) |
|
1404 |
||
1405 |
" |
|
1406 |
Filename canonicalize:'/etc/../etc' |
|
1407 |
Filename canonicalize:'/home/cg/../' |
|
1408 |
Filename canonicalize:'/home/cg/../././' |
|
1409 |
Filename canonicalize:'./home/cg/../././' |
|
1410 |
Filename canonicalize:'/home/././cg/../././' |
|
1411 |
Filename canonicalize:'/home/././cg/././' |
|
1412 |
Filename canonicalize:'/home/cg/../../..' |
|
1413 |
Filename canonicalize:'cg/../../..' |
|
1414 |
Filename canonicalize:'./' |
|
1415 |
Filename canonicalize:'/home/.' |
|
1416 |
Filename canonicalize:'/home/../..' |
|
1417 |
Filename canonicalize:'//foo' |
|
1418 |
Filename canonicalize:'///foo' |
|
1419 |
Filename canonicalize:'//foo//bar' |
|
1420 |
" |
|
1421 |
! |
|
1422 |
||
1423 |
canonicalizedNameComponents:aPathString |
|
1424 |
"convert the argument, aPathString to a good format. |
|
1425 |
This should eliminate useless directory components (i.e. '././') |
|
1426 |
and useless tree walks (i.e. '../foo/..'). |
|
1427 |
||
1428 |
Answer a sequenceable collection of name components." |
|
1429 |
||
1430 |
|comps newComps rootName dotDot dot| |
|
1431 |
||
1432 |
dotDot := self parentDirectoryName. |
|
1433 |
dot := self currentDirectoryName. |
|
1434 |
rootName := self separatorString. |
|
1435 |
||
1436 |
comps := self components:aPathString. |
|
1437 |
newComps := OrderedCollection new:comps size. |
|
1438 |
comps do:[:eachComponent | |
|
1439 |
eachComponent ~= dot ifTrue:[ |
|
1440 |
eachComponent = dotDot ifTrue:[ |
|
1441 |
(newComps isEmpty |
|
1442 |
or:[(newComps size == 1 and:[newComps first startsWith:rootName]) |
|
1443 |
or:[newComps last = dotDot]]) ifTrue:[ |
|
1444 |
newComps add:eachComponent |
|
1445 |
] ifFalse:[ |
|
1446 |
newComps removeLast |
|
1447 |
]. |
|
1448 |
] ifFalse:[ |
|
1449 |
newComps add:eachComponent |
|
1450 |
]. |
|
1451 |
] |
|
1452 |
]. |
|
1453 |
"/ add current Directory if empty |
|
1454 |
newComps isEmpty ifTrue:[ |
|
1455 |
newComps add:dot. |
|
1456 |
]. |
|
1457 |
^ newComps |
|
1458 |
||
1459 |
" |
|
1460 |
Filename canonicalizedNameComponents:'/etc/../etc' |
|
1461 |
Filename canonicalizedNameComponents:'/home/cg/../' |
|
1462 |
Filename canonicalizedNameComponents:'/home/cg/../././' |
|
1463 |
Filename canonicalizedNameComponents:'./home/cg/../././' |
|
1464 |
Filename canonicalizedNameComponents:'/home/././cg/../././' |
|
1465 |
Filename canonicalizedNameComponents:'/home/././cg/././' |
|
1466 |
Filename canonicalizedNameComponents:'/home/cg/../../..' |
|
1467 |
Filename canonicalizedNameComponents:'cg/../../..' |
|
1468 |
Filename canonicalizedNameComponents:'/' |
|
1469 |
Filename canonicalizedNameComponents:'./' |
|
1470 |
Filename canonicalizedNameComponents:'/.' |
|
1471 |
Filename canonicalizedNameComponents:'/home/.' |
|
1472 |
Filename canonicalizedNameComponents:'/home' |
|
1473 |
Filename canonicalizedNameComponents:'/home/../..' |
|
1474 |
Filename canonicalizedNameComponents:'//foo' |
|
1475 |
Filename canonicalizedNameComponents:'///foo' |
|
1476 |
Filename canonicalizedNameComponents:'//foo//bar' |
|
1477 |
" |
|
1478 |
! |
|
1479 |
||
1480 |
components:aString |
|
1481 |
"separate the pathName given by aString into |
|
16578 | 1482 |
a collection containing the directory components and the file's name as |
16389 | 1483 |
the final component. |
1484 |
If the argument names an absolute path, the first component will be the |
|
1485 |
name of the root directory (i.e. '/')." |
|
1486 |
||
1487 |
|sep f vol rest components| |
|
1488 |
||
1489 |
self isAbstract ifTrue:[ |
|
1490 |
^ ConcreteClass components:aString |
|
1491 |
]. |
|
1492 |
||
1493 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1494 |
"/ However, MSDOS drive-letters and network drives are |
|
1495 |
"/ not correctly handled here. |
|
1496 |
||
1497 |
sep := self separator. |
|
1498 |
f := aString asFilename. |
|
1499 |
vol := f volume. |
|
1500 |
vol size ~~ 0 ifTrue:[ |
|
1501 |
rest := f localPathName. |
|
1502 |
] ifFalse:[ |
|
1503 |
rest := aString |
|
1504 |
]. |
|
1505 |
||
1506 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1507 |
(rest startsWith:sep) ifTrue:[ |
|
1508 |
"first was a separator - root directory - restore" |
|
1509 |
(rest size > 1 and:[rest second = sep and:[vol isEmptyOrNil]]) ifTrue:[ |
|
1510 |
"keep \\ for windows network paths" |
|
1511 |
components at:1 put:(String with:sep with:sep). |
|
1512 |
] ifFalse:[ |
|
1513 |
components at:1 put:sep asString. |
|
1514 |
]. |
|
1515 |
]. |
|
1516 |
components := components select:[:each| each notEmpty]. |
|
1517 |
||
1518 |
"/ prepend volume to first component (the root directory) |
|
1519 |
vol size ~~ 0 ifTrue:[ |
|
1520 |
components at:1 put:(vol , (components at:1)). |
|
1521 |
]. |
|
1522 |
^ components |
|
1523 |
||
1524 |
" |
|
1525 |
Filename components:'/foo/bar/baz' |
|
1526 |
Filename components:'/' |
|
1527 |
Filename components:'//' |
|
1528 |
Filename components:'foo/bar/baz' |
|
1529 |
Filename components:'foo/bar' |
|
1530 |
Filename components:'foo' |
|
1531 |
Filename components:'/foo' |
|
1532 |
Filename components:'//foo' |
|
1533 |
Filename components:'' |
|
1534 |
||
1535 |
Filename components:'\' |
|
1536 |
Filename components:'\foo' |
|
1537 |
Filename components:'\foo\' |
|
1538 |
Filename components:'\foo\bar' |
|
1539 |
Filename components:'\foo\bar\' |
|
1540 |
Filename components:'c:' |
|
1541 |
Filename components:'c:\' |
|
1542 |
Filename components:'c:\foo' |
|
1543 |
Filename components:'c:\foo\' |
|
1544 |
Filename components:'c:\foo\bar' |
|
1545 |
Filename components:'c:\foo\bar\' |
|
1546 |
Filename components:'\\idefix' |
|
1547 |
Filename components:'\\idefix\home' |
|
1548 |
Filename components:'\\idefix\home\bar' |
|
1549 |
" |
|
1550 |
||
1551 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
|
1552 |
! |
|
1553 |
||
6802 | 1554 |
nameFromComponents:aCollectionOfDirectoryNames |
1555 |
"return a filenameString from components given in aCollectionOfDirectoryNames. |
|
1556 |
If the first component is the name of the root directory (i.e. '/'), |
|
1557 |
an absolute path-string is returned." |
|
1558 |
||
1559 |
|sep s| |
|
1560 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1561 |
self isAbstract ifTrue:[ |
6802 | 1562 |
^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames |
1563 |
]. |
|
1564 |
||
1565 |
"/ fallBack - works on Unix & MSDOS |
|
1566 |
||
8243 | 1567 |
sep := self separatorString. |
6802 | 1568 |
s := ''. |
1569 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
|
1570 |
index == 1 ifTrue:[ |
|
7074 | 1571 |
s := component. |
1572 |
] ifFalse:[ |
|
1573 |
(index == 2 and:[ (s endsWith:sep) ]) ifTrue:[ |
|
6802 | 1574 |
s := s , component |
7074 | 1575 |
] ifFalse:[ |
1576 |
s := s , sep , component |
|
6802 | 1577 |
] |
1578 |
]. |
|
1579 |
]. |
|
1580 |
^ s |
|
1581 |
||
1582 |
" |
|
1583 |
Filename nameFromComponents:#('/' 'foo' 'bar' 'baz') |
|
1584 |
Filename nameFromComponents:#('foo' 'bar' 'baz') |
|
7074 | 1585 |
Filename nameFromComponents:#('/') |
1586 |
||
1587 |
|comps| |
|
1588 |
comps := Filename components:'/foo/bar/baz'. |
|
1589 |
Filename nameFromComponents:comps |
|
1590 |
||
1591 |
|comps| |
|
1592 |
comps := Filename components:'\foo\bar\baz'. |
|
1593 |
Filename nameFromComponents:comps |
|
1594 |
||
1595 |
|comps| |
|
1596 |
comps := Filename components:'c:\foo\bar\baz'. |
|
1597 |
Filename nameFromComponents:comps |
|
1598 |
||
1599 |
|comps| |
|
1600 |
comps := Filename components:'foo\bar\baz'. |
|
1601 |
Filename nameFromComponents:comps |
|
1602 |
||
1603 |
|comps| |
|
1604 |
comps := Filename components:'foo'. |
|
1605 |
Filename nameFromComponents:comps |
|
1606 |
||
1607 |
|comps| |
|
1608 |
comps := Filename components:'\'. |
|
1609 |
Filename nameFromComponents:comps |
|
1610 |
||
1611 |
|comps| |
|
1612 |
comps := Filename components:'c:\'. |
|
1613 |
Filename nameFromComponents:comps |
|
6802 | 1614 |
" |
1615 |
||
1616 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
1617 |
! |
|
1618 |
||
6383 | 1619 |
readingFile:aPathName do:aBlock |
1620 |
"create a read-stream on a file, evaluate aBlock, passing that stream, |
|
1621 |
and return the blocks value. |
|
1622 |
Ensures that the stream is closed." |
|
1623 |
||
6529 | 1624 |
^ aPathName asFilename readingFileDo:aBlock. |
1625 |
||
1626 |
" |
|
1627 |
read the first line from some file: |
|
1628 |
||
1629 |
|rslt| |
|
1630 |
||
1631 |
rslt := |
|
1632 |
Filename |
|
1633 |
readingFile:'/etc/passwd' |
|
1634 |
do:[:s | |
|
1635 |
s nextLine |
|
1636 |
]. |
|
1637 |
Transcript showCR:rslt. |
|
1638 |
" |
|
1639 |
||
1640 |
" |
|
1641 |
find all used shells in /etc/passwd and count their usage: |
|
1642 |
||
6383 | 1643 |
|rslt| |
1644 |
||
6529 | 1645 |
rslt := |
1646 |
Filename |
|
1647 |
readingFile:'/etc/passwd' |
|
1648 |
do: |
|
1649 |
[:s | |
|
1650 |
|shells| |
|
1651 |
||
1652 |
shells := Bag new. |
|
1653 |
s linesDo: |
|
1654 |
[:line | |
|
1655 |
|parts| |
|
1656 |
||
1657 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
1658 |
shells add:(parts seventh). |
|
1659 |
]. |
|
1660 |
shells contents |
|
1661 |
]. |
|
1662 |
Transcript showCR:rslt. |
|
1663 |
" |
|
6383 | 1664 |
! ! |
1665 |
||
7261 | 1666 |
!Filename methodsFor:'Compatibility-VW5.4'! |
6139 | 1667 |
|
1668 |
asLogicalFileSpecification |
|
1669 |
^ self |
|
1670 |
||
1671 |
"Created: / 30.10.2001 / 17:31:10 / cg" |
|
6447 | 1672 |
! |
1673 |
||
10583 | 1674 |
canBeWritten |
1675 |
"same as isWritable - for ST-80 compatibility" |
|
1676 |
||
1677 |
^ self isWritable |
|
1678 |
||
1679 |
" |
|
1680 |
'/foo/bar' asFilename canBeWritten |
|
1681 |
'/tmp' asFilename canBeWritten |
|
1682 |
'Makefile' asFilename canBeWritten |
|
1683 |
" |
|
1684 |
! |
|
1685 |
||
7596 | 1686 |
definitelyExists |
1687 |
"for now - a kludge" |
|
1688 |
||
1689 |
^ self exists |
|
1690 |
! |
|
1691 |
||
6447 | 1692 |
extension |
6454 | 1693 |
"return the receiver's extension; |
1694 |
that is the characters from and including |
|
1695 |
the last period or nil, if there is none." |
|
1696 |
||
1697 |
|string idx| |
|
1698 |
||
1699 |
string := self asString. |
|
1700 |
idx := string lastIndexOf:$.. |
|
1701 |
idx > 1 ifTrue:[ |
|
1702 |
^ string copyFrom:idx |
|
1703 |
]. |
|
1704 |
^ nil |
|
1705 |
||
1706 |
" |
|
1707 |
'foo.html' asFilename extension |
|
1708 |
'foo.bar' asFilename extension |
|
1709 |
'foo.bar.baz' asFilename extension |
|
1710 |
'foo.' asFilename extension |
|
1711 |
'foo' asFilename extension |
|
1712 |
'.login' asFilename extension |
|
1713 |
" |
|
6139 | 1714 |
! ! |
1715 |
||
615 | 1716 |
!Filename methodsFor:'comparing'! |
1717 |
||
16255 | 1718 |
< aFilename |
1719 |
"compare file names - used for sorting" |
|
1720 |
||
1721 |
^ self asString < aFilename asString |
|
1722 |
! |
|
1723 |
||
615 | 1724 |
= aFilename |
1725 |
"return true, if the argument represents the same filename" |
|
1726 |
||
1727 |
|str| |
|
1728 |
||
1729 |
self species == aFilename species ifTrue:[ |
|
9453 | 1730 |
str := aFilename asString. |
15811 | 1731 |
self species isCaseSensitive ifTrue:[ |
9453 | 1732 |
^ nameString = str |
1733 |
]. |
|
1734 |
^ nameString sameAs:str |
|
615 | 1735 |
]. |
1736 |
^ false |
|
1737 |
! |
|
1738 |
||
5877 | 1739 |
contentsIsPrefixOf:aFilename |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1740 |
"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
|
1741 |
is the same as or a prefix of the contents of the file represented by the argument, aFilename. |
16578 | 1742 |
This compares the files' actual contents; not the filenames." |
3868 | 1743 |
|
8771 | 1744 |
|f2 s1 s2 bufferSize buffer1 buffer2 n| |
1745 |
||
1746 |
bufferSize := 8192 * 4. |
|
4979 | 1747 |
|
1748 |
f2 := aFilename asFilename. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1749 |
self fileSize > f2 fileSize ifTrue:[^ false]. |
3868 | 1750 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1751 |
[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1752 |
s1 := self readStream. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1753 |
s2 := f2 readStream. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1754 |
s1 binary. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1755 |
s2 binary. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1756 |
|
8771 | 1757 |
buffer1 := ByteArray new:bufferSize. |
1758 |
buffer2 := ByteArray new:bufferSize. |
|
7776 | 1759 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1760 |
[s1 atEnd] whileFalse:[ |
8771 | 1761 |
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
|
1762 |
n == 0 ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1763 |
"/ receiver shorter. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1764 |
^ true |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1765 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1766 |
(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
|
1767 |
"/ aFilename shorter |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1768 |
^ false |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1769 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1770 |
buffer1 ~= buffer2 ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1771 |
^ false |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1772 |
] |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1773 |
]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1774 |
"/ receiver shorter or same size. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1775 |
] ensure:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1776 |
s1 notNil ifTrue:[s1 close]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1777 |
s2 notNil ifTrue:[s2 close]. |
3868 | 1778 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1779 |
^ true |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1780 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1781 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1782 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1783 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1784 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1785 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1786 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1787 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1788 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1789 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1790 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1791 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1792 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1793 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1794 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1795 |
|
5877 | 1796 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1797 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1798 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1799 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1800 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1801 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1802 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1803 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1804 |
|
5877 | 1805 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1806 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1807 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1808 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1809 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1810 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1811 |
|
5877 | 1812 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1813 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1814 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1815 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1816 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1817 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1818 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1819 |
|
5877 | 1820 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
1821 |
||
1822 |
" |
|
1823 |
! |
|
1824 |
||
1825 |
contentsStartsWithContentsOf:aFilename |
|
1826 |
"return true if the contents of the file represented by aFilename |
|
1827 |
is the same as or a prefix of the contents of the file represented by the receiver. |
|
16578 | 1828 |
This compares the files' actual contents; not the filenames." |
5877 | 1829 |
|
1830 |
^ aFilename asFilename contentsIsPrefixOf:self |
|
1831 |
||
1832 |
" |
|
1833 |
|s| |
|
1834 |
||
1835 |
s := 'testFile1' asFilename writeStream. |
|
1836 |
s nextPutAll:'11111'. |
|
1837 |
s nextPutAll:'22222'. |
|
1838 |
s nextPutAll:'33333'. |
|
1839 |
s close. |
|
1840 |
||
1841 |
s := 'testFile2' asFilename writeStream. |
|
1842 |
s nextPutAll:'11111'. |
|
1843 |
s nextPutAll:'22222'. |
|
1844 |
s nextPutAll:'33333'. |
|
1845 |
s close. |
|
1846 |
||
1847 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1848 |
||
1849 |
s := 'testFile2' asFilename writeStream. |
|
1850 |
s nextPutAll:'11111'. |
|
1851 |
s nextPutAll:'22222'. |
|
1852 |
s nextPutAll:'33333'. |
|
1853 |
s nextPutAll:'44444'. |
|
1854 |
s close. |
|
1855 |
||
1856 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1857 |
||
1858 |
s := 'testFile2' asFilename writeStream. |
|
1859 |
s nextPutAll:'11111'. |
|
1860 |
s nextPutAll:'22222'. |
|
1861 |
s close. |
|
1862 |
||
1863 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
1864 |
||
1865 |
s := 'testFile2' asFilename writeStream. |
|
1866 |
s nextPutAll:'11111'. |
|
1867 |
s nextPutAll:'22222'. |
|
1868 |
s nextPutAll:'33334'. |
|
1869 |
s close. |
|
1870 |
||
1871 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1872 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1873 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1874 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1875 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1876 |
hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1877 |
"return an integer useful as a hash-key" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1878 |
|
15811 | 1879 |
self species isCaseSensitive ifFalse:[ |
11425 | 1880 |
^ nameString asUppercase hash |
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
1881 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1882 |
^ nameString hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1883 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1884 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1885 |
sameContentsAs:aFilename |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1886 |
"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
|
1887 |
same contents as the file represented by the argument, aFilename. |
16578 | 1888 |
This compares the file's actual contents; not the filenames." |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1889 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1890 |
|f2| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1891 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1892 |
f2 := aFilename asFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1893 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
5877 | 1894 |
^ self contentsIsPrefixOf:f2. |
3868 | 1895 |
|
1896 |
" |
|
1897 |
'Make.proto' asFilename sameContentsAs:'Makefile' |
|
7122 | 1898 |
'Make.proto' asFilename sameContentsAs:'Make.proto' |
3868 | 1899 |
" |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1900 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1901 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1902 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1903 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1904 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1905 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1906 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1907 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1908 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1909 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1910 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1911 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1912 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1913 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1914 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1915 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1916 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifFalse:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1917 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1918 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1919 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1920 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1921 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1922 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1923 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1924 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1925 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1926 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1927 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1928 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1929 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1930 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1931 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1932 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1933 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1934 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1935 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1936 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1937 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1938 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1939 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1940 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1941 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1942 |
" |
615 | 1943 |
! ! |
1944 |
||
1945 |
!Filename methodsFor:'converting'! |
|
1946 |
||
1947 |
asAbsoluteFilename |
|
1948 |
"return the receiver converted to a filename with |
|
1949 |
an absolute pathname." |
|
1950 |
||
15811 | 1951 |
^ self species named:self pathName |
7332 | 1952 |
|
1953 |
" |
|
1954 |
'.' asFilename |
|
1955 |
'.' asFilename asAbsoluteFilename |
|
9173 | 1956 |
'c:' asFilename asAbsoluteFilename |
7332 | 1957 |
" |
615 | 1958 |
! |
1959 |
||
10769 | 1960 |
asAutoDeletedFilename |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
1961 |
"will automatically delete myself, when no longer referenced" |
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
1962 |
|
11784 | 1963 |
^ AutoDeletedFilename basicNew setName:self name |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
1964 |
|
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
1965 |
"Modified (comment): / 07-09-2011 / 12:20:59 / cg" |
10769 | 1966 |
! |
1967 |
||
6802 | 1968 |
asCanonicalizedFilename |
1969 |
"return the receiver converted to a filename without intermediate ..'s and .'s |
|
1970 |
(similar to an absolute pathname, but symlinks are not resolved)." |
|
1971 |
||
15811 | 1972 |
^ self species named:(self species canonicalize:nameString) |
7074 | 1973 |
|
1974 |
" |
|
1975 |
'c:\test\work' asFilename asCanonicalizedFilename |
|
1976 |
'/test/work' asFilename asCanonicalizedFilename |
|
1977 |
" |
|
6802 | 1978 |
! |
1979 |
||
615 | 1980 |
asFilename |
1970 | 1981 |
"return the receiver converted to a filename; here, thats the receiver itself." |
615 | 1982 |
|
1983 |
"Thats pretty easy here :-)" |
|
1984 |
^ self |
|
1970 | 1985 |
|
1986 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 1987 |
! |
1988 |
||
1989 |
asString |
|
1990 |
"return the receiver converted to a string" |
|
1991 |
||
1992 |
^ nameString |
|
1993 |
! |
|
1994 |
||
6256 | 1995 |
asURI |
15001 | 1996 |
"return the receiver converted to a file URI" |
6256 | 1997 |
|
1998 |
^ FileURI fromFilename:self. |
|
1999 |
! |
|
2000 |
||
15001 | 2001 |
asURL |
2002 |
"return an URL-object from myself" |
|
2003 |
||
2004 |
^ URL fromString:self pathName. |
|
2005 |
! |
|
2006 |
||
5890 | 2007 |
components |
2008 |
"return the receivers filename components - that is the name of each directory |
|
2009 |
along the pathName (that DOES include the root directory)" |
|
2010 |
||
15811 | 2011 |
^ self species components:self name |
5890 | 2012 |
|
2013 |
" |
|
2014 |
'.' asFilename asAbsoluteFilename components |
|
2015 |
'Makefile' asFilename asAbsoluteFilename components |
|
2016 |
" |
|
2017 |
! |
|
2018 |
||
615 | 2019 |
makeLegalFilename |
1970 | 2020 |
"convert the receivers name to be a legal filename. |
2021 |
This removes/replaces invalid characters and/or compresses |
|
2022 |
the name as required by the OS. |
|
615 | 2023 |
The implementation may change in the future to be more |
2024 |
OS specific." |
|
2025 |
||
2026 |
" |
|
2027 |
actually, in Unix spaces are allowed - but it makes life |
|
2028 |
so hard; therefore, replace them by underscores ... |
|
2029 |
" |
|
16761 | 2030 |
nameString := nameString copyReplaceAll:(Character space) with:$_ ifNone:nameString. |
615 | 2031 |
" |
2032 |
need more - especially on SYS5.3 type systems, |
|
2033 |
we may want to contract the fileName to 14 characters. |
|
2034 |
" |
|
2035 |
^ self |
|
2036 |
||
2037 |
" |
|
2038 |
'hello world' asFilename makeLegalFilename |
|
2039 |
" |
|
1970 | 2040 |
|
3658 | 2041 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2042 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2043 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2044 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2045 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2046 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2047 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2048 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2049 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 2050 |
! ! |
2051 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2052 |
!Filename methodsFor:'enumerating-contents'! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2053 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2054 |
allDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2055 |
"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
|
2056 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2057 |
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
|
2058 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2059 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2060 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2061 |
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
|
2062 |
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
|
2063 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2064 |
self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | |
9453 | 2065 |
|eachFileOrDirectory| |
2066 |
||
2067 |
eachFileOrDirectory := self construct:eachFileOrDirectoryName. |
|
2068 |
eachFileOrDirectory isDirectory ifTrue:[ |
|
2069 |
aBlock value:eachFileOrDirectory |
|
2070 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2071 |
]. |
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 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2074 |
'.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2075 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2076 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2077 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2078 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2079 |
allParentDirectoriesDo:aBlock |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2080 |
"evaluate aBlock for all (recursive) directories along the parent directory path. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2081 |
The block is invoked with a filename-arguments." |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2082 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2083 |
|parent here| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2084 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2085 |
here := self. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2086 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2087 |
[here notNil and:[parent ~= here]] whileTrue:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2088 |
aBlock value:parent. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2089 |
here := parent. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2090 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2091 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2092 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2093 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2094 |
'.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2095 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2096 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2097 |
|
9362 | 2098 |
directories |
2099 |
"return a collection of directories contained in the directory represented by the receiver." |
|
2100 |
||
10557 | 2101 |
^ self directoryContentsAsFilenames |
2102 |
select:[:eachFileOrDirectory | eachFileOrDirectory isDirectory] |
|
9362 | 2103 |
|
2104 |
" |
|
2105 |
'.' asFilename directories. |
|
2106 |
" |
|
10557 | 2107 |
|
2108 |
"Modified: / 29-05-2007 / 12:02:56 / cg" |
|
9362 | 2109 |
! |
2110 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2111 |
directoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2112 |
"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
|
2113 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2114 |
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
|
2115 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2116 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2117 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2118 |
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
|
2119 |
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
|
2120 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2121 |
self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
9453 | 2122 |
eachFileOrDirectory isDirectory ifTrue:[ |
2123 |
aBlock value:eachFileOrDirectory |
|
2124 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2125 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2126 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2127 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2128 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2129 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2130 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2131 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2132 |
directoryContentsAsFilenamesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2133 |
"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
|
2134 |
The block is invoked with a filename-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2135 |
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
|
2136 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2137 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2138 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2139 |
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
|
2140 |
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
|
2141 |
Notice: this enumerates fileName objects; see also |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2142 |
#directoryContentsDo:, which enumerates strings." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2143 |
|
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2144 |
self directoryContentsDo:[:entry | |
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2145 |
aBlock value:(self construct:entry). |
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2146 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2147 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2148 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2149 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2150 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2151 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2152 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2153 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2154 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2155 |
|
7464 | 2156 |
directoryContentsDo:aBlock |
2157 |
"evaluate aBlock for each file in the directory represented by the receiver. |
|
2158 |
The block is invoked with a string as argument. |
|
2159 |
The enumerations order is undefined - i.e. usually NOT sorted by |
|
2160 |
filenames (but by creation time - on some systems). |
|
2161 |
This excludes entries for '.' or '..'. |
|
7473 | 2162 |
An exception is raised it the directory does not exist.. |
7464 | 2163 |
So users of this method better test for existing directory before. |
2164 |
Notice: this enumerates strings; see also |
|
2165 |
#directoryContentsAsFilenamesDo:, which enumerates fileName objects." |
|
2166 |
||
2167 |
|s fn| |
|
2168 |
||
7846 | 2169 |
FileStream openErrorSignal |
2170 |
handle:[:ex |] |
|
2171 |
do:[ |
|
2172 |
s := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
|
2173 |
]. |
|
2174 |
s isNil ifTrue:[^ self]. |
|
7464 | 2175 |
|
2176 |
[ |
|
2177 |
[s atEnd] whileFalse:[ |
|
2178 |
fn := s nextLine. |
|
2179 |
((fn ~= '.') and:[fn ~= '..']) ifTrue:[ |
|
2180 |
aBlock value:fn |
|
2181 |
] |
|
2182 |
] |
|
2183 |
] ensure:[ |
|
2184 |
s close |
|
2185 |
]. |
|
2186 |
||
2187 |
" |
|
2188 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
7473 | 2189 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
7464 | 2190 |
" |
2191 |
||
2192 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
2193 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
|
2194 |
! |
|
2195 |
||
9382 | 2196 |
files |
9383 | 2197 |
"return a collection of files contained in the directory represented by the receiver." |
9382 | 2198 |
|
10557 | 2199 |
^ self directoryContentsAsFilenames |
15364 | 2200 |
reject:[:eachFileOrDirectory | eachFileOrDirectory isDirectory ] |
9382 | 2201 |
|
2202 |
" |
|
2203 |
'.' asFilename files. |
|
2204 |
" |
|
10557 | 2205 |
|
2206 |
"Modified: / 29-05-2007 / 12:02:15 / cg" |
|
9382 | 2207 |
! |
2208 |
||
9806 | 2209 |
filesDo:aBlock |
2210 |
"evaluate aBlock for all files contained in the directory represented by the receiver." |
|
2211 |
||
10557 | 2212 |
^ self directoryContentsAsFilenames |
2213 |
do:[:eachFileOrDirectory | |
|
2214 |
eachFileOrDirectory isDirectory ifFalse:[ aBlock value: eachFileOrDirectory]]. |
|
9806 | 2215 |
|
2216 |
" |
|
2217 |
'.' asFilename filesDo:[:f | Transcript showCR:f]. |
|
2218 |
" |
|
2219 |
||
2220 |
"Created: / 29-08-2006 / 11:03:15 / cg" |
|
10557 | 2221 |
"Modified: / 29-05-2007 / 12:02:46 / cg" |
9806 | 2222 |
! |
2223 |
||
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2224 |
recursiveDirectoryContentsAsFilenamesDo:aBlock |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2225 |
"evaluate aBlock for all files and directories found under the receiver. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2226 |
The block is invoked with the filenames as argument. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2227 |
The walk is bread-first. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2228 |
This excludes any entries for '.' or '..'. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2229 |
Subdirectory files are included with a relative pathname. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2230 |
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)." |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2231 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2232 |
self recursiveDirectoryContentsDo:[:relFn | |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2233 |
aBlock value:(self construct:relFn) |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2234 |
]. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2235 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2236 |
" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2237 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2238 |
" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2239 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2240 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2241 |
! |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2242 |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2243 |
recursiveDirectoryContentsDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2244 |
"evaluate aBlock for all files and directories found under the receiver. |
13057
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2245 |
The block is invoked with the relative filenames as string-argument. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2246 |
The walk is bread-first. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2247 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2248 |
Subdirectory files are included with a relative pathname. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2249 |
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
|
2250 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2251 |
self recursiveDirectoryContentsDo:aBlock directoryPrefix:'' |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2252 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2253 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2254 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2255 |
" |
13057
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2256 |
|
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2257 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2258 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2259 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2260 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2261 |
"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
|
2262 |
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
|
2263 |
The walk is breadth-first. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2264 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2265 |
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
|
2266 |
A proceedable exception is raised forn non-accessable directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2267 |
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
|
2268 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2269 |
|fileNames dirNames p| |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2270 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2271 |
fileNames := OrderedCollection new. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2272 |
dirNames := OrderedCollection new. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2273 |
self directoryContentsDo:[:f | |t| |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2274 |
t := self construct:f. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2275 |
t isDirectory ifTrue:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2276 |
t isSymbolicLink ifFalse:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2277 |
dirNames add:f |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2278 |
] |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2279 |
] ifFalse:[ |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2280 |
fileNames add:f |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2281 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2282 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2283 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2284 |
aPrefix size > 0 ifTrue:[ |
8243 | 2285 |
p := aPrefix , self separator |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2286 |
] ifFalse:[ |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2287 |
p := '' |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2288 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2289 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2290 |
fileNames do:[:aFile | aBlock value:(p , aFile)]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2291 |
dirNames do:[:dN | |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2292 |
aBlock value:(p , dN). |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2293 |
(self construct:dN) |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2294 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN) |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2295 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2296 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2297 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2298 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2299 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2300 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2301 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2302 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2303 |
withAllDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2304 |
"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
|
2305 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2306 |
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
|
2307 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2308 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2309 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2310 |
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
|
2311 |
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
|
2312 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2313 |
self isDirectory ifTrue:[ |
9453 | 2314 |
aBlock value:self. |
2315 |
self allDirectoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2316 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2317 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2318 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2319 |
'.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2320 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2321 |
! ! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2322 |
|
542 | 2323 |
!Filename methodsFor:'error handling'! |
2324 |
||
615 | 2325 |
accessDeniedError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2326 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2327 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2328 |
"report an error that access to some file was denied" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2329 |
|
4820 | 2330 |
|errNo errString| |
2331 |
||
2332 |
errNo := OperatingSystem lastErrorNumber. |
|
2333 |
errString := OperatingSystem lastErrorString. |
|
2334 |
errString size == 0 ifTrue:[ |
|
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2335 |
errString := ''. |
4820 | 2336 |
] ifFalse:[ |
6662
250ea1d04a4a
errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents:
6556
diff
changeset
|
2337 |
errString := ' (' , errString , ')' |
4820 | 2338 |
]. |
2339 |
||
615 | 2340 |
^ OperatingSystem accessDeniedErrorSignal |
13139 | 2341 |
raiseRequestWith:filename ? self |
2342 |
errorString:(' : ' , (filename ? self) asString , errString) |
|
4820 | 2343 |
|
2344 |
"Modified: / 26.9.1999 / 16:11:44 / cg" |
|
615 | 2345 |
! |
2346 |
||
2347 |
fileCreationError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2348 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2349 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2350 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2351 |
|
615 | 2352 |
^ OperatingSystem accessDeniedErrorSignal |
13139 | 2353 |
raiseRequestWith:filename?self |
15455 | 2354 |
errorString:(' - cannot create/write file: "%1"' bindWith:(filename ? self) asString) |
542 | 2355 |
! |
2356 |
||
2357 |
fileNotFoundError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2358 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2359 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2360 |
"report an error that some file was not found" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2361 |
|
542 | 2362 |
^ OperatingSystem fileNotFoundErrorSignal |
13139 | 2363 |
raiseRequestWith:filename?self |
2364 |
errorString:('file not found: ' , (filename ? self) asString) |
|
542 | 2365 |
! |
2366 |
||
2367 |
removeError:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2368 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2369 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2370 |
"report an error that some file could not be removed" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2371 |
|
542 | 2372 |
^ OperatingSystem accessDeniedErrorSignal |
13139 | 2373 |
raiseRequestWith:filename?self |
2374 |
errorString:('cannot remove: ' , (filename?self) asString) |
|
615 | 2375 |
! |
2376 |
||
2377 |
reportError:string with:filename |
|
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2378 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2379 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2380 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2381 |
|
15192 | 2382 |
^ OsError |
13139 | 2383 |
raiseRequestWith:filename?self |
9453 | 2384 |
errorString:string |
615 | 2385 |
! ! |
2386 |
||
2387 |
!Filename methodsFor:'file access'! |
|
2388 |
||
3015 | 2389 |
appendStream |
2390 |
"return a stream for appending to the file represented by the receiver. |
|
2391 |
If the file does not already exist, it is created. |
|
2392 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
2393 |
||
2394 |
^ self appendingWriteStream |
|
2395 |
! |
|
2396 |
||
615 | 2397 |
appendingWriteStream |
2398 |
"return a stream for appending to the file represented by the receiver. |
|
5720 | 2399 |
If the file does not already exist, it is created; |
2400 |
if it does exist, writes are appended at the end." |
|
615 | 2401 |
|
2947 | 2402 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
5720 | 2403 |
|
2404 |
" |
|
2405 |
|s| |
|
2406 |
||
2407 |
s := '/tmp/foo' asFilename writeStream. |
|
2408 |
s nextPutAll:'1234567890'. |
|
2409 |
s close. |
|
2410 |
||
2411 |
s := '/tmp/foo' asFilename appendingWriteStream. |
|
2412 |
s nextPutAll:'abcdef'. |
|
2413 |
s close. |
|
2414 |
||
2415 |
'/tmp/foo' asFilename contents |
|
2416 |
" |
|
615 | 2417 |
! |
2418 |
||
15490 | 2419 |
existingReadWriteStream |
2420 |
"return a stream for read/write the file represented by the receiver. |
|
2421 |
If the file does not already exist, an exception is raised." |
|
2422 |
||
2423 |
^ FileStream oldFileNamed:(self osNameForAccess) |
|
2424 |
||
2425 |
" |
|
2426 |
'/tmp/blaFaselQuall666666' asFilename remove. |
|
2427 |
'/tmp/blaFaselQuall666666' asFilename existingReadWriteStream. |
|
2428 |
" |
|
2429 |
" |
|
2430 |
|s| |
|
2431 |
s := '/tmp/foo' asFilename readWriteStream. |
|
2432 |
s nextPutAll:'1234567890'; close. |
|
2433 |
s := '/tmp/foo' asFilename existingReadWriteStream. |
|
2434 |
s nextPutAll:'abcdef'; close. |
|
2435 |
||
2436 |
'/tmp/foo' asFilename contents inspect. |
|
2437 |
'/tmp/foo' asFilename remove |
|
2438 |
" |
|
2439 |
! |
|
2440 |
||
615 | 2441 |
newReadWriteStream |
2442 |
"return a stream for read/write the file represented by the receiver. |
|
5720 | 2443 |
If the file does not already exist, it is created; |
2444 |
if it does exist, it is truncated." |
|
615 | 2445 |
|
2947 | 2446 |
^ FileStream newFileNamed:(self osNameForAccess) |
5720 | 2447 |
|
2448 |
" |
|
2449 |
|s| |
|
2450 |
||
2451 |
s := '/tmp/foo' asFilename writeStream. |
|
2452 |
s nextPutAll:'1234567890'. |
|
2453 |
s close. |
|
2454 |
||
2455 |
s := '/tmp/foo' asFilename newReadWriteStream. |
|
2456 |
s nextPutAll:'12345'. |
|
2457 |
s close. |
|
2458 |
||
2459 |
'/tmp/foo' asFilename contents |
|
2460 |
" |
|
615 | 2461 |
! |
2462 |
||
15459 | 2463 |
openWithMode:anArrayOrString |
2464 |
"return a stream for read/write the file represented by the receiver. |
|
2465 |
If the file does not already exist, it is created; |
|
2466 |
if it does exist, it is truncated." |
|
2467 |
||
2468 |
^ FileStream open:self osNameForAccess withMode:anArrayOrString |
|
2469 |
||
2470 |
" |
|
2471 |
|s| |
|
2472 |
||
2473 |
s := '/tmp/foo' asFilename openWithMode:'r+'. |
|
2474 |
s nextPutAll:'1234567890'. |
|
2475 |
s close. |
|
2476 |
||
2477 |
||
2478 |
'/tmp/foo' asFilename contents |
|
2479 |
" |
|
2480 |
! |
|
2481 |
||
615 | 2482 |
readStream |
2483 |
"return a stream for reading from the file represented by the receiver. |
|
7828 | 2484 |
Raises an error if the file does not exist." |
615 | 2485 |
|
2947 | 2486 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 2487 |
|
2488 |
" |
|
2489 |
'/tmp/foo' asFilename readStream |
|
2490 |
" |
|
2491 |
! |
|
2492 |
||
2493 |
readWriteStream |
|
2494 |
"return a stream for read/write the file represented by the receiver. |
|
7828 | 2495 |
If the file does not already exist, it is created. |
2496 |
If the file does exist, it is NOT truncated, but rewritten at the beginning." |
|
615 | 2497 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2498 |
^ FileStream fileNamed:(self osNameForAccess) |
5720 | 2499 |
|
2500 |
" |
|
2501 |
|s| |
|
2502 |
||
2503 |
s := '/tmp/foo' asFilename writeStream. |
|
2504 |
s nextPutAll:'1234567890'. |
|
2505 |
s close. |
|
2506 |
||
7828 | 2507 |
s := '/tmp/foo' asFilename readWriteStream. |
5720 | 2508 |
s nextPutAll:'abcdef'. |
2509 |
s close. |
|
2510 |
||
2511 |
'/tmp/foo' asFilename contents |
|
7828 | 2512 |
'/tmp/foo' asFilename remove |
5720 | 2513 |
" |
615 | 2514 |
! |
2515 |
||
2516 |
writeStream |
|
2517 |
"return a stream for writing to the file represented by the receiver. |
|
5720 | 2518 |
If the file does not already exist, it is created; |
2519 |
if it does exist, it is truncated." |
|
615 | 2520 |
|
2947 | 2521 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 2522 |
|
2523 |
" |
|
2524 |
'/tmp/foo' asFilename writeStream |
|
2525 |
" |
|
5720 | 2526 |
|
2527 |
" |
|
2528 |
|s| |
|
2529 |
||
2530 |
s := '/tmp/foo' asFilename writeStream. |
|
2531 |
s nextPutAll:'1234567890'. |
|
2532 |
s close. |
|
2533 |
||
2534 |
s := '/tmp/foo' asFilename writeStream. |
|
2535 |
s nextPutAll:'12345'. |
|
2536 |
s close. |
|
2537 |
||
2538 |
'/tmp/foo' asFilename contents |
|
2539 |
" |
|
615 | 2540 |
! ! |
2541 |
||
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2542 |
!Filename methodsFor:'file access - migration'! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2543 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2544 |
appendingWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2545 |
"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
|
2546 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2547 |
if it does exist, writes are appended at the end. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2548 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2549 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2550 |
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
|
2551 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2552 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2553 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2554 |
FileStream appendingOldFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2555 |
] on:FileStream openErrorSignal do:[:ex| nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2556 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2557 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2558 |
newReadWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2559 |
"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
|
2560 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2561 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2562 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2563 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2564 |
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
|
2565 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2566 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2567 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2568 |
FileStream newFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2569 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2570 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2571 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2572 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2573 |
"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
|
2574 |
If the file does not already exist, nil is returned. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2575 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2576 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2577 |
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
|
2578 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2579 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2580 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2581 |
FileStream readonlyFileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2582 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2583 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2584 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2585 |
'/tmp/foo' asFilename readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2586 |
'/tmp/foo' asFilename readStream |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2587 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2588 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2589 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2590 |
readWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2591 |
"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
|
2592 |
If the file does not already exist, it is created. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2593 |
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
|
2594 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2595 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2596 |
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
|
2597 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2598 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2599 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2600 |
FileStream fileNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2601 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2602 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2603 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2604 |
writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2605 |
"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
|
2606 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2607 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2608 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2609 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2610 |
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
|
2611 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2612 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2613 |
^ [ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2614 |
FileStream newFileForWritingNamed:(self osNameForAccess) |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2615 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2616 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2617 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2618 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2619 |
'/etc/foo' asFilename writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2620 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2621 |
! ! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2622 |
|
16310 | 2623 |
!Filename methodsFor:'file access rights'! |
615 | 2624 |
|
12529 | 2625 |
accessRights |
2626 |
"return the access rights of the file as opaque data |
|
2627 |
(SmallInteger in unix/linux)" |
|
2628 |
||
2629 |
^ OperatingSystem accessModeOf:self osNameForFile. |
|
2630 |
||
2631 |
" |
|
2632 |
'Make.proto' asFilename accessRights |
|
2633 |
" |
|
2634 |
! |
|
2635 |
||
2636 |
accessRights:opaqueData |
|
2637 |
"set the access rights of the file to opaqueData, |
|
2638 |
which is normally retrieved by Filename>>#accessRights." |
|
2639 |
||
2640 |
(OperatingSystem changeAccessModeOf:self osNameForFile to:opaqueData) ifFalse:[ |
|
2641 |
^ self accessDeniedError:self |
|
2642 |
]. |
|
2643 |
||
2644 |
" |
|
2645 |
|rights| |
|
2646 |
||
2647 |
rights := 'Make.proto' asFilename accessRights. |
|
2648 |
'Make.proto' asFilename accessRights:rights. |
|
2649 |
" |
|
2650 |
||
2651 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2652 |
! |
|
2653 |
||
615 | 2654 |
addAccessRights:aCollection |
2655 |
"add the access rights as specified in aCollection for the file represented |
|
2656 |
by the receiver. The argument must be a collection of symbols, |
|
2657 |
such as #readUser, #writeGroup etc." |
|
2658 |
||
2922 | 2659 |
|access osName| |
2660 |
||
2947 | 2661 |
osName := self osNameForFile. |
2922 | 2662 |
access := OperatingSystem accessModeOf:osName. |
615 | 2663 |
aCollection do:[:accessSymbol | |
9453 | 2664 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
615 | 2665 |
]. |
2922 | 2666 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
9453 | 2667 |
^ self accessDeniedError:self |
615 | 2668 |
] |
2669 |
||
2670 |
" |
|
2671 |
'foo' asFilename writeStream close. |
|
2672 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
2673 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
2674 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
2675 |
" |
|
2676 |
! |
|
2677 |
||
6223 | 2678 |
makeExecutable |
2679 |
"make the file executable - you must have permission to do so. |
|
2680 |
For directories, execution means: 'allow changing into it'" |
|
2681 |
||
2682 |
^ self addAccessRights:#(executeUser) |
|
2683 |
||
2684 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
2685 |
! |
|
2686 |
||
2687 |
makeExecutableForAll |
|
2688 |
"make the file executable for all - you must have permission to do so. |
|
2689 |
For directories, execution means: 'allow changing into it'" |
|
2690 |
||
2691 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
2692 |
||
2693 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
2694 |
! |
|
2695 |
||
2696 |
makeExecutableForGroup |
|
2697 |
"make the file executable for the group - you must have permission to do so. |
|
2698 |
For directories, execution means: 'allow changing into it'" |
|
2699 |
||
2700 |
^ self addAccessRights:#(executeGroup) |
|
2701 |
||
2702 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
2703 |
! |
|
2704 |
||
2705 |
makeReadable |
|
2706 |
"make the file readable for the owner - you must have permission to do so." |
|
2707 |
||
2708 |
^ self addAccessRights:#(readUser) |
|
2709 |
! |
|
2710 |
||
2711 |
makeReadableForAll |
|
2712 |
"make the file readable for all - you must have permission to do so." |
|
2713 |
||
2714 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
2715 |
! |
|
2716 |
||
2717 |
makeReadableForGroup |
|
2718 |
"make the file readable for the group - you must have permission to do so." |
|
2719 |
||
2720 |
^ self addAccessRights:#(readGroup) |
|
2721 |
! |
|
2722 |
||
2723 |
makeUnwritable |
|
2724 |
"make the file unwritable for all - you must have permission to do so." |
|
2725 |
||
2726 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
2727 |
! |
|
2728 |
||
2729 |
makeWritable |
|
2730 |
"make the file writableable for all - you must have permission to do so." |
|
2731 |
||
2732 |
^ self addAccessRights:#(writeUser) |
|
2733 |
! |
|
2734 |
||
2735 |
makeWritableForAll |
|
2736 |
"make the file writable for all - you must have permission to do so." |
|
2737 |
||
2738 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
2739 |
! |
|
2740 |
||
2741 |
makeWritableForGroup |
|
2742 |
"make the file writable for the group - you must have permission to do so." |
|
2743 |
||
2744 |
^ self addAccessRights:#(writeGroup) |
|
2745 |
! |
|
2746 |
||
2747 |
removeAccessRights:aCollection |
|
2748 |
"remove the access rights as specified in aCollection for the file represented |
|
2749 |
by the receiver. The argument must be a collection of symbols, |
|
2750 |
such as #readUser, #writeGroup etc. |
|
2751 |
Raises an exception if not successful." |
|
2752 |
||
2753 |
|access osName| |
|
2754 |
||
2755 |
osName := self osNameForFile. |
|
2756 |
access := OperatingSystem accessModeOf:osName. |
|
2757 |
aCollection do:[:accessSymbol | |
|
9453 | 2758 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
6223 | 2759 |
]. |
2760 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
|
9453 | 2761 |
^ self accessDeniedError:self |
6223 | 2762 |
]. |
2763 |
||
2764 |
" |
|
2765 |
'foo' asFilename writeStream close. |
|
2766 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
2767 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
2768 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
2769 |
" |
|
2770 |
||
2771 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2772 |
! |
|
2773 |
||
2774 |
symbolicAccessRights |
|
2775 |
"return the access rights of the file as a aCollection of access symbols. |
|
2776 |
The returned collection consists of symbols like: |
|
2777 |
#readUser, #writeGroup etc." |
|
2778 |
||
2779 |
|access osName| |
|
2780 |
||
2781 |
osName := self osNameForFile. |
|
2782 |
access := OperatingSystem accessModeOf:osName. |
|
2783 |
||
2784 |
^ |
|
2785 |
#( readUser writeUser executeUser |
|
2786 |
readGroup writeGroup executeGroup |
|
2787 |
readOthers writeOthers executeOthers |
|
2788 |
) select:[:eachSymbolicAccessSymbol | |
|
2789 |
access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol). |
|
2790 |
]. |
|
2791 |
||
2792 |
" |
|
2793 |
'Makefile' asFilename symbolicAccessRights |
|
2794 |
" |
|
2795 |
||
2796 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2797 |
! |
|
2798 |
||
2799 |
symbolicAccessRights:aCollectionOfSymbols |
|
2800 |
"set the access rights of the file given a aCollection of access symbols. |
|
2801 |
The collection must consist of symbols like: |
|
2802 |
#readUser, #writeGroup etc." |
|
2803 |
||
2804 |
|access osName| |
|
2805 |
||
2806 |
osName := self osNameForFile. |
|
2807 |
access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol | |
|
2808 |
bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol) |
|
2809 |
]. |
|
2810 |
||
2811 |
(OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[ |
|
2812 |
^ self accessDeniedError:self |
|
2813 |
]. |
|
2814 |
||
2815 |
" |
|
2816 |
|rights| |
|
2817 |
||
2818 |
rights := 'Makefile' asFilename symbolicAccessRights. |
|
2819 |
'Makefile' asFilename symbolicAccessRights:(rights , #(executeOthers)). |
|
2820 |
" |
|
2821 |
||
2822 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
2823 |
! ! |
|
2824 |
||
2825 |
!Filename methodsFor:'file operations'! |
|
2826 |
||
7329 | 2827 |
appendTo:newNameOrStream |
2828 |
"append the file - the argument must be convertable to a filename. |
|
2829 |
Raises an exception, if an error occurs." |
|
2830 |
||
2831 |
|inStream outStream outStreamToClose| |
|
2832 |
||
2833 |
inStream := self readStream. |
|
2834 |
[ |
|
2835 |
newNameOrStream isStream ifTrue:[ |
|
2836 |
outStream := newNameOrStream. |
|
2837 |
] ifFalse:[ |
|
2838 |
outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream. |
|
2839 |
]. |
|
2840 |
||
8769 | 2841 |
inStream binary. |
2842 |
outStream binary. |
|
2843 |
||
7329 | 2844 |
[ |
2845 |
inStream copyToEndInto:outStream. |
|
15192 | 2846 |
] on:OsError do:[:ex| |
7329 | 2847 |
^ self fileCreationError:newNameOrStream |
2848 |
] |
|
2849 |
] ensure:[ |
|
2850 |
inStream close. |
|
2851 |
outStreamToClose notNil ifTrue:[outStreamToClose close]. |
|
2852 |
]. |
|
2853 |
||
2854 |
" |
|
2855 |
'/etc/group' asFilename appendTo:'/tmp/Makefile.foo'. |
|
2856 |
'Makefile' asFilename appendTo:'/tmp/Makefile.foo' |
|
2857 |
'Makefile' asFilename copyTo:'/' |
|
2858 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
2859 |
" |
|
2860 |
||
2861 |
"Modified: / 23.12.1999 / 21:52:36 / cg" |
|
2862 |
! |
|
2863 |
||
2982 | 2864 |
basicMakeDirectory |
2865 |
"create a directory with the receivers name. |
|
2866 |
Return true if successful, false if not." |
|
2867 |
||
2868 |
^ OperatingSystem createDirectory:(self osNameForDirectory) |
|
2869 |
! |
|
2870 |
||
10020 | 2871 |
copyTo:newNameArg |
16578 | 2872 |
"Copy the file's contents into another file. |
9235 | 2873 |
The argument must be convertable to a filename. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2874 |
Raises an exception, if an error occurs." |
615 | 2875 |
|
12529 | 2876 |
|newName inStream outStream newNameAlreadyExists| |
10020 | 2877 |
|
2878 |
newName := newNameArg asFilename. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2879 |
|
8535 | 2880 |
"Contents is not copied if newName represent same file as me." |
10020 | 2881 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
8535 | 2882 |
|
615 | 2883 |
inStream := self readStream. |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2884 |
[ |
12529 | 2885 |
newNameAlreadyExists := newName exists. |
10020 | 2886 |
outStream := newName writeStream. |
12529 | 2887 |
newNameAlreadyExists ifFalse:[ |
15823 | 2888 |
[ |
2889 |
"would be nice to keep the access rights of the original test suite" |
|
2890 |
newName accessRights:self accessRights. |
|
2891 |
] on:OperatingSystem accessDeniedErrorSignal do:[:ex| |
|
2892 |
"ignore the error - may occure when copying to a network drive" |
|
2893 |
]. |
|
12529 | 2894 |
]. |
16492 | 2895 |
inStream binary; buffered:false. |
15846 | 2896 |
outStream binary; buffered:false. |
2897 |
inStream copyToEndInto:outStream. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2898 |
] ensure:[ |
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
2899 |
inStream close. |
14759 | 2900 |
outStream notNil ifTrue:[outStream syncData; close]. |
615 | 2901 |
]. |
2902 |
||
2903 |
" |
|
12529 | 2904 |
'Make.proto' asFilename copyTo:'/tmp/Makefile.foo' |
2905 |
'Make.proto' asFilename copyTo:'/' |
|
615 | 2906 |
'smalltalk' asFilename copyTo:'/dev/null' |
2907 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2908 |
|
10020 | 2909 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
2910 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
615 | 2911 |
! |
2912 |
||
15465 | 2913 |
copyToStream:outStream |
16578 | 2914 |
"Copy the file's contents into another file. |
15465 | 2915 |
The argument must be convertable to a filename. |
2916 |
Raises an exception, if an error occurs." |
|
2917 |
||
15858 | 2918 |
|inStream resetBinary| |
15465 | 2919 |
|
2920 |
"Contents is not copied if newName represent same file as me." |
|
2921 |
outStream isFileStream ifTrue:[ |
|
2922 |
outStream fileName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
|
2923 |
]. |
|
2924 |
||
2925 |
inStream := self readStream. |
|
2926 |
[ |
|
16485 | 2927 |
inStream binary"; buffered:false". |
15465 | 2928 |
resetBinary := false. |
2929 |
outStream isBinary ifFalse:[ |
|
2930 |
outStream binary. |
|
2931 |
resetBinary := true. |
|
2932 |
]. |
|
15858 | 2933 |
inStream copyToEndInto:outStream. |
15465 | 2934 |
] ensure:[ |
2935 |
inStream close. |
|
2936 |
resetBinary ifTrue:[ |
|
2937 |
outStream text. |
|
2938 |
]. |
|
2939 |
]. |
|
2940 |
||
2941 |
" |
|
2942 |
|out| |
|
2943 |
out := FileStream newTemporary. |
|
2944 |
'Make.proto' asFilename copyToStream:out. |
|
2945 |
out reset; contents |
|
2946 |
" |
|
2947 |
! |
|
2948 |
||
6983 | 2949 |
createAsEmptyFile |
2950 |
"create an empty file with the receivers name. |
|
2951 |
Raises an exception if not successful |
|
2952 |
(either already existing or creation not possible)" |
|
2953 |
||
2954 |
|writeStream| |
|
2955 |
||
2956 |
self exists ifTrue:[ |
|
2957 |
OperatingSystem accessDeniedErrorSignal |
|
2958 |
raiseRequestWith:self |
|
2959 |
errorString:(' - file exists: ' , self asString). |
|
2960 |
^ self |
|
2961 |
]. |
|
2962 |
||
2963 |
FileStream openErrorSignal handle:[:ex| |
|
2964 |
self fileCreationError:self. |
|
2965 |
^ self |
|
2966 |
] do:[ |
|
2967 |
writeStream := self newReadWriteStream. |
|
2968 |
]. |
|
2969 |
writeStream close. |
|
2970 |
! |
|
2971 |
||
615 | 2972 |
delete |
2973 |
"remove the file - same as remove, for ST-80 compatibility" |
|
2974 |
||
2975 |
self remove |
|
2976 |
! |
|
2977 |
||
2978 |
makeDirectory |
|
2979 |
"create a directory with the receivers name. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2980 |
Raises an exception if not successful" |
615 | 2981 |
|
2982 | 2982 |
(self basicMakeDirectory) ifFalse:[ |
9453 | 2983 |
"/ |
2984 |
"/ could have existed before ... |
|
2985 |
"/ |
|
2986 |
(self exists and:[self isDirectory]) ifFalse:[ |
|
2987 |
self fileCreationError:self. |
|
2988 |
^ false |
|
2989 |
] |
|
2982 | 2990 |
]. |
2991 |
^ true |
|
1970 | 2992 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
2993 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 2994 |
! |
2995 |
||
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2996 |
moveFileTo:newName |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
2997 |
"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
|
2998 |
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
|
2999 |
Raise an exception if not successful. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3000 |
(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
|
3001 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3002 |
[self renameTo:newName] |
15192 | 3003 |
on:OsError |
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
3004 |
do:[:ex | |
15121
9b338c1757de
use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents:
15023
diff
changeset
|
3005 |
ex creator == OperatingSystem fileNotFoundErrorSignal ifTrue:[ |
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
3006 |
ex reject |
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
3007 |
]. |
15819 | 3008 |
self safeCopyTo:newName. |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3009 |
self remove |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3010 |
]. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3011 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3012 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3013 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3014 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3015 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3016 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3017 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3018 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3019 |
f renameTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3020 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3021 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3022 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3023 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3024 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3025 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3026 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3027 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3028 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3029 |
f moveTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3030 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3031 |
! |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3032 |
|
16490 | 3033 |
moveTo:newNameArg |
615 | 3034 |
"copy the file represented by the receiver, then delete it. |
3035 |
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
|
3036 |
Raise an exception if not successful. |
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
3037 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
615 | 3038 |
|
16490 | 3039 |
|newName| |
3040 |
||
3041 |
newName := newNameArg asFilename. |
|
6771 | 3042 |
[self renameTo:newName] |
12956 | 3043 |
on:(OSErrorHolder inappropriateReferentSignal) |
7134
764473cb4635
no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents:
7122
diff
changeset
|
3044 |
do:[:ex | |
12956 | 3045 |
"handle renames accross device boundaries (Unix. cross device link)" |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
3046 |
self isDirectory ifTrue:[ |
6997 | 3047 |
self recursiveMoveDirectoryTo:newName. |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
3048 |
] ifFalse:[ |
15819 | 3049 |
self safeCopyTo:newName. |
12956 | 3050 |
self remove. |
6995
a7650ef2b1be
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6983
diff
changeset
|
3051 |
]. |
6771 | 3052 |
]. |
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3053 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3054 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3055 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3056 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3057 |
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
|
3058 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3059 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3060 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3061 |
f renameTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3062 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3063 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3064 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3065 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3066 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3067 |
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
|
3068 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3069 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3070 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3071 |
f moveTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3072 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3073 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3074 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3075 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3076 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3077 |
Otherwise, copy the directory and recursively |
12975 | 3078 |
all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3079 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3080 |
|
4245
610136f7e16b
recursive copy of directories
Claus Gittinger <cg@exept.de>
parents:
4199
diff
changeset
|
3081 |
|ok d| |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3082 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3083 |
self isDirectory ifFalse:[ |
9453 | 3084 |
d := destination asFilename. |
12529 | 3085 |
d isDirectory ifTrue:[ |
9453 | 3086 |
d := d construct:self baseName. |
3087 |
]. |
|
12529 | 3088 |
self copyTo:d. |
3089 |
^ self. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3090 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3091 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3092 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3093 |
"/ 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
|
3094 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3095 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3096 |
ok := OperatingSystem |
9453 | 3097 |
recursiveCopyDirectory:(self osNameForDirectory) |
3098 |
to:(destination asFilename osNameForDirectory). |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3099 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3100 |
ok ifFalse:[ |
9453 | 3101 |
self recursiveCopyWithoutOSCommandTo:destination |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3102 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3103 |
|
12975 | 3104 |
"Created: / 05-05-1999 / 13:35:01 / cg" |
3105 |
"Modified: / 31-05-1999 / 13:11:34 / cg" |
|
3106 |
"Modified: / 29-07-2010 / 12:41:06 / sr" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3107 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3108 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3109 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3110 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3111 |
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
|
3112 |
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
|
3113 |
Raises an exception if not successful." |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3114 |
|
12529 | 3115 |
|destinationFilename| |
3116 |
||
3117 |
destinationFilename := destination asFilename. |
|
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 |
self isDirectory ifTrue:[ |
12529 | 3120 |
destinationFilename exists ifTrue:[ |
3121 |
destinationFilename := destinationFilename construct:self baseName. |
|
3122 |
destinationFilename makeDirectory. |
|
3123 |
] ifFalse:[ |
|
3124 |
destinationFilename makeDirectory. |
|
3125 |
destinationFilename accessRights:self accessRights. |
|
11192
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
3126 |
]. |
12529 | 3127 |
|
9453 | 3128 |
self directoryContents do:[:aFilenameString | |
3129 |
|src dst| |
|
3130 |
||
3131 |
src := self construct:aFilenameString. |
|
3132 |
src isDirectory ifTrue:[ |
|
3133 |
src recursiveCopyWithoutOSCommandTo:destinationFilename |
|
3134 |
] ifFalse:[ |
|
3135 |
src copyTo:(destinationFilename construct:aFilenameString) |
|
3136 |
]. |
|
3137 |
] |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3138 |
] ifFalse:[ |
12529 | 3139 |
self copyTo:destinationFilename |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3140 |
] |
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 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3143 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3144 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3145 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3146 |
|
4246 | 3147 |
"Modified: / 31.5.1999 / 18:12:31 / cg" |
615 | 3148 |
! |
3149 |
||
659 | 3150 |
recursiveMakeDirectory |
3151 |
"create a directory with the receivers name and all required intermediate |
|
3152 |
directories. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3153 |
Raises an exception if not successful." |
659 | 3154 |
|
2922 | 3155 |
(OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[ |
9453 | 3156 |
^ self fileCreationError:self |
659 | 3157 |
] |
3158 |
||
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3159 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3160 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
659 | 3161 |
! |
3162 |
||
6997 | 3163 |
recursiveMoveDirectoryTo:newName |
3164 |
"recursively copy the directory represented by the receiver, then delete it. |
|
3165 |
This is different to renaming in case of cross device moves. |
|
3166 |
Raise an exception if not successful. |
|
3167 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
|
3168 |
||
3169 |
[self renameTo:newName] |
|
15192 | 3170 |
on:OsError |
6997 | 3171 |
do:[ |
3172 |
self recursiveCopyTo:newName. |
|
3173 |
self recursiveRemove |
|
3174 |
]. |
|
3175 |
! |
|
3176 |
||
615 | 3177 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3178 |
"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
|
3179 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3180 |
Raise an exception if not successful." |
615 | 3181 |
|
3182 |
|ok| |
|
3183 |
||
3302 | 3184 |
"/ typically, an 'rm -rf' is faster and removes better; |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3185 |
"/ 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
|
3186 |
"/ fallBack doing a manual directory walk. |
3302 | 3187 |
|
3188 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
3189 |
ok ifFalse:[ |
|
9453 | 3190 |
self recursiveRemoveWithoutOSCommand |
3302 | 3191 |
]. |
3192 |
||
3193 |
" |
|
3194 |
'foo' asFilename makeDirectory. |
|
3195 |
'foo/bar' asFilename writeStream close. |
|
3196 |
('foo' asFilename remove) ifFalse:[ |
|
9453 | 3197 |
Transcript showCR:'could not remove foo' |
3302 | 3198 |
] |
3199 |
" |
|
3200 |
" |
|
3201 |
'foo' asFilename makeDirectory. |
|
3202 |
'foo/bar' asFilename writeStream close. |
|
3203 |
('foo' asFilename recursiveRemove) ifFalse:[ |
|
9453 | 3204 |
Transcript showCR:'could not remove foo' |
3302 | 3205 |
] |
3206 |
" |
|
3207 |
||
3208 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3209 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 3210 |
! |
3211 |
||
13246 | 3212 |
recursiveRemoveAll |
13247
9e47a0e73ba4
comment/format in: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13246
diff
changeset
|
3213 |
"Remove all of my subfiles/subdirectories. |
3302 | 3214 |
Raise an error if not successful. |
3215 |
This one walks down the directory hierarchy, not using any OS |
|
3216 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3217 |
|
4939 | 3218 |
|files| |
3219 |
||
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3220 |
self isDirectory ifTrue:[ |
9453 | 3221 |
(files := self directoryContents) size > 0 ifTrue:[ |
3222 |
files do:[:aFilenameString | |
|
3223 |
|f| |
|
3224 |
||
3225 |
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
|
3226 |
Error handle:[:ex | |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3227 |
f isDirectory ifFalse:[ ex reject ]. |
15298 | 3228 |
|
13949 | 3229 |
f recursiveRemoveAll. |
3230 |
f removeDirectory |
|
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3231 |
] do:[ |
9453 | 3232 |
f remove |
3233 |
]. |
|
10362
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3234 |
|
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3235 |
"/ f isDirectory ifTrue:[ |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3236 |
"/ f recursiveRemoveWithoutOSCommand |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3237 |
"/ ] ifFalse:[ |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3238 |
"/ f remove |
ed621d39a311
when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents:
10271
diff
changeset
|
3239 |
"/ ]. |
9453 | 3240 |
]. |
3241 |
] |
|
615 | 3242 |
]. |
13246 | 3243 |
|
3244 |
" |
|
3245 |
'foo' asFilename makeDirectory. |
|
3246 |
'foo/bar' asFilename writeStream close. |
|
3247 |
'foo' asFilename remove |
|
3248 |
" |
|
3249 |
" |
|
3250 |
'foo' asFilename makeDirectory. |
|
3251 |
'foo/bar' asFilename writeStream close. |
|
3252 |
'foo' asFilename recursiveRemove |
|
3253 |
" |
|
3254 |
||
3255 |
"Created: / 25-01-2011 / 16:42:15 / cg" |
|
3256 |
! |
|
3257 |
||
3258 |
recursiveRemoveWithoutOSCommand |
|
3259 |
"if I represent a regular file, remove it. |
|
3260 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
3261 |
Raise an error if not successful. |
|
3262 |
This one walks down the directory hierarchy, not using any OS |
|
3263 |
command to do the remove." |
|
3264 |
||
15303 | 3265 |
self |
3266 |
recursiveRemoveAll; |
|
3267 |
remove. |
|
615 | 3268 |
|
3269 |
" |
|
3270 |
'foo' asFilename makeDirectory. |
|
3271 |
'foo/bar' asFilename writeStream close. |
|
4940 | 3272 |
'foo' asFilename remove |
615 | 3273 |
" |
3274 |
" |
|
3275 |
'foo' asFilename makeDirectory. |
|
3276 |
'foo/bar' asFilename writeStream close. |
|
4940 | 3277 |
'foo' asFilename recursiveRemove |
615 | 3278 |
" |
3279 |
||
13246 | 3280 |
"Created: / 25-02-1998 / 19:50:40 / cg" |
13949 | 3281 |
"Modified: / 19-01-2012 / 17:18:28 / cg" |
615 | 3282 |
! |
3283 |
||
3284 |
remove |
|
845 | 3285 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3286 |
Raises an exception if not successful. |
845 | 3287 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 3288 |
|
8741 | 3289 |
|linkInfo osName ok| |
3290 |
||
3291 |
osName := self osNameForFile. |
|
13793
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3292 |
(ok := OperatingSystem removeFile:osName) ifFalse:[ |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3293 |
linkInfo := self linkInfo. |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3294 |
(linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[ |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3295 |
ok := OperatingSystem removeDirectory:osName |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3296 |
]. |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3297 |
ok ifFalse:[ |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3298 |
self exists ifTrue:[ |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3299 |
self removeError:self |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3300 |
] |
6392
f3c2c3edf2c8
do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents:
6383
diff
changeset
|
3301 |
] |
615 | 3302 |
]. |
3303 |
||
3304 |
" |
|
3305 |
(FileStream newFileNamed:'foo') close. |
|
3306 |
'foo' asFilename remove |
|
3307 |
" |
|
3308 |
||
3309 |
" |
|
3310 |
'foo' asFilename makeDirectory. |
|
3311 |
'foo/bar' asFilename writeStream close. |
|
8738 | 3312 |
'foo' asFilename remove. 'expect an exception' |
3313 |
'foo' asFilename recursiveRemove. |
|
615 | 3314 |
" |
3315 |
||
13793
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3316 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3317 |
"Modified: / 11-10-2011 / 10:20:01 / cg" |
615 | 3318 |
! |
3319 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3320 |
removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3321 |
"remove the directory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3322 |
Raises an exception if not successful (or if its not a directory). |
5596 | 3323 |
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
|
3324 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3325 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3326 |
|ok| |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3327 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3328 |
ok := OperatingSystem removeDirectory:(self osNameForFile). |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3329 |
ok ifFalse:[ |
9453 | 3330 |
self exists ifFalse:[ ^ self]. |
3331 |
self removeError:self |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3332 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3333 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3334 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3335 |
(FileStream newFileNamed:'foo') close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3336 |
'foo' asFilename removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3337 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3338 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3339 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3340 |
'foo' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3341 |
'foo' asFilename removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3342 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3343 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3344 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3345 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3346 |
'foo/bar' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3347 |
('foo' asFilename remove) ifFalse:[ |
9453 | 3348 |
Transcript showCR:'could not remove foo' |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3349 |
] |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3350 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3351 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3352 |
"Modified: / 20.11.1997 / 17:40:22 / stefan" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3353 |
"Modified: / 5.5.1999 / 13:41:12 / cg" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3354 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3355 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3356 |
removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3357 |
"remove the file. |
5596 | 3358 |
Raises an exception if not successful (or if its not a file). |
3359 |
Use #remove if it is not known if the receiver is a directory or file. |
|
3360 |
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
|
3361 |
|
8738 | 3362 |
(OperatingSystem removeFile:self osNameForFile) ifFalse:[ |
3363 |
self exists ifTrue:[ |
|
3364 |
self removeError:self |
|
3365 |
]. |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3366 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3367 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3368 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3369 |
(FileStream newFileNamed:'foo') close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3370 |
'foo' asFilename removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3371 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3372 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3373 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3374 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3375 |
'foo' asFilename removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3376 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3377 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3378 |
|
16490 | 3379 |
renameTo:newNameArg |
671 | 3380 |
"rename the file - the argument must be convertable to a String. |
15823 | 3381 |
Raises an exception if not successful. |
3382 |
If newName already exists, it will be replaced by myself." |
|
615 | 3383 |
|
16490 | 3384 |
|errno newName| |
3385 |
||
3386 |
newName := newNameArg asFilename. |
|
2922 | 3387 |
(OperatingSystem |
9453 | 3388 |
renameFile:(self osNameForFile) |
16490 | 3389 |
to:(newName osNameForFile) |
2922 | 3390 |
) ifFalse:[ |
12318 | 3391 |
errno := OperatingSystem lastErrorNumber. |
3392 |
||
9453 | 3393 |
self exists ifFalse:[ |
3394 |
^ self fileNotFoundError:self |
|
3395 |
]. |
|
12956 | 3396 |
(OperatingSystem errorHolderForNumber:errno) |
16490 | 3397 |
parameter:newName; |
12956 | 3398 |
reportError. |
615 | 3399 |
]. |
3400 |
||
3401 |
" |
|
3402 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
3403 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3404 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3405 |
"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
|
3406 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3407 |
|
15819 | 3408 |
safeCopyTo:newNameArg |
16578 | 3409 |
"Copy the file's contents into another file. |
15819 | 3410 |
Do it safe in an atomic operation shich makes sure that no partially written file appears. |
3411 |
The argument must be convertable to a filename. |
|
3412 |
Raises an exception, if an error occurs." |
|
3413 |
||
15823 | 3414 |
|newName inStream accessRights tempStream| |
15819 | 3415 |
|
3416 |
newName := newNameArg asFilename. |
|
3417 |
||
3418 |
"Contents is not copied if newName represent same file as me." |
|
3419 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
|
3420 |
||
3421 |
inStream := self readStream. |
|
15823 | 3422 |
newName exists ifTrue:[ |
15819 | 3423 |
accessRights := newName accessRights. |
3424 |
] ifFalse:[ |
|
3425 |
accessRights := self accessRights. |
|
3426 |
]. |
|
3427 |
||
3428 |
[ |
|
3429 |
"let the temp filename start with a ~ to make it invisible" |
|
16490 | 3430 |
tempStream := FileStream newTemporaryIn:newName directory osNameForFile nameTemplate:'~%1_%2'. |
15823 | 3431 |
[ |
16676 | 3432 |
"would be nice to keep the access rights of the original file" |
15824 | 3433 |
tempStream fileName accessRights:accessRights. |
15823 | 3434 |
] on:OperatingSystem accessDeniedErrorSignal do:[:ex| |
3435 |
"ignore the error - may occure when copying to a network drive" |
|
3436 |
]. |
|
15819 | 3437 |
|
16492 | 3438 |
inStream binary; buffered:false. |
15846 | 3439 |
tempStream binary; buffered:false. |
15819 | 3440 |
[ |
3441 |
inStream copyToEndInto:tempStream. |
|
15846 | 3442 |
] ifCurtailed:[ |
3443 |
tempStream close. |
|
3444 |
tempStream fileName remove. |
|
3445 |
tempStream := nil. |
|
15819 | 3446 |
]. |
15823 | 3447 |
tempStream syncData. |
15819 | 3448 |
] ensure:[ |
3449 |
inStream close. |
|
15823 | 3450 |
tempStream notNil ifTrue:[tempStream close]. |
15819 | 3451 |
]. |
3452 |
tempStream fileName renameTo:newName. |
|
3453 |
||
3454 |
" |
|
3455 |
'Make.proto' asFilename safeCopyTo:'/tmp/Makefile.foo' |
|
3456 |
'Make.proto' asFilename safeCopyTo:'/' |
|
3457 |
'smalltalk' asFilename safeCopyTo:'/xxxxxxxxxxxxxxxx/bla' |
|
3458 |
" |
|
3459 |
||
3460 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
|
3461 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
3462 |
! |
|
3463 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3464 |
truncateTo:newSize |
16578 | 3465 |
"change the file's size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3466 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3467 |
(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
|
3468 |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3469 |
(OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3470 |
^ 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
|
3471 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3472 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3473 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3474 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3475 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3476 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3477 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3478 |
s close. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3479 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3480 |
'test' asFilename truncateTo:100. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3481 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3482 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3483 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3484 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 3485 |
! ! |
3486 |
||
3487 |
!Filename methodsFor:'file queries'! |
|
3488 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3489 |
accessTime |
16578 | 3490 |
"return a timeStamp containing the file's last access time." |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3491 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3492 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3493 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3494 |
(i := self info) isNil ifTrue:[^ nil]. |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3495 |
^ i accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3496 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3497 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3498 |
Filename currentDirectory accessTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3499 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3500 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3501 |
"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
|
3502 |
"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
|
3503 |
"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
|
3504 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3505 |
|
6977 | 3506 |
creationTime |
16578 | 3507 |
"return a timeStamp containing the file's creation time. |
6977 | 3508 |
NOTICE: only windoof distinguishes creation from modification; |
6978 | 3509 |
under unix, nil is returned (callers should fall back and use mod-time then" |
6977 | 3510 |
|
3511 |
|i| |
|
3512 |
||
3513 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
|
6978 | 3514 |
^ i creationTime |
3515 |
||
3516 |
" |
|
3517 |
Filename currentDirectory creationTime |
|
6977 | 3518 |
" |
3519 |
||
3520 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
|
3521 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
|
3522 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
|
3523 |
! |
|
3524 |
||
615 | 3525 |
dates |
16578 | 3526 |
"return the file's modification and access times as an object (currently a dictionary) |
615 | 3527 |
that responds to the at: message with arguments |
3528 |
#modified, #accessed or #statusChanged." |
|
3529 |
||
2922 | 3530 |
|info dates osName| |
3531 |
||
2947 | 3532 |
osName := self osNameForAccess. |
2922 | 3533 |
info := OperatingSystem infoOf:osName. |
615 | 3534 |
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
|
3535 |
"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
|
3536 |
Answer the dates of the link itself" |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3537 |
info := OperatingSystem linkInfoOf:osName. |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3538 |
info isNil ifTrue:[ |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3539 |
^ nil |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3540 |
] |
615 | 3541 |
]. |
3542 |
dates := IdentityDictionary new. |
|
6978 | 3543 |
dates at:#created put:(info creationTime). |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3544 |
dates at:#modified put:(info modificationTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3545 |
dates at:#accessed put:(info accessTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3546 |
dates at:#statusChanged put:(info statusChangeTime). |
615 | 3547 |
^ dates |
3548 |
||
3549 |
" |
|
6978 | 3550 |
Filename currentDirectory dates |
615 | 3551 |
'../regression' asFilename dates |
3552 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3553 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3554 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 3555 |
! |
3556 |
||
3557 |
fileSize |
|
3558 |
"return the size of the file in bytes" |
|
3559 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3560 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3561 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3562 |
(i := self info) isNil ifTrue:[^ nil]. |
6794
498d85323172
use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents:
6793
diff
changeset
|
3563 |
^ i fileSize |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3564 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3565 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 3566 |
! |
3567 |
||
3568 |
fileType |
|
3569 |
"this returns a string describing the type of contents of |
|
3570 |
the file. This is done using the unix 'file' command, |
|
3571 |
(which usually is configurable by /etc/magic). |
|
3665 | 3572 |
On non-unix systems, this may simply return 'file', |
2922 | 3573 |
not knowning about the contents. |
3574 |
Warning: |
|
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3575 |
Since the returned string differs among systems (and language settings), |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3576 |
it is only useful for user-information; |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3577 |
NOT as a tag to be used by a program." |
3665 | 3578 |
|
16755 | 3579 |
|suffix baseNm info mime| |
3665 | 3580 |
|
3581 |
"/ since we cannot depend on a 'file' command being available, |
|
3582 |
"/ do the most obvious ones here. |
|
3583 |
"/ (also useful since the 'file' command takes some time, and the code |
|
3584 |
"/ 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
|
3585 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3586 |
info := self linkInfo. |
9060 | 3587 |
info isNil ifTrue:[ |
3588 |
^ 'removed' "/ could happen, when coming from a snapshot image |
|
3589 |
]. |
|
3590 |
||
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3591 |
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
|
3592 |
^ 'symbolic link to ' , info path |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3593 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3594 |
info isDirectory ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3595 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3596 |
self isExecutable ifFalse:[^ 'directory, locked']. |
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3597 |
^ 'directory' |
2573 | 3598 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3599 |
info isCharacterSpecial ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3600 |
^ 'character device special file' |
3665 | 3601 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3602 |
info isBlockSpecial ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3603 |
^ 'block device special file' |
3665 | 3604 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3605 |
info isSocket ifTrue:[ |
6245
90a9f29d8075
fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6227
diff
changeset
|
3606 |
^ 'socket' |
3665 | 3607 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3608 |
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
|
3609 |
^ 'fifo' |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3610 |
]. |
3665 | 3611 |
|
1602 | 3612 |
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
|
3613 |
info fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 3614 |
|
17112 | 3615 |
"/ suffix := self suffix asLowercase. |
3616 |
"/ baseNm := self withoutSuffix baseName asLowercase. |
|
2922 | 3617 |
|
16755 | 3618 |
mime := self mimeTypeOfContents. |
3619 |
mime notNil ifTrue:[ |
|
3620 |
"/ kludge to avoid making libview a prereq. of libbasic |
|
3621 |
(Smalltalk at:#MIMETypes) notNil ifTrue:[ |
|
3622 |
info := (Smalltalk at:#MIMETypes) fileInfoForMimeType:mime. |
|
3623 |
info notNil ifTrue:[^ info]. |
|
3624 |
]. |
|
1602 | 3625 |
]. |
2906 | 3626 |
^ 'file' |
615 | 3627 |
|
3628 |
" |
|
3629 |
'Makefile' asFilename fileType |
|
3630 |
'.' asFilename fileType |
|
3665 | 3631 |
'/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
|
3632 |
'/usr/tmp' asFilename fileType |
3665 | 3633 |
'/tmp/.X11-unix/X0' asFilename fileType |
615 | 3634 |
'smalltalk.rc' asFilename fileType |
3635 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3636 |
" |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
3637 |
|
3665 | 3638 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 3639 |
! |
3640 |
||
2836 | 3641 |
id |
16578 | 3642 |
"return the file's/directory's file-id (inode number)" |
2836 | 3643 |
|
2947 | 3644 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 3645 |
|
3646 |
" |
|
3647 |
Filename currentDirectory id |
|
3648 |
" |
|
3649 |
||
3650 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
3651 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
3652 |
! |
|
3653 |
||
615 | 3654 |
info |
16578 | 3655 |
"return some object filled with the file's info; |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3656 |
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
|
3657 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3658 |
|
9453 | 3659 |
type - a symbol giving the files fileType |
3660 |
mode - numeric access mode |
|
3661 |
uid - owners user id |
|
3662 |
gid - owners group id |
|
3663 |
size - files size |
|
3664 |
id - files number (i.e. inode number) |
|
3665 |
accessed - last access time (as osTime-stamp) |
|
3666 |
modified - last modification time (as osTime-stamp) |
|
16272 | 3667 |
statusChangeTime - last staus change (as osTime-stamp) |
615 | 3668 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3669 |
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
|
3670 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3671 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
9453 | 3672 |
modified |
3673 |
size |
|
3674 |
type |
|
615 | 3675 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3676 |
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
|
3677 |
to either handle nil values, |
615 | 3678 |
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
|
3679 |
(i.e. instead of: |
9453 | 3680 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3681 |
use |
9453 | 3682 |
someFilename isDirectory |
615 | 3683 |
" |
3684 |
||
2947 | 3685 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 3686 |
|
3687 |
" |
|
3688 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3689 |
'/dev/null' asFilename info |
615 | 3690 |
'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
|
3691 |
'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
|
3692 |
'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
|
3693 |
'../../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
|
3694 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3695 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3696 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3697 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3698 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3699 |
'c:\' asFilename info |
615 | 3700 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
3701 |
|
16272 | 3702 |
"Modified: / 17-08-1998 / 10:24:10 / cg" |
3703 |
"Modified (comment): / 21-03-2014 / 00:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
615 | 3704 |
! |
3705 |
||
3706 |
linkInfo |
|
16578 | 3707 |
"return the file's info. If it is a symbolic link return the info of the link itself |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
3708 |
instead of the link's target. |
615 | 3709 |
The information is the same as returned by #info, except that if the |
3710 |
receiver represents a symbolic link, the links information |
|
3711 |
is returned |
|
3712 |
(while in this case, #info returns the info of the target file, |
|
3713 |
which is accessed via the symbolic link). |
|
3714 |
||
3715 |
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
|
3716 |
path -> the target files pathname |
615 | 3717 |
|
3718 |
See the comment in #info for more details." |
|
3719 |
||
2947 | 3720 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 3721 |
|
3722 |
" |
|
3723 |
Filename currentDirectory linkInfo |
|
3724 |
'/dev/null' asFilename linkInfo |
|
3725 |
'Make.proto' asFilename linkInfo |
|
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3726 |
'Make.proto' asFilename linkInfo path |
615 | 3727 |
'source/Point.st' asFilename linkInfo |
3728 |
'../../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
|
3729 |
'/usr/tmp' asFilename linkInfo |
615 | 3730 |
" |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3731 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
3732 |
"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
|
3733 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3734 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3735 |
modificationTime |
16578 | 3736 |
"return a timeStamp containing the file's modification time." |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3737 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3738 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3739 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3740 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3741 |
^ i modificationTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3742 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3743 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3744 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3745 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3746 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3747 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3748 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
3749 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 3750 |
! |
3751 |
||
3752 |
type |
|
3753 |
"return the symbolic type of the file" |
|
3754 |
||
2947 | 3755 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 3756 |
|
3757 |
" |
|
3758 |
Filename currentDirectory type |
|
3759 |
" |
|
3760 |
||
3761 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
3762 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 3763 |
! ! |
3764 |
||
3765 |
!Filename methodsFor:'file utilities'! |
|
3766 |
||
3767 |
edit |
|
3768 |
"start an editView on the file represented by the receiver" |
|
3769 |
||
3770 |
EditTextView openOn:self asString |
|
3771 |
||
3772 |
" |
|
3773 |
'smalltalk.rc' asFilename edit |
|
3774 |
" |
|
3775 |
! |
|
3776 |
||
3777 |
fileIn |
|
13424 | 3778 |
"load source code from the file" |
3779 |
||
3780 |
^ (ProgrammingLanguage forFile: self) fileIn: self |
|
3781 |
||
3782 |
"Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
542 | 3783 |
! ! |
3784 |
||
2 | 3785 |
!Filename methodsFor:'instance creation'! |
3786 |
||
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3787 |
/ subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3788 |
"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
|
3789 |
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
|
3790 |
(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
|
3791 |
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
|
3792 |
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
|
3793 |
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
|
3794 |
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
|
3795 |
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
|
3796 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3797 |
^ 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
|
3798 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3799 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3800 |
'/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
|
3801 |
'/' 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
|
3802 |
'/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
|
3803 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3804 |
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
|
3805 |
'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
|
3806 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3807 |
! |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
3808 |
|
615 | 3809 |
construct:subname |
3810 |
"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
|
3811 |
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
|
3812 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 3813 |
The argument may not specify an absolute path name. |
3814 |
Please do not use this to create filenames with suffixes, |
|
3815 |
since some systems require special naming conventions. |
|
3816 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 3817 |
|
11784 | 3818 |
|constructedName| |
3819 |
||
3820 |
constructedName := self constructString:subname. |
|
15811 | 3821 |
^ self species named:constructedName. |
615 | 3822 |
|
3823 |
" |
|
3824 |
'/tmp' asFilename construct:'foo' |
|
3825 |
'/' asFilename construct:'foo' |
|
3826 |
'/usr/tmp' asFilename construct:'foo' |
|
3827 |
'/foo/bar' asFilename construct:'baz' |
|
6670 | 3828 |
'/foo/bar' asFilename construct:'baz' asFilename |
2922 | 3829 |
|
3830 |
Bad example; works on UNIX, but may not on others: |
|
11784 | 3831 |
'foo/bar.baz' asFilename construct:'.suff' |
615 | 3832 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3833 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
3834 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 3835 |
! |
3836 |
||
2922 | 3837 |
constructDirectory:subname |
3838 |
"same as #construct: on most systems. |
|
3839 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
3840 |
||
15811 | 3841 |
^ self species named:(self constructDirectoryString:subname) |
2922 | 3842 |
! |
3843 |
||
3844 |
constructDirectoryString:subName |
|
3845 |
"same as #constructString: on most systems. |
|
3846 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
3847 |
||
3848 |
^ self constructString:subName |
|
3849 |
! |
|
3850 |
||
3851 |
constructString:subName |
|
2911 | 3852 |
"taking the receiver as a directory name, construct a new |
3853 |
filename-string for an entry within this directory |
|
2922 | 3854 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 3855 |
The argument may not specify an absolute path name. |
3856 |
The code below works for UNIX & MSDOS; |
|
3857 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3858 |
||
3859 |
|sepString sub| |
|
3860 |
||
3861 |
sub := subName asString. |
|
15811 | 3862 |
sepString := self species separatorString. |
8243 | 3863 |
nameString size == 0 ifTrue:[ |
3864 |
^ sub |
|
2911 | 3865 |
]. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3866 |
(nameString endsWith:sepString) ifTrue:[ |
6247 | 3867 |
^ nameString , sub |
3868 |
]. |
|
2960 | 3869 |
^ nameString , sepString , sub |
2911 | 3870 |
|
3871 |
" |
|
3872 |
'/tmp' asFilename constructString:'foo' |
|
3873 |
'/' asFilename constructString:'foo' |
|
3874 |
'/usr/tmp' asFilename constructString:'foo' |
|
3875 |
'/foo/bar' asFilename constructString:'baz' |
|
6247 | 3876 |
'' asFilename constructString:'baz' |
2911 | 3877 |
" |
3878 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3879 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3880 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3881 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
3882 |
"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
|
3883 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3884 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3885 |
filenameFor:fileName |
6973 | 3886 |
"return a filename representing the argument, fileName |
3887 |
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
|
3888 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3889 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3890 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3891 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3892 |
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
|
3893 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3894 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3895 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3896 |
'/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
|
3897 |
'/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
|
3898 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3899 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
3900 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
9263 | 3901 |
! |
3902 |
||
3903 |
secureConstruct:subname |
|
3904 |
"taking the receiver as a directory name, construct a new |
|
3905 |
filename for an entry within this directory |
|
3906 |
(i.e. for a file or a subdirectory in that directory). |
|
3907 |
The argument may not specify an absolute path name. |
|
3908 |
Please do not use this to create filenames with suffixes, |
|
3909 |
since some systems require special naming conventions. |
|
3910 |
See also: #withSuffix: (which is different, but often needed). |
|
3911 |
||
3912 |
This method differs from #construct:, by not permitting subName |
|
3913 |
to navigate above (via ..) the current filename." |
|
3914 |
||
15811 | 3915 |
^ self species named:(self secureConstructString:subname) |
9263 | 3916 |
|
3917 |
" |
|
3918 |
'/tmp' asFilename secureConstruct:'foo' |
|
3919 |
'/tmp' asFilename secureConstruct:'../foo' |
|
3920 |
'/tmp' asFilename secureConstruct:'/./foo' |
|
3921 |
'/tmp' asFilename secureConstruct:'foo/../bar' |
|
3922 |
'/' asFilename secureConstruct:'foo' |
|
3923 |
'/usr/tmp' asFilename secureConstruct:'foo' |
|
3924 |
'/foo/bar' asFilename secureConstruct:'baz' |
|
3925 |
'/foo/bar' asFilename secureConstruct:'baz' asFilename |
|
3926 |
||
3927 |
Bad example; works on UNIX, but may not on others: |
|
3928 |
'foo/bar.baz' secureConstruct:'.suff' |
|
3929 |
" |
|
3930 |
||
3931 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
|
3932 |
! |
|
3933 |
||
3934 |
secureConstructString:subName |
|
3935 |
"taking the receiver as a directory name, construct a new |
|
3936 |
filename-string for an entry within this directory |
|
3937 |
(i.e. for a file or a subdirectory in that directory). |
|
3938 |
||
3939 |
This method differs from #constructString, by not permitting subName |
|
3940 |
to navigate above (via ..) the current filename. |
|
3941 |
||
3942 |
The code below works for UNIX & MSDOS; |
|
3943 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
3944 |
||
3945 |
|sepString sub normalizedPath pathStream| |
|
3946 |
||
15811 | 3947 |
sepString := self species separatorString. |
9263 | 3948 |
sub := subName asString. |
3949 |
||
3950 |
sub := sub asCollectionOfSubstringsSeparatedByAll:sepString. |
|
3951 |
normalizedPath := OrderedCollection new:sub size. |
|
3952 |
sub do:[:eachPathComponent| |
|
3953 |
eachPathComponent = '..' ifTrue:[ |
|
3954 |
normalizedPath isEmpty ifTrue:[ |
|
3955 |
self error:'secureConstruct: - trying to escape from: ', nameString. |
|
3956 |
]. |
|
3957 |
normalizedPath removeLast. |
|
3958 |
] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[ |
|
3959 |
normalizedPath add:eachPathComponent. |
|
3960 |
]] |
|
3961 |
]. |
|
3962 |
pathStream := WriteStream with:nameString. |
|
3963 |
(nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[ |
|
3964 |
pathStream nextPutAll:sepString. |
|
3965 |
]. |
|
3966 |
normalizedPath do:[:eachPathComponent| |
|
3967 |
pathStream nextPutAll:eachPathComponent. |
|
3968 |
] separatedBy:[ |
|
3969 |
pathStream nextPutAll:sepString. |
|
3970 |
]. |
|
3971 |
||
3972 |
^ pathStream contents. |
|
3973 |
||
3974 |
" |
|
3975 |
'/tmp' asFilename secureConstructString:'foo' |
|
3976 |
'/tmp' asFilename secureConstructString:'../foo' |
|
3977 |
'/tmp' asFilename secureConstructString:'foo/../bla' |
|
3978 |
'/tmp' asFilename secureConstructString:'foo/./bla' |
|
3979 |
'/tmp' asFilename secureConstructString:'/bla/foo/../../foo' |
|
3980 |
'/' asFilename secureConstructString:'foo' |
|
3981 |
'/usr/tmp' asFilename secureConstructString:'foo' |
|
3982 |
'/foo/bar' asFilename secureConstructString:'baz' |
|
3983 |
'' asFilename secureConstructString:'baz' |
|
3984 |
'' asFilename secureConstructString:'/baz' |
|
3985 |
" |
|
2 | 3986 |
! ! |
3987 |
||
195 | 3988 |
!Filename methodsFor:'misc'! |
3989 |
||
3990 |
, aString |
|
3991 |
"this allows filenames to understand how names are concatenated. |
|
14072 | 3992 |
Returns a string consisting of the receiver's name, concatenated |
195 | 3993 |
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
|
3994 |
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
|
3995 |
See also: #withSuffix: which is new and better." |
195 | 3996 |
|
5866 | 3997 |
<resource:#obsolete> |
3998 |
||
2906 | 3999 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 4000 |
^ (nameString , aString asString) |
195 | 4001 |
|
4002 |
" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4003 |
'Makefile' asFilename , '.bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4004 |
('Makefile' asFilename , '.bak') asFilename |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4005 |
'Makefile' asFilename withSuffix:'bak' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4006 |
'Makefile' asFilename construct:'.bak' |
195 | 4007 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4008 |
|
14072 | 4009 |
"Modified: / 07-09-1997 / 23:45:36 / cg" |
4010 |
"Modified (comment): / 01-04-2012 / 13:18:21 / cg" |
|
9263 | 4011 |
! |
4012 |
||
4013 |
canonicalize |
|
4014 |
"normalize a filename by removing all empty path components or dots, |
|
4015 |
and by resolving parent directory '..' references. |
|
4016 |
||
4017 |
The code below works for UNIX & MSDOS; |
|
4018 |
other filename classes (i.e. VMS) may want to redefine this method." |
|
4019 |
||
15811 | 4020 |
nameString := self species canonicalize:nameString. |
9263 | 4021 |
|
4022 |
" |
|
4023 |
'/tmp/bla' asFilename canonicalize. |
|
4024 |
'/tmp/bla/../fasel' asFilename canonicalize. |
|
4025 |
'/tmp/bla/.././/fasel' asFilename canonicalize. |
|
4026 |
'..' asFilename canonicalize. |
|
4027 |
'bla/../fasel' asFilename canonicalize. |
|
4028 |
'//bla/../fasel' asFilename canonicalize. |
|
4029 |
" |
|
195 | 4030 |
! ! |
4031 |
||
14232 | 4032 |
!Filename methodsFor:'os shell'! |
4033 |
||
4034 |
openExplorer |
|
4035 |
"open a file-explorer on the directory represented by the receiver. |
|
4036 |
On non-windows systems, an error is raised" |
|
4037 |
||
4038 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
|
4039 |
self warn:'sorry - this operation is only available under windows'. |
|
4040 |
]. |
|
4041 |
||
4042 |
OperatingSystem |
|
4043 |
openApplicationForDocument:self pathName |
|
4044 |
operation:#explore. |
|
4045 |
||
4046 |
"Created: / 21-07-2012 / 12:28:18 / cg" |
|
14804 | 4047 |
! |
4048 |
||
4049 |
openFinder |
|
4050 |
"open a finder on the directory represented by the receiver. |
|
4051 |
On non-osx systems, an error is raised" |
|
4052 |
||
4053 |
OperatingSystem isOSXlike ifFalse:[ |
|
4054 |
self warn:'sorry - this operation is only available under osx'. |
|
4055 |
]. |
|
4056 |
||
16547 | 4057 |
OperatingSystem executeCommand:'open "',self pathName,'"' |
14804 | 4058 |
! |
4059 |
||
4060 |
openTerminal |
|
16545 | 4061 |
"open a terminal window on the directory represented by the receiver; |
4062 |
on osx, a terminal app is opened, |
|
4063 |
on windows a cmd.exe window, |
|
4064 |
on unix, an xterm is opened." |
|
4065 |
||
4066 |
OperatingSystem isOSXlike ifTrue:[ |
|
4067 |
"/ I dont know yet how to tell the terminal to |
|
4068 |
"/ go to a particular directory. |
|
4069 |
"/ therefore, use the built in terminal |
|
4070 |
VT100TerminalView openShellIn:self pathName. |
|
4071 |
^ self. |
|
4072 |
]. |
|
14804 | 4073 |
|
14941 | 4074 |
[ |
16545 | 4075 |
|cmd| |
4076 |
||
14941 | 4077 |
OperatingSystem isOSXlike ifTrue:[ |
16545 | 4078 |
cmd := '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ' |
14941 | 4079 |
] ifFalse:[ |
16545 | 4080 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
4081 |
cmd := 'c:\windows\System32\cmd.exe' |
|
4082 |
] ifFalse:[ |
|
4083 |
"/ VT100TerminalView openShellIn:self pathName |
|
4084 |
cmd := 'xterm' |
|
4085 |
] |
|
4086 |
]. |
|
4087 |
OperatingSystem |
|
4088 |
executeCommand:cmd |
|
4089 |
inDirectory:self pathName. |
|
14941 | 4090 |
] fork |
14232 | 4091 |
! ! |
4092 |
||
615 | 4093 |
!Filename methodsFor:'printing & storing'! |
174 | 4094 |
|
615 | 4095 |
printOn:aStream |
4392 | 4096 |
"append a user printed representation of the receiver to aStream. |
4097 |
The format is suitable for a human - not meant to be read back." |
|
174 | 4098 |
|
2906 | 4099 |
aStream nextPutAll:(self class name). |
4100 |
aStream nextPutAll:'('''. |
|
615 | 4101 |
nameString printOn:aStream. |
4102 |
aStream nextPutAll:''')' |
|
2906 | 4103 |
|
4104 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 4105 |
! |
4106 |
||
615 | 4107 |
storeOn:aStream |
4108 |
"append a printed representation of the receiver to aStream, |
|
4109 |
which allows reconstructing it via readFrom:" |
|
328 | 4110 |
|
615 | 4111 |
aStream nextPut:$(. |
4112 |
nameString storeOn:aStream. |
|
4113 |
aStream nextPutAll:' asFilename)' |
|
1 | 4114 |
! ! |
4115 |
||
7258 | 4116 |
!Filename methodsFor:'private-accessing'! |
1 | 4117 |
|
6227 | 4118 |
getName |
4119 |
"get the raw filename" |
|
4120 |
||
4121 |
^ nameString |
|
4122 |
! |
|
4123 |
||
68 | 4124 |
setName:aString |
38 | 4125 |
"set the filename" |
4126 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
4127 |
nameString := aString. |
3666 | 4128 |
|
4129 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 4130 |
! ! |
4131 |
||
2 | 4132 |
!Filename methodsFor:'queries'! |
4133 |
||
68 | 4134 |
exists |
92 | 4135 |
"return true, if such a file exists." |
68 | 4136 |
|
2947 | 4137 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 4138 |
|
85 | 4139 |
" |
92 | 4140 |
'/foo/bar' asFilename exists |
4141 |
'/tmp' asFilename exists |
|
4142 |
'Makefile' asFilename exists |
|
85 | 4143 |
" |
77 | 4144 |
! |
4145 |
||
5928 | 4146 |
filenamesMatching:aPattern |
4147 |
"VW compatibility" |
|
4148 |
||
15811 | 4149 |
^ (self filesMatching:aPattern) |
4150 |
collect:[:eachName | self construct:eachName]. |
|
5928 | 4151 |
|
4152 |
" |
|
4153 |
'/etc' asFilename filenamesMatching:'a*;c*' |
|
4154 |
" |
|
4155 |
||
4156 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
4157 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
4158 |
! |
|
4159 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4160 |
filesMatching:aPattern |
2550 | 4161 |
"given the receiver, representing a directory; |
4162 |
return a collection of files matching a pattern. |
|
4163 |
The pattern may be a simple matchPattern, or a set of |
|
4164 |
multiple patterns separated by semicolons." |
|
4165 |
||
15737 | 4166 |
|matchers caseSensitive| |
2550 | 4167 |
|
4168 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
15811 | 4169 |
caseSensitive := self species isCaseSensitive. |
2550 | 4170 |
^ self directoryContents |
9453 | 4171 |
select:[:name | |
15737 | 4172 |
(matchers detect:[:p | p match:name caseSensitive:caseSensitive] ifNone:0) ~~ 0 |
9453 | 4173 |
] |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4174 |
|
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4175 |
" |
2550 | 4176 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4177 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4178 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4179 |
"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
|
4180 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 4181 |
! |
4182 |
||
4183 |
filesMatchingWithoutDotDirs:aPattern |
|
4184 |
"given the receiver, representing a directory; |
|
4185 |
return a collection of files matching a pattern. |
|
4186 |
Exclude '.' and '..' from the returned list. |
|
4187 |
The pattern may be a simple matchPattern, or a set of |
|
4188 |
multiple patterns separated by semicolons." |
|
4189 |
||
15737 | 4190 |
|matchers caseSensitive| |
2550 | 4191 |
|
4192 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
15811 | 4193 |
caseSensitive := self species isCaseSensitive. |
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4194 |
|
2550 | 4195 |
^ self directoryContents |
9453 | 4196 |
select:[:name | |
4197 |
name ~= '.' |
|
4198 |
and:[name ~= '..' |
|
15737 | 4199 |
and:[(matchers detect:[:p | p match:name caseSensitive:caseSensitive] ifNone:0) ~~ 0]] |
2550 | 4200 |
] |
4201 |
||
4202 |
" |
|
4203 |
Filename currentDirectory filesMatching:'M*' |
|
4204 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
4205 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
4206 |
" |
|
4207 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4208 |
"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
|
4209 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4210 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4211 |
|
9206 | 4212 |
fullAlternativePathName |
4213 |
^ nameString |
|
4214 |
! |
|
4215 |
||
615 | 4216 |
isExecutable |
4217 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
4218 |
For directories, true is returned if the directory can be entered. |
|
4219 |
See isExecutableProgram for a related check." |
|
4220 |
||
2947 | 4221 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 4222 |
|
4223 |
" |
|
4224 |
'/foo/bar' asFilename isExecutable |
|
4225 |
'/tmp' asFilename isExecutable |
|
4226 |
'Makefile' asFilename isExecutable |
|
4227 |
'/bin/ls' asFilename isExecutable |
|
356 | 4228 |
" |
4229 |
! |
|
4230 |
||
615 | 4231 |
isExecutableProgram |
4232 |
"return true, if such a file exists and is an executable program. |
|
4233 |
(i.e. for directories, false is returned.)" |
|
356 | 4234 |
|
2922 | 4235 |
|osName| |
4236 |
||
2947 | 4237 |
osName := self osNameForAccess. |
2922 | 4238 |
^ (OperatingSystem isExecutable:osName) |
4239 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 4240 |
|
4241 |
" |
|
615 | 4242 |
'/tmp' asFilename isExecutable |
4243 |
'/bin/ls' asFilename isExecutable |
|
4244 |
'/tmp' asFilename isExecutableProgram |
|
4245 |
'/bin/ls' asFilename isExecutableProgram |
|
4246 |
" |
|
4247 |
! |
|
4248 |
||
2922 | 4249 |
isHidden |
4250 |
"return true, if the receiver represents a hidden file. |
|
4251 |
The definitions of hidden files depends on the OS used; |
|
4252 |
on UNIX, a name starting with a period is considered hidden; |
|
16578 | 4253 |
on MSDOS, the file's hidden attribute is also used. |
2922 | 4254 |
VMS has no concept of hidden files." |
4255 |
||
4256 |
^ false |
|
4257 |
! |
|
4258 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4259 |
isMountPoint:aPathName |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4260 |
"return true, if I represent a mount-point. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4261 |
Warning: |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4262 |
the receiver must be an absolute pathname, |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4263 |
because a realPath is not used/generated for the query (to avoid automounting). |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4264 |
Aka: do not ask: '../../' asFilename isMountPoint; |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4265 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4266 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4267 |
self isAbsolute ifFalse:[ |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4268 |
self error:'this query must be done on an absolute pathname'. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4269 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4270 |
^ OperatingSystem isMountPoint:(self name) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4271 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4272 |
|
615 | 4273 |
isReadable |
4274 |
"return true, if such a file exists and is readable." |
|
4275 |
||
2947 | 4276 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 4277 |
|
4278 |
" |
|
4279 |
'/foo/bar' asFilename isReadable |
|
4280 |
'/tmp' asFilename isReadable |
|
4281 |
'Makefile' asFilename isReadable |
|
328 | 4282 |
" |
4283 |
! |
|
4284 |
||
11529 | 4285 |
isSharedLibrary |
4286 |
"return true, if such a file exists and is a shared library." |
|
4287 |
||
4288 |
ObjectFileLoader isNil ifTrue:[ |
|
4289 |
"we cannot handle shared libraries, so there are no shared libraries" |
|
4290 |
^ false. |
|
4291 |
]. |
|
14932 | 4292 |
^ (ObjectFileLoader validBinaryExtensions includes:self suffix) |
4293 |
and:[self isRegularFile]. |
|
11529 | 4294 |
|
4295 |
" |
|
4296 |
'libstx_libbasic.so' asFilename isSharedLibrary |
|
4297 |
'libstx_libbasic.dll' asFilename isSharedLibrary |
|
4298 |
'/tmp' asFilename isSharedLibrary |
|
14932 | 4299 |
'/tmp.dll' asFilename isSharedLibrary |
11529 | 4300 |
" |
4301 |
! |
|
4302 |
||
615 | 4303 |
isWritable |
4304 |
"return true, if such a file exists and is writable." |
|
4305 |
||
2947 | 4306 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 4307 |
|
4308 |
" |
|
4309 |
'/foo/bar' asFilename isWritable |
|
4310 |
'/tmp' asFilename isWritable |
|
4311 |
'Makefile' asFilename isWritable |
|
328 | 4312 |
" |
174 | 4313 |
! |
4314 |
||
15574 | 4315 |
isWritableDirectory |
4316 |
"return true, if such a directory exists and is writable. |
|
4317 |
Don't believe #isWritable, since on an NFS mounted filesystem |
|
4318 |
with UID mapping and attribute cache enabled, there may be false negatives." |
|
4319 |
||
4320 |
self isDirectory ifFalse:[ |
|
4321 |
^ false. |
|
4322 |
]. |
|
4323 |
||
4324 |
self isWritable ifFalse:[ |
|
4325 |
"/ on an NFS mounted filesystem with UID mapping and |
|
4326 |
"/ attribute cache enabled, |
|
4327 |
"/ this query may fail, but creation may work actually. |
|
4328 |
"/ check again... |
|
4329 |
[ |
|
4330 |
|tempFile| |
|
4331 |
||
4332 |
tempFile := FileStream newTemporaryIn:self. |
|
4333 |
tempFile close. |
|
4334 |
tempFile fileName remove. |
|
4335 |
] on:OpenError do:[:ex| |
|
4336 |
^ false. |
|
4337 |
]. |
|
4338 |
]. |
|
4339 |
^ true. |
|
4340 |
||
4341 |
" |
|
4342 |
'/foo/bar' asFilename isWritableDirectory |
|
4343 |
'/tmp' asFilename isWritableDirectory |
|
4344 |
'/etc' asFilename isWritableDirectory |
|
4345 |
'Makefile' asFilename isWritableDirectory |
|
4346 |
'/net/exeptn/home2/office' asFilename isWritable |
|
4347 |
'/net/exeptn/home2/office' asFilename isWritableDirectory |
|
4348 |
" |
|
4349 |
! |
|
4350 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4351 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4352 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4353 |
|
15811 | 4354 |
^ self species separator |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4355 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4356 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
8947 | 4357 |
! |
4358 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4359 |
species |
15811 | 4360 |
"create only new instances of the concrete OS specific class. |
4361 |
Redefined in AutoDeletedFilename, to not create AutoDeleted instances |
|
4362 |
per default (from directories etc.)" |
|
4363 |
||
4364 |
self == Filename ifTrue:[ |
|
4365 |
^ ConcreteClass. |
|
4366 |
] ifFalse:[ |
|
4367 |
^ self class. |
|
4368 |
]. |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4369 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4370 |
|
8947 | 4371 |
withSpecialExpansions |
4372 |
"return a new filename, expanding any OS specific macros. |
|
15811 | 4373 |
Here, a ~/ prefix is expanded to the users home dir (as in bash)" |
8947 | 4374 |
|
4375 |
|newName| |
|
4376 |
||
15811 | 4377 |
newName := self species nameWithSpecialExpansions:nameString. |
4378 |
newName = nameString ifTrue:[ |
|
4379 |
^ self. |
|
8947 | 4380 |
]. |
15811 | 4381 |
^ self species named:newName. |
8947 | 4382 |
|
4383 |
" |
|
4384 |
'~' asFilename withSpecialExpansions |
|
15811 | 4385 |
'~/Desktop' asFilename withSpecialExpansions |
4386 |
'~stefan' asFilename withSpecialExpansions |
|
4387 |
'~stefan/Desktop' asFilename withSpecialExpansions |
|
8947 | 4388 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4389 |
! ! |
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 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4392 |
|
7291 | 4393 |
mimeTypeFromName |
16578 | 4394 |
"return the mimeType as guessed from the file's name/and or extension. |
7291 | 4395 |
This could be less accurate than mimeTypeOfContents, but avoids |
4396 |
reading the file (is therefore much faster). |
|
4397 |
Also it works with non-existing files. |
|
4398 |
Returns nil for directories and other non-regular files." |
|
4399 |
||
17112 | 4400 |
|mimeTypes| |
4401 |
||
16755 | 4402 |
"/ kludge to avoid making libview a prereq. of libbasic |
17112 | 4403 |
(mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[ |
4404 |
^ mimeTypes mimeTypeForFilename:(self name) |
|
16755 | 4405 |
]. |
4406 |
^ nil |
|
7291 | 4407 |
|
4408 |
" |
|
4409 |
'Makefile' asFilename mimeTypeFromName |
|
4410 |
'.' asFilename mimeTypeFromName |
|
4411 |
'/dev/null' asFilename mimeTypeFromName |
|
4412 |
'/tmp/.X11-unix/X0' asFilename mimeTypeFromName |
|
4413 |
'smalltalk.rc' asFilename mimeTypeFromName |
|
4414 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName |
|
4415 |
'../../rules/stmkmf' asFilename mimeTypeFromName |
|
4416 |
'/bläh' asFilename mimeTypeFromName |
|
10902 | 4417 |
'/x.zip' asFilename mimeTypeFromName |
4418 |
'/x.gz' asFilename mimeTypeFromName |
|
7291 | 4419 |
" |
4420 |
! |
|
4421 |
||
5011 | 4422 |
mimeTypeOfContents |
4423 |
"this tries to guess the mime type of contents of |
|
4424 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
4425 |
or the contents is unknown. |
|
4426 |
This is done using some heuristics, and may need some improvement" |
|
4427 |
||
17111 | 4428 |
|type buffer s size mimeTypes| |
5011 | 4429 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4430 |
type := self type. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4431 |
type isNil ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4432 |
type == #directory ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4433 |
type == #characterSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4434 |
type == #blockSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4435 |
type == #socket ifTrue:[ ^ nil ]. |
5011 | 4436 |
self fileSize == 0 ifTrue:[^ nil]. |
4437 |
||
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4438 |
s := self readStreamOrNil. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4439 |
s isNil ifTrue:[^ nil]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4440 |
|
5011 | 4441 |
"/ read some data from the file ... |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
4442 |
buffer := String new:2048. |
5011 | 4443 |
|
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4444 |
s errorSignal handle:[:ex | |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4445 |
size := 0. |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4446 |
] do:[ |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4447 |
size := s nextBytes:buffer size into:buffer. |
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
4448 |
]. |
5011 | 4449 |
s close. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4450 |
|
16755 | 4451 |
"/ kludge to avoid making libview a prereq. of libbasic |
17111 | 4452 |
(mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[ |
17112 | 4453 |
^ mimeTypes mimeTypeOfData:buffer suffix:self suffix. |
16755 | 4454 |
]. |
4455 |
^ nil |
|
5011 | 4456 |
|
4457 |
" |
|
6753
1a4a541850f2
add search for unprintable characters on mimeTypeContents
penk
parents:
6729
diff
changeset
|
4458 |
'Makefile' asFilename mimeTypeOfContents |
1a4a541850f2
add search for unprintable characters on mimeTypeContents
penk
parents:
6729
diff
changeset
|
4459 |
'.' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4460 |
'/dev/null' asFilename mimeTypeOfContents |
10153 | 4461 |
'/tmp/.X11-unix/X0' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4462 |
'smalltalk.rc' asFilename mimeTypeOfContents |
5011 | 4463 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents |
10153 | 4464 |
'../../rules/stmkmf' asFilename mimeTypeOfContents |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
4465 |
'/bläh' asFilename mimeTypeOfContents |
10153 | 4466 |
'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
|
4467 |
'G:\A\A01.TOP' asFilename mimeTypeOfContents |
10153 | 4468 |
" |
4469 |
||
4470 |
"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
|
4471 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4472 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4473 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4474 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4475 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4476 |
"return my baseName as a string. |
2012 | 4477 |
- thats the file/directory name without leading parent-dirs. |
2922 | 4478 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
4479 |
and '/usr/lib' asFilename baseName -> lib). |
|
7075 | 4480 |
This method does not check if the path is valid. |
4481 |
The code here should work for Unix and MSDOS, but needs to be redefined |
|
4482 |
for VMS (and maybe others as well). |
|
2911 | 4483 |
See also: #pathName, #directoryName and #directoryPathName. |
4484 |
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
|
4485 |
|
2922 | 4486 |
|len index sep endIdx| |
4487 |
||
4488 |
sep := self separator. |
|
4489 |
len := nameString size. |
|
4490 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
7075 | 4491 |
^ nameString |
2922 | 4492 |
]. |
4493 |
||
4494 |
endIdx := len. |
|
4495 |
len > 1 ifTrue:[ |
|
7075 | 4496 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
2922 | 4497 |
]. |
4498 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
4499 |
^ 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
|
4500 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4501 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4502 |
'/foo/bar' asFilename baseName |
4903 | 4503 |
'/foo/bar.cc' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4504 |
'.' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4505 |
'..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4506 |
'../..' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4507 |
'../../libbasic' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4508 |
'../../libpr' asFilename baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4509 |
'../../libbasic/Object.st' asFilename baseName |
3851 | 4510 |
'/' asFilename baseName |
4511 |
'\' asFilename baseName |
|
4512 |
'c:\' asFilename baseName |
|
4513 |
'\\idefix' asFilename baseName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4514 |
" |
2012 | 4515 |
|
3851 | 4516 |
"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
|
4517 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4518 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4519 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4520 |
"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
|
4521 |
- 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
|
4522 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4523 |
(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
|
4524 |
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
|
4525 |
|
15811 | 4526 |
^ self species named:(self directoryName) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4527 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4528 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4529 |
'/foo/bar' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4530 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4531 |
'/foo/bar' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4532 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4533 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4534 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4535 |
'../..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4536 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4537 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4538 |
"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
|
4539 |
! |
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 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4542 |
"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
|
4543 |
- 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
|
4544 |
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
|
4545 |
This method does not check if the path is valid. |
2922 | 4546 |
|
4547 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
4548 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
4549 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4550 |
(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
|
4551 |
a string instead of a Filename instance). |
2922 | 4552 |
|
2012 | 4553 |
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
|
4554 |
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
|
4555 |
|
16389 | 4556 |
|index sep sepString p rest parentDirectoryString| |
2922 | 4557 |
|
4558 |
sep := self separator. |
|
4559 |
sepString := sep asString. |
|
4560 |
(nameString = sepString) ifTrue:[ |
|
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4561 |
"/ |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4562 |
"/ the trivial '/' case |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4563 |
"/ |
16389 | 4564 |
^ sepString |
2922 | 4565 |
]. |
4566 |
||
4567 |
"/ |
|
3893 | 4568 |
"/ strip off multiple trailing slashes |
2922 | 4569 |
"/ |
4570 |
p := nameString. |
|
16389 | 4571 |
[p endsWith:sep] whileTrue:[ |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4572 |
(p = sepString) ifTrue:[ |
16389 | 4573 |
^ sepString |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4574 |
]. |
15163
7862c37d3947
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
15121
diff
changeset
|
4575 |
p := p copyButLast:1 |
2922 | 4576 |
]. |
4577 |
||
16389 | 4578 |
parentDirectoryString := self class parentDirectoryName. |
4579 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4580 |
"/ strip off trailing components |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4581 |
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
|
4582 |
index == 0 ifTrue:[ |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4583 |
"/ no separator found |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4584 |
p = '.' ifTrue:[ |
16389 | 4585 |
^ parentDirectoryString |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4586 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4587 |
p = '..' ifTrue:[ |
16389 | 4588 |
^ parentDirectoryString, sepString, parentDirectoryString |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4589 |
]. |
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4590 |
^ '.' |
2922 | 4591 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4592 |
rest := p copyFrom:(index+1). |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4593 |
(rest = '.') ifTrue:[ |
7519
0cfe202e7e3e
#directoryName returned a Filename
Stefan Vogel <sv@exept.de>
parents:
7473
diff
changeset
|
4594 |
^ p copyTo:index-1. |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
4595 |
]. |
16389 | 4596 |
(rest = parentDirectoryString) ifTrue:[ |
15811 | 4597 |
^ (self species 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
|
4598 |
]. |
3893 | 4599 |
index == 1 ifTrue:[ |
16389 | 4600 |
^ sepString |
3893 | 4601 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4602 |
^ p copyTo:(index - 1) |
1049
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 |
" |
3893 | 4605 |
'/home' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4606 |
'/foo/bar/' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4607 |
'/foo/bar/' asFilename directory |
1049
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 |
'/foo/bar' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4610 |
'bitmaps' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4611 |
'bitmaps' asFilename directoryPathName |
6402
23ddc6a6573e
directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents:
6392
diff
changeset
|
4612 |
'.' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4613 |
'.' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4614 |
'..' asFilename directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
4615 |
'..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4616 |
'../..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4617 |
'../..' asFilename directoryPathName |
7343 | 4618 |
'/foo/bar/baz/..' asFilename directoryName |
4619 |
'/foo/bar/baz/.' asFilename directoryName |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4620 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4621 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
4622 |
"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
|
4623 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 4624 |
"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
|
4625 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4626 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4627 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4628 |
"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
|
4629 |
- 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
|
4630 |
the receiver is contained in. |
2012 | 4631 |
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
|
4632 |
|
15811 | 4633 |
^ (self species named:self pathName) directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4634 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4635 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4636 |
'/foo/bar/' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4637 |
'/foo/bar' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4638 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4639 |
'.' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4640 |
'.' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4641 |
'.' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4642 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4643 |
'..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4644 |
'..' asFilename directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4645 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4646 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4647 |
'../..' asFilename directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4648 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4649 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4650 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 4651 |
"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
|
4652 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4653 |
|
14567 | 4654 |
encodedNameString |
4655 |
"answer the name as passed to OS system calls" |
|
4656 |
||
4657 |
^ OperatingSystem encodePath:nameString |
|
4658 |
! |
|
4659 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4660 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4661 |
"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
|
4662 |
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
|
4663 |
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
|
4664 |
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
|
4665 |
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
|
4666 |
match. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4667 |
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
|
4668 |
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
|
4669 |
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
|
4670 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4671 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4672 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4673 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4674 |
'mak' asFilename filenameCompletion |
1517 | 4675 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4676 |
'Makef' asFilename filenameCompletion;yourself |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4677 |
'/u' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4678 |
'../../libpr' asFilename inspect filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4679 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4680 |
|
1517 | 4681 |
"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
|
4682 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4683 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4684 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4685 |
"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
|
4686 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4687 |
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
|
4688 |
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
|
4689 |
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
|
4690 |
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
|
4691 |
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
|
4692 |
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
|
4693 |
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
|
4694 |
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
|
4695 |
|
15811 | 4696 |
|mySpecies 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
|
4697 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 4698 |
|
15811 | 4699 |
mySpecies := self species. |
4700 |
||
4701 |
caseless := mySpecies isCaseSensitive not. |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4702 |
matching := OrderedCollection new. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4703 |
|
15811 | 4704 |
nm := mySpecies nameWithSpecialExpansions:nameString. |
4705 |
nm := mySpecies canonicalize:nm. |
|
4706 |
||
4707 |
sepString := mySpecies separatorString. |
|
3666 | 4708 |
(nm endsWith:sepString) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4709 |
"/ two exceptions here: |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4710 |
"/ 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
|
4711 |
"/ 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
|
4712 |
self isDirectory ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4713 |
|first longest| |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4714 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4715 |
first := nil. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4716 |
self directoryContentsDo:[:fileName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4717 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4718 |
matching add:fileName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4719 |
first isNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4720 |
first := longest := fileName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4721 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4722 |
"/ more than one file |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4723 |
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
|
4724 |
longest isEmpty ifTrue:[ |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4725 |
^ #() |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4726 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4727 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4728 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4729 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4730 |
longest notNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4731 |
nameString := (self constructString:longest). |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4732 |
^ matching |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4733 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4734 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4735 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4736 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4737 |
|
15811 | 4738 |
parentString := mySpecies parentDirectoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4739 |
baseName := self baseName. |
3666 | 4740 |
baseName ~= nm ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4741 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4742 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4743 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4744 |
self isAbsolute ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4745 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4746 |
] ifFalse:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4747 |
aDirectory isNil ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4748 |
dir := self directory |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4749 |
] ifFalse:[ |
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4750 |
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
|
4751 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4752 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4753 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4754 |
caseless ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4755 |
lcBaseName := baseName asLowercase |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4756 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
4757 |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
4758 |
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
|
4759 |
^ #(). |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
4760 |
] do:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4761 |
dir directoryContents do:[:fileName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4762 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4763 |
((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
|
4764 |
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
|
4765 |
matching add:fileName |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4766 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4767 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4768 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4769 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4770 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4771 |
(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
|
4772 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4773 |
find the longest common prefix |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4774 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4775 |
matchLen := baseName size. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4776 |
matchLen > matching first size ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4777 |
try := baseName. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4778 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4779 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4780 |
try := matching first copyTo:matchLen. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4781 |
allMatching := true. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4782 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4783 |
|
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4784 |
[allMatching] whileTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4785 |
matching do:[:aName | |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4786 |
((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
|
4787 |
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
|
4788 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4789 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4790 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4791 |
allMatching ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4792 |
matchLen < matching first size ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4793 |
matchLen := matchLen + 1. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4794 |
try := matching first copyTo:matchLen. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4795 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4796 |
allMatching := false |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4797 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4798 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4799 |
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
|
4800 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4801 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4802 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4803 |
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
|
4804 |
" |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4805 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4806 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4807 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4808 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4809 |
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
|
4810 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4811 |
prefix notNil ifTrue:[ |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4812 |
(prefix endsWith:sepString) ifTrue:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4813 |
"/ avoid introducing double slashes |
15163
7862c37d3947
Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents:
15121
diff
changeset
|
4814 |
prefix := prefix copyButLast:(sepString size). |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4815 |
]. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4816 |
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
|
4817 |
nMatch == 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4818 |
nameString := nm := matching first |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4819 |
] ifFalse:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4820 |
nMatch > 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4821 |
nameString := nm := prefix , sepString , nm |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4822 |
] |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4823 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4824 |
] ifFalse:[ |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4825 |
nMatch == 1 ifTrue:[ |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4826 |
nameString := nm := matching first |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
4827 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4828 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4829 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4830 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4831 |
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
|
4832 |
(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
|
4833 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4834 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4835 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4836 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4837 |
|
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4838 |
'../' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4839 |
'/' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4840 |
'/usr/' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4841 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4842 |
'mak' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4843 |
'Make' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4844 |
'Makef' asFilename filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4845 |
'/u' asFilename filenameCompletion |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4846 |
'../../libpr' asFilename filenameCompletion |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
4847 |
'/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
|
4848 |
|
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4849 |
'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
|
4850 |
'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
|
4851 |
'c:\p' asFilename filenameCompletion |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4852 |
'c:\' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4853 |
'c:' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
4854 |
'\' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4855 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4856 |
|
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
4857 |
"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
|
4858 |
"Modified: / 17-11-2007 / 14:31:08 / cg" |
2903 | 4859 |
! |
4860 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4861 |
head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4862 |
"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
|
4863 |
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
|
4864 |
(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
|
4865 |
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
|
4866 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4867 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4868 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4869 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4870 |
Filename currentDirectory head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4871 |
'Makefile' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4872 |
'/foo/bar/baz.st' asFilename head |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4873 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4874 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4875 |
"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
|
4876 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4877 |
|
7120 | 4878 |
isAbsolute |
4879 |
"return true, if the receiver represents an absolute pathname |
|
4880 |
(in contrast to one relative to the current directory)." |
|
4881 |
||
15811 | 4882 |
((nameString startsWith:self species separator) or:[nameString startsWith:'~']) ifTrue:[^ true]. |
7120 | 4883 |
^ self isVolumeAbsolute |
4884 |
||
4885 |
" |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
4886 |
'/foo/bar' asFilename isAbsolute |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
4887 |
'~/bla' asFilename isAbsolute |
7120 | 4888 |
'..' asFilename isAbsolute |
4889 |
'..' asAbsoluteFilename isAbsolute |
|
4890 |
'source/SBrowser.st' asFilename isAbsolute |
|
12437
704dc2f7a1d0
comment/format in: #isAbsolute
Claus Gittinger <cg@exept.de>
parents:
12388
diff
changeset
|
4891 |
'source/SBrowser.st' asFilename isRelative |
704dc2f7a1d0
comment/format in: #isAbsolute
Claus Gittinger <cg@exept.de>
parents:
12388
diff
changeset
|
4892 |
'SBrowser.st' asFilename isRelative |
7120 | 4893 |
" |
4894 |
! |
|
4895 |
||
4896 |
isExplicitRelative |
|
4897 |
"return true, if this name is an explicit relative name |
|
4898 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
4899 |
||
4900 |
^ false |
|
4901 |
! |
|
4902 |
||
4903 |
isImplicit |
|
4904 |
"return true, if the receiver represents a builtin file. |
|
4905 |
The definitions of builtin files depends on the OS used; |
|
4906 |
on UNIX, '.' and '..' are builtin names." |
|
4907 |
||
4908 |
^ false |
|
4909 |
||
4910 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
|
4911 |
! |
|
4912 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4913 |
isParentDirectoryOf:aFilenameOrString |
16389 | 4914 |
"Answer true, if myself is a parent directory of aFilenameOrString. |
4915 |
Unexpected results may be returned, if one of myself or aFilenameOrString does |
|
4916 |
not exist and relative and absolute path names are mixed |
|
4917 |
('/' asFilename isParentDirectoryOf:'../noExistant' -> false) |
|
4918 |
||
4919 |
Warning: maybe symbolic links must be resolved which could lead to automounting" |
|
4920 |
||
4921 |
|filenameArg otherNames myNames myName| |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4922 |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4923 |
filenameArg := aFilenameOrString asFilename. |
16389 | 4924 |
|
4925 |
"first do a simple comparison" |
|
4926 |
otherNames := self class canonicalizedNameComponents:filenameArg name. |
|
4927 |
myNames := self class canonicalizedNameComponents:self name. |
|
4928 |
((otherNames startsWith:myNames) and:[myNames first ~= self class parentDirectoryName]) ifTrue:[ |
|
4929 |
^ otherNames ~= myNames |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
4930 |
]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4931 |
|
16389 | 4932 |
"fall back - try it again with ~ substitution and symbolic links resolved" |
4933 |
otherNames := self class canonicalizedNameComponents:filenameArg pathName. |
|
4934 |
myNames := self class canonicalizedNameComponents:self pathName. |
|
4935 |
(otherNames startsWith:myNames) ifTrue:[ |
|
4936 |
^ otherNames ~= myNames |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4937 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4938 |
|
16389 | 4939 |
myName := self class nameFromComponents:myNames. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4940 |
filenameArg allParentDirectoriesDo:[:parent | |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4941 |
parent pathName = myName ifTrue:[^ true]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4942 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4943 |
^ false. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4944 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4945 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4946 |
'/etc' asFilename isParentDirectoryOf:'/etc/passwd' |
16389 | 4947 |
'etc' asFilename isParentDirectoryOf:'etc/passwd' |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4948 |
'/etc' asFilename isParentDirectoryOf:'/etc/' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4949 |
'/etc' asFilename isParentDirectoryOf:'/etc' |
16389 | 4950 |
'/et' asFilename isParentDirectoryOf:'/etc' |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4951 |
'/home' asFilename isParentDirectoryOf:Filename currentDirectory |
16389 | 4952 |
'~' asFilename isParentDirectoryOf:Filename currentDirectory |
4953 |
'~' asFilename isParentDirectoryOf:'.' |
|
4954 |
'~' asFilename isParentDirectoryOf:'..' |
|
4955 |
'~' asFilename isParentDirectoryOf:'../smalltalk' |
|
4956 |
'../..' asFilename isParentDirectoryOf:'../nonExistant' |
|
4957 |
'..' asFilename isParentDirectoryOf:'../../nonExistant' |
|
4958 |
'/' asFilename isParentDirectoryOf:'../nonExistant' |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4959 |
'/' asFilename isParentDirectoryOf:'/phys/qnx' |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4960 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4961 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4962 |
|
7120 | 4963 |
isRelative |
4964 |
"return true, if this name is interpreted relative to some |
|
4965 |
directory (opposite of absolute)" |
|
4966 |
||
4967 |
^ self isAbsolute not |
|
4968 |
||
4969 |
" |
|
4970 |
'./foo/bar' asFilename isRelative |
|
4971 |
'../../foo/bar' asFilename isRelative |
|
4972 |
'/foo/bar' asFilename isRelative |
|
4973 |
'bar' asFilename isRelative |
|
4974 |
" |
|
4975 |
||
4976 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
4977 |
! |
|
4978 |
||
4979 |
isRootDirectory |
|
4980 |
"return true, if I represent the root directory |
|
4981 |
(i.e. I have no parentDir)" |
|
4982 |
||
4983 |
"/ mhmh - should we use: |
|
4984 |
"/ |
|
4985 |
"/ parentDir := self construct:'..'. |
|
4986 |
"/ (parentDir exists |
|
4987 |
"/ and:[parentDir isDirectory |
|
4988 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
|
4989 |
"/ ^ false |
|
4990 |
"/ ]. |
|
4991 |
"/ ^ true |
|
4992 |
"/ |
|
4993 |
||
4994 |
^ self pathName = Filename rootDirectory pathName |
|
4995 |
||
4996 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
4997 |
! |
|
4998 |
||
4999 |
isVolumeAbsolute |
|
5000 |
"return true, if the receiver represents an absolute pathname |
|
5001 |
on some disk volume (MSDOS only)" |
|
5002 |
||
5003 |
^ false |
|
5004 |
||
5005 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
5006 |
! |
|
5007 |
||
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5008 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5009 |
"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
|
5010 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5011 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5012 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5013 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5014 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5015 |
|
615 | 5016 |
name |
5017 |
"return the name of the file represented by the receiver as a string. |
|
883 | 5018 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 5019 |
See also: pathName" |
174 | 5020 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5021 |
"/ self isAbsolute ifTrue:[^ self pathName]. |
615 | 5022 |
^ nameString |
174 | 5023 |
|
5024 |
" |
|
615 | 5025 |
'/foo/bar' asFilename name |
5026 |
'/foo/bar' asFilename pathName |
|
5027 |
'.' asFilename name |
|
5028 |
'.' asFilename pathName |
|
5029 |
'../..' asFilename name |
|
883 | 5030 |
'../..' asFilename pathName |
615 | 5031 |
'bitmaps' asFilename name |
5032 |
'bitmaps' asFilename pathName |
|
5033 |
'/tmp/../usr' asFilename name |
|
883 | 5034 |
'/tmp/../usr' asFilename pathName |
5035 |
'source/..' asFilename name |
|
5036 |
'source/..' asFilename pathName |
|
5037 |
'/tmp/..' asFilename name |
|
5038 |
'/tmp/..' asFilename pathName |
|
92 | 5039 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5040 |
|
883 | 5041 |
"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
|
5042 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5043 |
|
7308 | 5044 |
nameString |
5045 |
"raw access to nameString - req'd for xml-store/reload" |
|
5046 |
||
5047 |
^ nameString |
|
5048 |
! |
|
5049 |
||
5050 |
nameString:aString |
|
5051 |
"raw access to nameString - req'd for xml-store/reload" |
|
5052 |
||
5053 |
nameString := aString |
|
5054 |
! |
|
5055 |
||
615 | 5056 |
pathName |
5057 |
"return the full pathname of the file represented by the receiver, |
|
1317 | 5058 |
as a string. This will not include ..'s. |
5059 |
If the path represented by the receiver does NOT represent a valid path, |
|
5060 |
no compression will be done (for now; this may change). |
|
5061 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5062 |
|
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5063 |
|
1317 | 5064 |
"/ sep := self class separator. |
5065 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
5066 |
"/ parentName := self class parentDirectoryName. |
|
5067 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
5068 |
"/ ^ nameString |
|
5069 |
"/ ] |
|
5070 |
"/ ]. |
|
15811 | 5071 |
^ OperatingSystem pathNameOf:(self species nameWithSpecialExpansions:nameString). |
2 | 5072 |
|
92 | 5073 |
" |
1317 | 5074 |
'/foo/bar' asFilename pathName |
5075 |
'.' asFilename pathName |
|
5076 |
'../..' asFilename pathName |
|
5077 |
'../..' asFilename name |
|
5078 |
'/tmp/../usr' asFilename pathName |
|
5079 |
'/././usr' asFilename pathName |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5080 |
'~/..' asFilename pathName |
92 | 5081 |
" |
159 | 5082 |
|
1317 | 5083 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 5084 |
! |
5085 |
||
11658 | 5086 |
physicalFilename |
5087 |
"return the fileName representing the physical file as represented by the receiver, |
|
5088 |
If the receiver represents a symbolic link, thats the fileName of the |
|
5089 |
final target. Otherwise, its the receivers pathName itself. |
|
5090 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
|
5091 |
nil is returned." |
|
5092 |
||
5093 |
|pathOrNil| |
|
5094 |
||
5095 |
pathOrNil := self physicalPathName. |
|
5096 |
pathOrNil isNil ifTrue:[ |
|
5097 |
^ nil |
|
5098 |
]. |
|
5099 |
^ pathOrNil asFilename |
|
5100 |
||
5101 |
" |
|
5102 |
'/foo/bar' asFilename physicalFileName |
|
5103 |
" |
|
5104 |
! |
|
5105 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5106 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5107 |
"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
|
5108 |
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
|
5109 |
final target. Otherwise, its the receivers pathName itself. |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5110 |
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
|
5111 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5112 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5113 |
|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
|
5114 |
|
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5115 |
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
|
5116 |
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
|
5117 |
" 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
|
5118 |
^ nil. |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5119 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5120 |
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
|
5121 |
^ 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
|
5122 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5123 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5124 |
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
|
5125 |
[ |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5126 |
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
|
5127 |
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
|
5128 |
"/ 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
|
5129 |
^ nil |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5130 |
]. |
11657 | 5131 |
path asFilename isAbsolute ifTrue:[ |
5132 |
t := path asFilename |
|
5133 |
] ifFalse:[ |
|
15811 | 5134 |
t := (self species named:t directoryName) construct:path. |
11657 | 5135 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5136 |
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
|
5137 |
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
|
5138 |
"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
|
5139 |
^ nil |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5140 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5141 |
] 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
|
5142 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5143 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5144 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5145 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5146 |
'/foo/bar' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5147 |
'.' asFilename physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5148 |
'../..' 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
|
5149 |
'/usr/tmp' asFilename physicalPathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5150 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5151 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5152 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5153 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5154 |
|
615 | 5155 |
tail |
16578 | 5156 |
"the file's name without directory prefix as a string. |
615 | 5157 |
An alias for baseName, for ST-80 compatiblity." |
174 | 5158 |
|
615 | 5159 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5160 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5161 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5162 |
Filename currentDirectory tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5163 |
'Makefile' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5164 |
'/foo/bar/baz.st' asFilename tail |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5165 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5166 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5167 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 5168 |
! |
5169 |
||
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5170 |
tail:nComponents |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5171 |
"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
|
5172 |
- 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
|
5173 |
(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
|
5174 |
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
|
5175 |
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
|
5176 |
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
|
5177 |
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
|
5178 |
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
|
5179 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5180 |
|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
|
5181 |
|
15811 | 5182 |
sep := self species separator. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5183 |
components := self components. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5184 |
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
|
5185 |
start < 1 ifTrue:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5186 |
start := 1. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5187 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5188 |
start = 1 ifTrue:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5189 |
tail := '' |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5190 |
] ifFalse:[ |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5191 |
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
|
5192 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5193 |
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
|
5194 |
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
|
5195 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5196 |
^ tail. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5197 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5198 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5199 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5200 |
'/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
|
5201 |
'/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
|
5202 |
'/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
|
5203 |
'/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
|
5204 |
'.' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5205 |
'..' asFilename tail:3 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5206 |
'../..' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5207 |
'../../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
|
5208 |
'../../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
|
5209 |
'../../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
|
5210 |
'../../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
|
5211 |
'/' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5212 |
'\' asFilename tail:2 |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5213 |
'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
|
5214 |
'\\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
|
5215 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5216 |
! |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5217 |
|
2629 | 5218 |
volume |
5219 |
"return the disc volume part of the name or an empty string. |
|
2906 | 5220 |
This is only used with MSDOS and VMS filenames |
5221 |
- by default (and on unix), an empty string is returned" |
|
5222 |
||
2629 | 5223 |
^ '' |
2906 | 5224 |
|
5225 |
"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
|
5226 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5227 |
|
7120 | 5228 |
!Filename methodsFor:'queries-type'! |
5229 |
||
5230 |
isDirectory |
|
5231 |
"return true, if the receiver represents an existing, |
|
5232 |
readable directories pathname." |
|
5233 |
||
5234 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
|
5235 |
||
5236 |
" |
|
5237 |
'/foo/bar' asFilename isDirectory |
|
5238 |
'/tmp' asFilename isDirectory |
|
5239 |
'Makefile' asFilename isDirectory |
|
5240 |
'c:\' asFilename isDirectory |
|
5241 |
'd:\' asFilename isDirectory |
|
5242 |
" |
|
5243 |
||
5244 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
5245 |
! |
|
5246 |
||
5247 |
isNonEmptyDirectory |
|
5248 |
"return true, if the receiver represents an existing, |
|
5249 |
readable directories pathname, and the directory is not empty." |
|
5250 |
||
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
5251 |
FileStream openErrorSignal |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
5252 |
handle:[:ex ] |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
5253 |
do:[ |
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
5254 |
self directoryContentsDo:[:pathString|^ true]. |
7120 | 5255 |
]. |
5256 |
^ false. |
|
5257 |
||
5258 |
" |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
5259 |
'/foo/bar' asFilename isNonEmptyDirectory |
7120 | 5260 |
'/tmp' asFilename isNonEmptyDirectory |
5261 |
'/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory. |
|
5262 |
'/tmp/empty' asFilename removeDirectory. |
|
5263 |
'Makefile' asFilename isNonEmptyDirectory |
|
5264 |
'c:\' asFilename isNonEmptyDirectory |
|
5265 |
'd:\' asFilename isNonEmptyDirectory |
|
5266 |
" |
|
5267 |
||
5268 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
5269 |
! |
|
5270 |
||
8836 | 5271 |
isRegularFile |
5272 |
"return true, if the receiver represents a plain, regular file" |
|
5273 |
||
5274 |
^ self type == #regular |
|
5275 |
||
5276 |
" |
|
5277 |
'/foo/bar' asFilename isRegularFile |
|
5278 |
'/tmp' asFilename isRegularFile |
|
5279 |
'Makefile' asFilename isRegularFile |
|
5280 |
'c:\' asFilename isRegularFile |
|
5281 |
'd:\' asFilename isRegularFile |
|
5282 |
'/dev/null' asFilename isRegularFile |
|
5283 |
" |
|
5284 |
! |
|
5285 |
||
7120 | 5286 |
isSpecialFile |
5287 |
"return true, if the receiver represents a socket, named pipe, fifo |
|
5288 |
or device special file (i.e. anything non regular and non-directory)" |
|
5289 |
||
5290 |
|t| |
|
5291 |
||
5292 |
t := self type. |
|
5293 |
^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]]) |
|
5294 |
||
5295 |
" |
|
5296 |
'/foo/bar' asFilename isSpecialFile |
|
5297 |
'/tmp' asFilename isSpecialFile |
|
5298 |
'Makefile' asFilename isSpecialFile |
|
5299 |
'c:\' asFilename isSpecialFile |
|
5300 |
'd:\' asFilename isSpecialFile |
|
5301 |
'/dev/null' asFilename isSpecialFile |
|
5302 |
" |
|
5303 |
! |
|
5304 |
||
5305 |
isSymbolicLink |
|
5306 |
"return true, if the file represented by the receiver is a symbolic |
|
5307 |
link. Notice that not all OS's support symbolic links; those that do |
|
5308 |
not will always return false." |
|
5309 |
||
5310 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
|
5311 |
||
5312 |
" |
|
5313 |
'Make.proto' asFilename isSymbolicLink |
|
5314 |
'Makefile' asFilename isSymbolicLink |
|
5315 |
" |
|
5316 |
! ! |
|
5317 |
||
6529 | 5318 |
!Filename methodsFor:'reading-directories'! |
5319 |
||
5320 |
directoryContents |
|
5321 |
"return the contents of the directory as a collection of strings. |
|
5322 |
This excludes any entries for '.' or '..'. |
|
5323 |
Returns nil for non-existing directories; however, this behavior |
|
5324 |
may be changed in the near future, to raise an exception instead. |
|
5325 |
So users of this method better test for existing directory before. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5326 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5327 |
this returns the file-names as strings; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5328 |
see also #directoryContentsAsFilenames, which returns fileName instances." |
6529 | 5329 |
|
12910 | 5330 |
|directoryStream contents| |
5331 |
||
5332 |
contents := OrderedCollection new. |
|
5333 |
directoryStream := DirectoryStream directoryNamed:(self osNameForDirectoryContents). |
|
5334 |
directoryStream isNil ifTrue:[^ nil]. |
|
5335 |
||
5336 |
[ |
|
5337 |
[directoryStream atEnd] whileFalse:[ |
|
5338 |
|entry| |
|
5339 |
||
5340 |
entry := directoryStream nextLine. |
|
5341 |
(entry notNil and:[entry ~= '.' and:[entry ~= '..']]) ifTrue:[ |
|
5342 |
contents add:entry |
|
5343 |
]. |
|
5344 |
]. |
|
6529 | 5345 |
] ensure:[ |
12910 | 5346 |
directoryStream close |
6529 | 5347 |
]. |
5348 |
||
5349 |
^ contents. |
|
5350 |
||
5351 |
" |
|
5352 |
'.' asFilename directoryContents |
|
5353 |
'/XXXdoesNotExist' asFilename directoryContents |
|
5354 |
" |
|
5355 |
||
5356 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
5357 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
|
5358 |
! |
|
5359 |
||
5360 |
directoryContentsAsFilenames |
|
5361 |
"return the contents of the directory as a collection of filenames. |
|
5362 |
This excludes any entries for '.' or '..'. |
|
5363 |
Returns nil for non-existing directories; however, this behavior |
|
5364 |
may be changed in the near future, to raise an exception instead. |
|
5365 |
So users of this method better test for existing directory before. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5366 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5367 |
this returns the file-names as fileName instances; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5368 |
see also #directoryContents, which returns strings." |
6529 | 5369 |
|
5370 |
|names| |
|
5371 |
||
5372 |
names := self directoryContents. |
|
5373 |
names isNil ifTrue:[^ nil]. |
|
12910 | 5374 |
^ names collect:[:entry | self construct:entry]. |
6529 | 5375 |
|
5376 |
" |
|
5377 |
'.' asFilename directoryContentsAsFilenames |
|
5378 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
|
5379 |
" |
|
5380 |
! |
|
5381 |
||
5382 |
fullDirectoryContents |
|
5383 |
"return the full contents of the directory as a collection of strings. |
|
5384 |
This is much like #directoryContents, but includes an entry for the |
|
5385 |
parent directory, if there is one. |
|
5386 |
Returns nil for non-existing directories; however, this behavior |
|
5387 |
may be changed in the near future, to raise an exception instead. |
|
5388 |
So users of this method better test for existing directory before." |
|
5389 |
||
5390 |
|files| |
|
5391 |
||
12910 | 5392 |
"here we get the files without '.' and '..'" |
6529 | 5393 |
files := self directoryContents. |
5394 |
files isNil ifTrue:[ |
|
9453 | 5395 |
"/ mhmh - that one does not exist |
5396 |
^ files |
|
6529 | 5397 |
]. |
5398 |
||
12910 | 5399 |
files addFirst:'..'. |
6529 | 5400 |
^ files |
5401 |
||
5402 |
" |
|
5403 |
'.' asFilename fullDirectoryContents |
|
5404 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
5405 |
'd:\FET' asFilename fullDirectoryContents |
|
5406 |
" |
|
5407 |
||
5408 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
|
5409 |
! |
|
5410 |
||
5411 |
recursiveDirectoryContents |
|
5412 |
"return the contents of the directory and all subdirectories |
|
5413 |
as a collection of strings. |
|
5414 |
This excludes any entries for '.' or '..'. |
|
5415 |
Subdirectory files are included with a relative pathname. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5416 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5417 |
this returns the file-names as strings; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5418 |
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5419 |
|
6529 | 5420 |
Warning: this may take a long time to execute." |
5421 |
||
5422 |
|fileNames dirNames| |
|
5423 |
||
5424 |
fileNames := OrderedCollection new. |
|
5425 |
dirNames := OrderedCollection new. |
|
5426 |
self directoryContents do:[:f | |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5427 |
(self construct:f) isDirectory ifTrue:[ |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5428 |
dirNames add:f |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5429 |
] ifFalse:[ |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5430 |
fileNames add:f |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5431 |
] |
6529 | 5432 |
]. |
5433 |
||
5434 |
dirNames do:[:dN | |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5435 |
|dd subFiles| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5436 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5437 |
dd := dN asFilename. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5438 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5439 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
6529 | 5440 |
]. |
5441 |
^ fileNames. |
|
5442 |
||
5443 |
" |
|
5444 |
'.' asFilename recursiveDirectoryContents |
|
5445 |
'../../clients' asFilename recursiveDirectoryContents |
|
5446 |
" |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5447 |
! |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5448 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5449 |
recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5450 |
"return the contents of the directory and all subdirectories |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5451 |
as a collection of filenames. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5452 |
This excludes any entries for '.' or '..'. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5453 |
Returns nil for non-existing directories; however, this behavior |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5454 |
may be changed in the near future, to raise an exception instead. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5455 |
So users of this method better test for existing directory before. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5456 |
Notice: |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5457 |
this returns the file-names as fileName instances; |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5458 |
see also #recursiveDirectoryContents, which returns strings. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5459 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5460 |
Warning: this may take a long time to execute." |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5461 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5462 |
|names| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5463 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5464 |
names := self recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5465 |
names isNil ifTrue:[^ nil]. |
12910 | 5466 |
^ names collect:[:entry | self construct:entry]. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5467 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5468 |
" |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5469 |
'.' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5470 |
'/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5471 |
" |
6529 | 5472 |
! ! |
5473 |
||
5474 |
!Filename methodsFor:'reading-files'! |
|
5475 |
||
5476 |
binaryContentsOfEntireFile |
|
5477 |
"return the binary contents of the file (as a byteArray); |
|
7680 | 5478 |
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
|
5479 |
|
7680 | 5480 |
^ self |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5481 |
readingFileDo:[:s | |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5482 |
|nBytes bytes n result| |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5483 |
|
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5484 |
s binary. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5485 |
nBytes := self fileSize. |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5486 |
(nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[ |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5487 |
bytes := ByteArray uninitializedNew:nBytes. |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5488 |
n := s nextBytes:nBytes into:bytes startingAt:1. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5489 |
n == nBytes ifTrue:[ |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5490 |
result := bytes |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5491 |
] ifFalse:[ |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5492 |
result := bytes copyTo:n |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5493 |
] |
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5494 |
] ifFalse:[ |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5495 |
result := s contentsOfEntireFile |
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5496 |
]. |
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5497 |
result |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5498 |
] |
6529 | 5499 |
|
5500 |
" |
|
5501 |
'Makefile' asFilename binaryContentsOfEntireFile |
|
5502 |
'foobar' asFilename binaryContentsOfEntireFile |
|
5503 |
" |
|
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5504 |
|
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
5505 |
"Modified: / 27-10-2012 / 19:42:07 / cg" |
6529 | 5506 |
! |
5507 |
||
5508 |
contents |
|
5509 |
"return the contents of the file as a collection of lines; |
|
7680 | 5510 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 5511 |
See also #contentsOfEntireFile, which returns a string for textFiles. |
5512 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
5513 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5514 |
^ self readingFileDo:[:s | s contents]. |
6529 | 5515 |
|
5516 |
" |
|
5517 |
'Makefile' asFilename contents |
|
5518 |
'foobar' asFilename contents |
|
5519 |
" |
|
5520 |
||
5521 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
5522 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
5523 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
5524 |
! |
|
5525 |
||
10780 | 5526 |
contentsAsString |
5527 |
"to compensate for the bad naming, use this to make things explicit. |
|
5528 |
See also #contents, which returns the lines as stringCollection for textFiles." |
|
5529 |
||
11397
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5530 |
^ self contentsOfEntireFile |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5531 |
|
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5532 |
" |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5533 |
'Makefile' asFilename contentsAsString |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
5534 |
'foobar' asFilename contentsAsString |
10780 | 5535 |
" |
5536 |
||
5537 |
"Modified: / 02-07-1996 / 12:49:45 / stefan" |
|
5538 |
"Created: / 08-11-2007 / 13:29:59 / cg" |
|
5539 |
! |
|
5540 |
||
6529 | 5541 |
contentsOfEntireFile |
5542 |
"return the contents of the file as a string; |
|
7680 | 5543 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 5544 |
See also #contents, which returns the lines as stringCollection for textFiles. |
5545 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
5546 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
5547 |
^ self readingFileDo:[:s | s contentsOfEntireFile]. |
6529 | 5548 |
|
5549 |
" |
|
5550 |
'Makefile' asFilename contentsOfEntireFile |
|
5551 |
'foobar' asFilename contentsOfEntireFile |
|
5552 |
" |
|
5553 |
||
5554 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
5555 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
5556 |
! |
|
5557 |
||
5558 |
readingFileDo:aBlock |
|
5559 |
"create a read-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
5560 |
and return the blocks value. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5561 |
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
|
5562 |
(old behavior, will vanish:)the block is evaluated with a nil argument. |
6529 | 5563 |
Ensures that the stream is closed." |
5564 |
||
5565 |
|stream result| |
|
5566 |
||
5567 |
stream := self readStream. |
|
5568 |
[ |
|
5569 |
result := aBlock value:stream |
|
5570 |
] ensure:[ |
|
14628 | 5571 |
stream notNil ifTrue:[stream close] |
6529 | 5572 |
]. |
5573 |
^ result |
|
5574 |
||
5575 |
" |
|
5576 |
read the first line from some file: |
|
5577 |
||
5578 |
|rslt| |
|
5579 |
||
5580 |
rslt := |
|
5581 |
'/etc/passwd' asFilename |
|
5582 |
readingFileDo:[:s | |
|
5583 |
s nextLine |
|
5584 |
]. |
|
5585 |
Transcript showCR:rslt. |
|
5586 |
" |
|
5587 |
||
5588 |
" |
|
5589 |
find all used shells in /etc/passwd and count their usage: |
|
5590 |
||
5591 |
|rslt| |
|
5592 |
||
5593 |
rslt := |
|
5594 |
'/etc/passwd' asFilename |
|
5595 |
readingFileDo: |
|
5596 |
[:s | |
|
5597 |
|shells| |
|
5598 |
||
5599 |
shells := Bag new. |
|
5600 |
s linesDo: |
|
5601 |
[:line | |
|
5602 |
|parts| |
|
5603 |
||
5604 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
5605 |
shells add:(parts seventh). |
|
5606 |
]. |
|
5607 |
shells contents |
|
5608 |
]. |
|
5609 |
Transcript showCR:rslt. |
|
5610 |
" |
|
6771 | 5611 |
! |
5612 |
||
5613 |
readingLinesDo:aBlock |
|
5614 |
"create a read-stream on the receiver file, |
|
5615 |
evaluate aBlock for each line read from the stream. |
|
5616 |
If the file cannot be opened, an error is raised. |
|
5617 |
Ensures that the stream is closed." |
|
5618 |
||
5619 |
self readingFileDo:[:stream | |
|
5620 |
stream linesDo:aBlock |
|
5621 |
]. |
|
5622 |
||
5623 |
" |
|
5624 |
'/etc/passwd' asFilename |
|
5625 |
readingLinesDo:[:eachLine | |
|
5626 |
Transcript showCR:eachLine. |
|
5627 |
]. |
|
5628 |
" |
|
5629 |
||
5630 |
" |
|
5631 |
'/etc/xxxxx' asFilename |
|
5632 |
readingLinesDo:[:eachLine | |
|
5633 |
Transcript showCR:eachLine. |
|
5634 |
]. |
|
5635 |
" |
|
6529 | 5636 |
! ! |
5637 |
||
2922 | 5638 |
!Filename methodsFor:'special accessing'! |
5639 |
||
5640 |
osName |
|
5641 |
"special - return the OS's name for the receiver." |
|
5642 |
||
5643 |
self isDirectory ifTrue:[ |
|
9453 | 5644 |
^ self osNameForDirectory |
2922 | 5645 |
]. |
5646 |
^ self osNameForFile |
|
5647 |
! |
|
5648 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5649 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5650 |
"internal - return the OS's name for the receiver to |
3665 | 5651 |
access its fileInfo. |
5652 |
This may be redefined for systems, where a special suffix must be |
|
5653 |
added in order to access directories (or others) as a file. |
|
5654 |
(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
|
5655 |
|
7064 | 5656 |
^ self osNameForFile |
3665 | 5657 |
|
5658 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5659 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5660 |
|
2922 | 5661 |
osNameForDirectory |
3753 | 5662 |
"internal - return the OS's name for the receiver to |
2922 | 5663 |
access it as a directory." |
5664 |
||
14218 | 5665 |
^ self osNameForFile |
3753 | 5666 |
|
5667 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 5668 |
! |
5669 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5670 |
osNameForDirectoryContents |
3753 | 5671 |
"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
|
5672 |
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
|
5673 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5674 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5675 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5676 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 5677 |
"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
|
5678 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
5679 |
|
2922 | 5680 |
osNameForFile |
5681 |
"internal - return the OS's name for the receiver to |
|
5682 |
access it as a file." |
|
5683 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5684 |
(nameString startsWith:'~') ifFalse:[ |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5685 |
^ nameString. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5686 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5687 |
|
15811 | 5688 |
^ self species nameWithSpecialExpansions:nameString. |
2922 | 5689 |
! ! |
5690 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5691 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5692 |
|
11748 | 5693 |
addSuffix:aSuffix |
14306
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
5694 |
"return a new filename for the receivers name with a additional suffix. |
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
5695 |
The new suffix is simply appended to the name, |
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
5696 |
regardless whether there is already an existing suffix. |
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
5697 |
See also #withSuffix:" |
11748 | 5698 |
|
5699 |
|prefixName| |
|
5700 |
||
5701 |
prefixName := self name. |
|
5702 |
aSuffix isEmptyOrNil ifTrue:[ |
|
15811 | 5703 |
^ self species named:prefixName |
11748 | 5704 |
]. |
5705 |
||
15811 | 5706 |
^ self species named: |
11748 | 5707 |
(prefixName |
15811 | 5708 |
, self species suffixSeparator asString |
11748 | 5709 |
, aSuffix asString) |
5710 |
||
5711 |
" |
|
5712 |
'abc.st' asFilename addSuffix:nil |
|
5713 |
'a.b.c' asFilename addSuffix:nil |
|
5714 |
'.b.c.' asFilename addSuffix:nil |
|
5715 |
'.b.c' asFilename addSuffix:nil |
|
5716 |
'.c.' asFilename addSuffix:nil |
|
5717 |
'.c' asFilename addSuffix:nil |
|
5718 |
'c.' asFilename addSuffix:nil |
|
5719 |
'.' asFilename addSuffix:nil |
|
5720 |
||
5721 |
'abc.st' asFilename addSuffix:'o' |
|
5722 |
'abc' asFilename addSuffix:'o' |
|
5723 |
'a.b.c' asFilename addSuffix:'o' |
|
5724 |
'a.b.c.' asFilename addSuffix:'o' |
|
5725 |
'.b.c.' asFilename addSuffix:'o' |
|
5726 |
'.c.' asFilename addSuffix:'o' |
|
5727 |
'.c' asFilename addSuffix:'o' |
|
5728 |
'c.' asFilename addSuffix:'o' |
|
5729 |
'.' asFilename addSuffix:'o' |
|
5730 |
'/foo/bar/baz.st' asFilename addSuffix:'c' |
|
5731 |
'/foo/bar/baz.c' asFilename addSuffix:'st' |
|
5732 |
'/foo/bar.c/baz.c' asFilename addSuffix:'st' |
|
5733 |
'/foo/bar.c/baz' asFilename addSuffix:'st' |
|
5734 |
" |
|
5735 |
! |
|
5736 |
||
2906 | 5737 |
hasSuffix:aSuffixString |
5738 |
"return true if my suffix is the same as aString. |
|
5739 |
This cares for systems, where case is ignored in filenames" |
|
5740 |
||
5741 |
|mySuffix| |
|
5742 |
||
5743 |
mySuffix := self suffix. |
|
15811 | 5744 |
self species isCaseSensitive ifTrue:[ |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5745 |
^ mySuffix = aSuffixString |
2906 | 5746 |
]. |
5747 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
5748 |
||
5749 |
" |
|
5750 |
'abc.st' asFilename hasSuffix:'st' |
|
5751 |
'abc.ST' asFilename hasSuffix:'st' |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5752 |
'.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
|
5753 |
'.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
|
5754 |
'.foorc.sav' asFilename hasSuffix:'sav' |
2906 | 5755 |
" |
5756 |
||
5757 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
5758 |
! |
|
5759 |
||
10155 | 5760 |
nameWithoutSuffix |
5761 |
"return the receivers name without the suffix. |
|
5762 |
If the name has no suffix, the original name is returned." |
|
5763 |
||
5764 |
|nm idx idxFromEnd| |
|
5765 |
||
5766 |
nm := self baseName. |
|
15811 | 5767 |
idx := nm lastIndexOf:(self species suffixSeparator). |
10155 | 5768 |
(idx == 0) ifTrue:[^ nameString]. |
5769 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
|
5770 |
"/ the suffix is considered empty. |
|
5771 |
(idx == 1) ifTrue:[^ nameString]. |
|
5772 |
||
5773 |
idxFromEnd := nm size - idx. |
|
5774 |
idx := nameString size - idxFromEnd. |
|
5775 |
||
5776 |
^ nameString copyTo:(idx - 1) |
|
5777 |
||
5778 |
" |
|
5779 |
'abc.st' asFilename nameWithoutSuffix |
|
5780 |
'abc' asFilename nameWithoutSuffix |
|
5781 |
'/abc' asFilename nameWithoutSuffix |
|
5782 |
'/abc.d' asFilename nameWithoutSuffix |
|
5783 |
'./abc' asFilename nameWithoutSuffix |
|
5784 |
'./abc.d' asFilename nameWithoutSuffix |
|
5785 |
'./.abc' asFilename nameWithoutSuffix |
|
5786 |
'a.b.c' asFilename nameWithoutSuffix |
|
5787 |
'a.b.' asFilename nameWithoutSuffix |
|
5788 |
'.b.c' asFilename nameWithoutSuffix |
|
5789 |
'.b.' asFilename nameWithoutSuffix |
|
5790 |
'.b' asFilename nameWithoutSuffix |
|
5791 |
'/foo/bar/baz.c' asFilename nameWithoutSuffix |
|
5792 |
'/foo/bar.x/baz.c' asFilename nameWithoutSuffix |
|
5793 |
'/foo/bar.x/baz' asFilename nameWithoutSuffix |
|
5794 |
'/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix |
|
5795 |
'/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix |
|
5796 |
" |
|
5797 |
||
5798 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
|
5799 |
"Created: / 07-11-2006 / 13:55:18 / cg" |
|
5800 |
! |
|
5801 |
||
9453 | 5802 |
prefix |
5803 |
"return my prefix. |
|
5804 |
The suffix is the namepart after the final period character, |
|
5805 |
or the empty string, if the name does not contain a period." |
|
5806 |
||
5807 |
^ self prefixAndSuffix at:1 |
|
5808 |
||
5809 |
" |
|
5810 |
'abc.st' asFilename prefix |
|
5811 |
'abc' asFilename prefix |
|
5812 |
'a.b.c' asFilename prefix |
|
5813 |
'a.b.c' asFilename prefix |
|
5814 |
'a.' asFilename prefix |
|
5815 |
'.a' asFilename prefix |
|
5816 |
" |
|
5817 |
||
5818 |
"Modified: / 07-09-1995 / 11:09:03 / claus" |
|
5819 |
"Created: / 13-07-2006 / 10:27:19 / fm" |
|
5820 |
! |
|
5821 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5822 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5823 |
"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
|
5824 |
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
|
5825 |
the prefix everything before, except for the period. |
1517 | 5826 |
The directory name part is stripped off (i.e. the returned prefix |
16578 | 5827 |
will consist of the file's basename only.) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5828 |
(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
|
5829 |
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
|
5830 |
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
|
5831 |
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
|
5832 |
'.foorc'. |
1517 | 5833 |
See also: #withoutSuffix and #withSuffix |
5834 |
Notice: |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5835 |
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
|
5836 |
the period character as suffixCharacter." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5837 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5838 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5839 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5840 |
nm := self baseName. |
15811 | 5841 |
idx := nm lastIndexOf:(self species suffixSeparator). |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5842 |
"/ 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
|
5843 |
"/ the suffix is considered empty. |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5844 |
((idx == 1) or:[ idx == 0 ]) ifTrue:[ |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5845 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5846 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5847 |
^ Array |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5848 |
with:(nm copyTo:idx-1) |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5849 |
with:(nm copyFrom:idx+1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5850 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5851 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5852 |
'abc.st' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5853 |
'abc' asFilename prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5854 |
'a.b.c' asFilename prefixAndSuffix |
1517 | 5855 |
'/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
|
5856 |
'a.' asFilename prefixAndSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5857 |
'.a' asFilename prefixAndSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5858 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5859 |
|parts| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5860 |
parts := 'Object.st' asFilename prefixAndSuffix. |
1517 | 5861 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5862 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5863 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5864 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 5865 |
"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
|
5866 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5867 |
|
2906 | 5868 |
suffix |
5869 |
"return my suffix. |
|
5870 |
The suffix is the namepart after the final period character, |
|
5871 |
or the empty string, if the name does not contain a period." |
|
5872 |
||
5873 |
^ self prefixAndSuffix at:2 |
|
5874 |
||
5875 |
" |
|
5876 |
'abc.st' asFilename suffix |
|
5877 |
'abc' asFilename suffix |
|
5878 |
'a.b.c' asFilename suffix |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5879 |
'a.b.c' asFilename suffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5880 |
'a.' asFilename suffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5881 |
'.a' asFilename suffix |
2906 | 5882 |
" |
5883 |
||
5884 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
5885 |
! |
|
5886 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5887 |
withSuffix:aSuffix |
2922 | 5888 |
"return a new filename for the receivers name with a different suffix. |
6256 | 5889 |
If the name already has a suffix, the new suffix replaces it; |
1993 | 5890 |
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
|
5891 |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5892 |
|prefixName| |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5893 |
|
10155 | 5894 |
prefixName := self nameWithoutSuffix. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5895 |
aSuffix isEmptyOrNil ifTrue:[ |
15811 | 5896 |
^ self species named:prefixName |
6262 | 5897 |
]. |
5898 |
||
15811 | 5899 |
^ self species named: |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5900 |
(prefixName |
6256 | 5901 |
, self class suffixSeparator asString |
5902 |
, aSuffix asString) |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5903 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5904 |
" |
6262 | 5905 |
'abc.st' asFilename withSuffix:nil |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5906 |
'a.b.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5907 |
'.b.c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5908 |
'.b.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5909 |
'.c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5910 |
'.c' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5911 |
'c.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5912 |
'.' asFilename withSuffix:nil |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5913 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5914 |
'abc.st' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5915 |
'abc' asFilename withSuffix:'o' |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5916 |
'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
|
5917 |
'a.b.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5918 |
'.b.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5919 |
'.c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5920 |
'.c' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5921 |
'c.' asFilename withSuffix:'o' |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5922 |
'.' asFilename withSuffix:'o' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5923 |
'/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
|
5924 |
'/foo/bar/baz.c' asFilename withSuffix:'st' |
1517 | 5925 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
1993 | 5926 |
'/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
|
5927 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5928 |
|
10155 | 5929 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
5930 |
"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
|
5931 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5932 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5933 |
withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5934 |
"return a new filename for the receivers name without the suffix. |
10155 | 5935 |
If the name has no suffix, a filename representing the same file as the receiver is returned." |
5936 |
||
5937 |
|n| |
|
5938 |
||
5939 |
n := self nameWithoutSuffix. |
|
5940 |
n = nameString ifTrue:[^ self]. |
|
15811 | 5941 |
^ self species named:n |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5942 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5943 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5944 |
'abc.st' asFilename withoutSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5945 |
'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
|
5946 |
'/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
|
5947 |
'/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
|
5948 |
'./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
|
5949 |
'./abc.d' asFilename withoutSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5950 |
'./.abc' asFilename withoutSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5951 |
'a.b.c' asFilename withoutSuffix |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5952 |
'a.b.' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5953 |
'.b.c' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5954 |
'.b.' asFilename withoutSuffix |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
5955 |
'.b' asFilename withoutSuffix |
1516 | 5956 |
'/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
|
5957 |
'/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
|
5958 |
'/foo/bar.x/baz' asFilename withoutSuffix |
1516 | 5959 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
5960 |
'/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
|
5961 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5962 |
|
10155 | 5963 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
5964 |
"Modified: / 07-11-2006 / 13:57:45 / cg" |
|
174 | 5965 |
! ! |
5966 |
||
5597 | 5967 |
!Filename methodsFor:'testing'! |
5968 |
||
5969 |
isFilename |
|
5970 |
"return true, if the receiver is some kind of filename; |
|
5971 |
false is returned here - the method is redefined from Object." |
|
5972 |
||
5973 |
^true |
|
5974 |
||
5975 |
||
5976 |
! ! |
|
5977 |
||
10271 | 5978 |
!Filename methodsFor:'writing-files'! |
5979 |
||
14512 | 5980 |
appendingFileDo:aBlock |
5981 |
"create a append-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
5982 |
and return the blocks value. |
|
5983 |
If the file cannot be opened, an exception is raised. |
|
5984 |
Ensures that the stream is closed." |
|
5985 |
||
5986 |
|stream result| |
|
5987 |
||
5988 |
stream := self appendStream. |
|
5989 |
[ |
|
5990 |
result := aBlock value:stream |
|
5991 |
] ensure:[ |
|
5992 |
stream close |
|
5993 |
]. |
|
5994 |
^ result |
|
5995 |
||
5996 |
" |
|
14513 | 5997 |
'ttt' asFilename appendingFileDo:[:s | |
14512 | 5998 |
s nextPutLine:'hello'. |
5999 |
s nextPutLine:'world'. |
|
14513 | 6000 |
] |
14512 | 6001 |
" |
6002 |
||
6003 |
"Created: / 09-11-2012 / 10:07:41 / sr" |
|
6004 |
! |
|
6005 |
||
10779 | 6006 |
contents:aStringOrCollectionOfLines |
10271 | 6007 |
"create (or overwrite) a file given its contents as a collection of lines. |
6008 |
Raises an error, if the file is unwritable." |
|
6009 |
||
10779 | 6010 |
^ self |
6011 |
writingFileDo:[:s | |
|
11748 | 6012 |
aStringOrCollectionOfLines isNonByteCollection ifTrue:[ |
6013 |
"a StringCollection or a collection of lines" |
|
6014 |
aStringOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')] |
|
6015 |
] ifFalse:[ |
|
6016 |
"something string-like" |
|
11877 | 6017 |
aStringOrCollectionOfLines isString ifFalse:[ |
6018 |
s binary |
|
6019 |
]. |
|
10779 | 6020 |
s nextPutAll:aStringOrCollectionOfLines |
6021 |
] |
|
6022 |
]. |
|
6023 |
||
6024 |
" |
|
6025 |
'foo1' asFilename contents:#('one' 'two' 'three') |
|
6026 |
'foo2' asFilename contents:'Hello world' |
|
15023 | 6027 |
'foo3' asFilename contents:#[1 2 3 4 5] |
10271 | 6028 |
" |
6029 |
||
6030 |
"Created: / 11-12-2006 / 14:11:21 / cg" |
|
10779 | 6031 |
"Modified: / 08-11-2007 / 13:28:41 / cg" |
10271 | 6032 |
! |
6033 |
||
6034 |
writingFileDo:aBlock |
|
6035 |
"create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
6036 |
and return the blocks value. |
|
6037 |
If the file cannot be opened, an exception is raised. |
|
6038 |
Ensures that the stream is closed." |
|
6039 |
||
6040 |
|stream result| |
|
6041 |
||
6042 |
stream := self writeStream. |
|
6043 |
[ |
|
6044 |
result := aBlock value:stream |
|
6045 |
] ensure:[ |
|
6046 |
stream close |
|
6047 |
]. |
|
6048 |
^ result |
|
6049 |
||
6050 |
" |
|
6051 |
'ttt' asFilename writingFileDo:[:s | |
|
6052 |
s nextPutLine:'hello'. |
|
6053 |
s nextPutLine:'world'. |
|
6054 |
] |
|
6055 |
" |
|
6056 |
||
6057 |
"Created: / 11-12-2006 / 14:09:39 / cg" |
|
6058 |
! ! |
|
6059 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
6060 |
!Filename class methodsFor:'documentation'! |
630 | 6061 |
|
6062 |
version |
|
17113 | 6063 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.431 2014-11-23 16:51:36 cg Exp $' |
12318 | 6064 |
! |
6065 |
||
6066 |
version_CVS |
|
17113 | 6067 |
^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.431 2014-11-23 16:51:36 cg Exp $' |
630 | 6068 |
! ! |
6771 | 6069 |
|
14628 | 6070 |
|
2906 | 6071 |
Filename initialize! |