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