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