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