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