Filename.st
author Claus Gittinger <cg@exept.de>
Tue, 26 Nov 2002 11:06:34 +0100
changeset 6893 9aa286d3a644
parent 6839 d5bc53f68bab
child 6908 27f9f8eceb56
permissions -rw-r--r--
added newTemporary with template
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 132
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
    13
"{ Package: 'stx:libbasic' }"
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
    14
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    15
Object subclass:#Filename
844
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
    16
	instanceVariableNames:'nameString'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
    17
	classVariableNames:'NextTempFilenameIndex ConcreteClass'
844
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
    18
	poolDictionaries:''
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
    19
	category:'System-Support'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
    20
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    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
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    23
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    24
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    25
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
 COPYRIGHT (c) 1992 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 132
diff changeset
    27
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    30
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
    Filenames; originally added for ST-80 compatibility, is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
    taking over functionality from other classes (FileDirectory).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    42
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    43
    Instances of Filename do not nescessarily represent valid or existing
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    44
    files - i.e. it is possible (and useful) to have instances for non-existing
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    45
    files around. In other words: the name-string is not checked automatically
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    46
    for being correct or existing.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    47
    Thus, it is possible to do queries such as:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    48
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    49
	'/fee/foo/foe' asFilename exists     
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    50
	'/not_existing' asFilename isDirectory 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    51
	'/foo/bar' asFilename isReadable 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    52
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
    53
    (all of the above examples will probably return false on your machine ;-).
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    54
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    55
    examples:
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    56
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    57
	'Makefile' asFilename readStream
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    58
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    59
	'newFile' asFilename writeStream
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    60
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    61
	Filename newTemporary writeStream
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    62
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    63
    Beside lots of protocol to query for a files attributes, the class
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    64
    protocol offers methods for filename completion, to construct pathes
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    65
    (in an OS-independent way) and to create temporary files.
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    66
    Especially the path-construction methods (i.e. #construct:) are highly
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    67
    recommended in order to avoid having OS details (like directory separators
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    68
    being slash or backslash) spreaded in your application.
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    69
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1225
diff changeset
    70
    [author:]
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    71
	Claus Gittinger
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    72
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1225
diff changeset
    73
    [see also:]
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    74
	String
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    75
	FileStream DirectoryStream PipeStream Socket
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    76
	OperatingSystem
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    77
	Date Time
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    78
"
360
claus
parents: 359
diff changeset
    79
!
claus
parents: 359
diff changeset
    80
claus
parents: 359
diff changeset
    81
examples
claus
parents: 359
diff changeset
    82
"
claus
parents: 359
diff changeset
    83
    does a file/directory exist ?:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    84
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    85
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    86
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    87
	f := 'foobar' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    88
	^ f exists  
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    89
									[exEnd]
360
claus
parents: 359
diff changeset
    90
claus
parents: 359
diff changeset
    91
claus
parents: 359
diff changeset
    92
    is it a directory ?:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    93
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    94
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    95
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    96
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    97
	^ f isDirectory.   
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    98
									[exEnd]
360
claus
parents: 359
diff changeset
    99
claus
parents: 359
diff changeset
   100
        
claus
parents: 359
diff changeset
   101
    get the working directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   102
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   103
	^ Filename defaultDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   104
									[exEnd]
360
claus
parents: 359
diff changeset
   105
claus
parents: 359
diff changeset
   106
claus
parents: 359
diff changeset
   107
    get a files full pathname 
claus
parents: 359
diff changeset
   108
    (caring for relative names or symbolic links):
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   109
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   110
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   111
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   112
	f := '..' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   113
	^ f pathName  
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   114
									[exEnd]
360
claus
parents: 359
diff changeset
   115
claus
parents: 359
diff changeset
   116
claus
parents: 359
diff changeset
   117
    get a directories directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   118
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   119
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   120
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   121
	f := Filename defaultDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   122
	^ f directory 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   123
									[exEnd]
360
claus
parents: 359
diff changeset
   124
claus
parents: 359
diff changeset
   125
claus
parents: 359
diff changeset
   126
    get a files directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   127
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   128
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   129
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   130
	f := './smalltalk' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   131
	^ f directory 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   132
									[exEnd]
360
claus
parents: 359
diff changeset
   133
claus
parents: 359
diff changeset
   134
claus
parents: 359
diff changeset
   135
    getting access & modification times:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   136
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   137
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   138
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   139
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   140
	^ f dates
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   141
									[exEnd]
360
claus
parents: 359
diff changeset
   142
claus
parents: 359
diff changeset
   143
    access time only:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   144
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   145
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   146
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   147
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   148
	^ f dates at:#accessed  
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   149
									[exEnd]
360
claus
parents: 359
diff changeset
   150
        
claus
parents: 359
diff changeset
   151
claus
parents: 359
diff changeset
   152
    getting all information on a file/directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   153
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   154
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   155
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   156
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   157
	^ f info
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   158
									[exEnd]
360
claus
parents: 359
diff changeset
   159
claus
parents: 359
diff changeset
   160
claus
parents: 359
diff changeset
   161
    getting a temporary file (unique name):
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   162
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   163
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   164
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   165
	f := Filename newTemporary.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   166
	^ f    
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   167
									[exEnd]
360
claus
parents: 359
diff changeset
   168
claus
parents: 359
diff changeset
   169
    creating, writing, reading and removing a temporary file:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   170
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   171
	|f writeStream readStream|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   172
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   173
	f := Filename newTemporary.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   174
	writeStream := f writeStream.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   175
	writeStream nextPutAll:'hello world'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   176
	writeStream cr.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   177
	writeStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   178
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   179
	'contents (as seen by unix''s cat command:' printNL.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   180
	OperatingSystem executeCommand:('cat ' , f pathName).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   181
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   182
	readStream := f readStream.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   183
	Transcript showCR:'contents as seen by smalltalk:'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   184
	Transcript showCR:(readStream upToEnd).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   185
	readStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   186
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   187
	f delete.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   188
									[exEnd]
360
claus
parents: 359
diff changeset
   189
        
claus
parents: 359
diff changeset
   190
claus
parents: 359
diff changeset
   191
    getting a directories contents:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   192
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   193
	|f files|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   194
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   195
	f := Filename currentDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   196
	files := f directoryContents.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   197
	Transcript showCR:'the files are:'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   198
	Transcript showCR:(files printString).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   199
									[exEnd]
360
claus
parents: 359
diff changeset
   200
claus
parents: 359
diff changeset
   201
claus
parents: 359
diff changeset
   202
    editing a file:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   203
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   204
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   205
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   206
	f := Filename newTemporary.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   207
	(f writeStream) nextPutAll:'hello world'; close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   208
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   209
	f edit
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   210
									[exEnd]
360
claus
parents: 359
diff changeset
   211
"
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   212
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   213
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   214
!Filename class methodsFor:'initialization'!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   215
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   216
initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   217
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   218
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   219
    self initializeConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   220
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   221
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   222
     self initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   223
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   224
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   225
    "Created: 7.9.1997 / 23:32:55 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   226
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   227
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   228
initializeConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   229
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   230
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   231
    OperatingSystem isMSDOSlike ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   232
	ConcreteClass := PCFilename
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   233
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   234
	OperatingSystem isVMSlike ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   235
	    ConcreteClass := OpenVMSFilename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   236
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   237
	    OperatingSystem isUNIXlike ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   238
		ConcreteClass := UnixFilename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   239
	    ] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   240
		ConcreteClass := nil
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   241
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   242
	]
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   243
    ]
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   244
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   245
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   246
     self initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   247
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   248
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   249
    "Modified: 7.9.1997 / 23:32:37 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   250
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   251
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   252
reinitialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   253
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   254
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   255
    self initializeConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   256
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   257
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   258
     self initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   259
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   260
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   261
    "Created: 7.9.1997 / 23:33:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   262
! !
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   263
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   264
!Filename class methodsFor:'instance creation'!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   265
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   266
currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   267
    "return a filename for the current directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   268
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   269
    (self ~~ ConcreteClass) ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   270
        ^ ConcreteClass currentDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   271
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   272
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   273
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   274
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   275
    ^ self named:'.'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   276
    "/ ^ self named:('.' asFilename pathName)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   277
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   278
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   279
     Filename currentDirectory 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   280
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   281
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   282
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   283
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   284
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   285
currentDirectoryName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   286
    "return a filename for the current directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   287
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   288
    (self ~~ ConcreteClass) ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   289
        ^ ConcreteClass currentDirectoryName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   290
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   291
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   292
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   293
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   294
    ^ '.'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   295
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   296
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   297
     Filename currentDirectoryName    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   298
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   299
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   300
    "Modified: / 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   301
    "Created: / 21.10.1998 / 17:49:57 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   302
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   303
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   304
defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   305
    "ST80 compatibility: same as currentDirectory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   306
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   307
    ^ self currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   308
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   309
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   310
     Filename defaultDirectory 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   311
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   312
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   313
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   314
defaultDirectoryName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   315
    "ST80 compatibility: return the defaultDirectories name (as a string)"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   316
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   317
    ^ self defaultDirectory name
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   318
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   319
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   320
     Filename defaultDirectoryName 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   321
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   322
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   323
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   324
defaultTempDirectoryName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   325
    "return the default temp directory as a filename.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   326
     This is used, if no special preferences were defined in
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   327
     any of the TEMP-environment variables (see tempDirectory)."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   328
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   329
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   330
	^ ConcreteClass defaultTempDirectoryName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   331
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   332
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   333
    ^ '/tmp'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   334
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   335
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   336
     Filename defaultTempDirectoryName           
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   337
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   338
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   339
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   340
    "Created: 7.3.1996 / 14:51:18 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   341
    "Modified: 8.9.1997 / 00:24:53 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   342
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   343
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   344
findDefaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   345
    "same as #defaultDirectory for ST80 compatibility"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   346
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   347
    ^ self defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   348
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   349
    "Created: 20.6.1997 / 17:00:29 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   350
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   351
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   352
fromComponents:aCollectionOfDirectoryNames
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   353
    "create & return a new filename from components given in
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   354
     aCollectionOfDirectoryNames. If the first component is the name of the
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   355
     root directory (i.e. '/') an absolute path-filename is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   356
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   357
    (self ~~ ConcreteClass) ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   358
        ^ ConcreteClass fromComponents:aCollectionOfDirectoryNames
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   359
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   360
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   361
    ^ self named:(self nameFromComponents:aCollectionOfDirectoryNames)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   362
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   363
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   364
     Filename fromComponents:#('/' 'foo' 'bar' 'baz')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   365
     Filename fromComponents:#('foo' 'bar' 'baz')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   366
     Filename fromComponents:#('/')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   367
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   368
     Filename fromComponents:
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   369
         (Filename components:('.' asFilename pathName))
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   370
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   371
     Filename fromComponents:
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   372
         (Filename components:('.' asFilename name)) 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   373
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   374
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   375
    "Modified: 8.9.1997 / 00:23:16 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   376
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   377
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   378
fromUser
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   379
    "show a box to enter a filename. 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   380
     Return a filename instance or nil (if cancel was pressed)."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   381
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   382
    |name|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   383
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   384
    name := Dialog 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   385
	requestFileName:'filename:' 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   386
	default:nil
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   387
	fromDirectory:(FileSelectionBox lastFileSelectionDirectory).
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   388
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   389
    name size > 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   390
	^ self named:name
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   391
    ].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   392
    ^ nil
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   393
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   394
    "
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   395
     Filename fromUser 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   396
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   397
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   398
    "Modified: 19.4.1996 / 13:57:44 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   399
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   400
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   401
homeDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   402
    "return your homeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   403
     Some OperatingSystems do not support this - on those, the defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   404
     (which is the currentDirectory) is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   405
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   406
    |s|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   407
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   408
    s := OperatingSystem getHomeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   409
    s isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   410
	^ self defaultDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   411
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   412
    ^ self named:s
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   413
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   414
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   415
     Filename homeDirectory        
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   416
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   417
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   418
    "Modified: 8.9.1997 / 00:25:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   419
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   420
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   421
named:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   422
    "return a filename for a directory named aString.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   423
     This is the same as 'aString asFilename'."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   424
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   425
    |cls|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   426
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   427
    cls := self.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   428
    cls == Filename ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   429
	cls := self concreteClass
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   430
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   431
    ^ (cls basicNew) setName:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   432
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   433
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   434
     Filename named:'/tmp/fooBar'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   435
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   436
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   437
    "Modified: 7.9.1997 / 23:30:06 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   438
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   439
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   440
newTemporary
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   441
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   442
     The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   443
     unix process id, and nn is a unique number, incremented with every
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   444
     call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   445
     If any of the environment variables ST_TMPDIR or TMPDIR is set, 
4757
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   446
     its value defines the temp directory.
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   447
     Notice, that no file is created by this - only a unique name
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   448
     is generated."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   449
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   450
    ^ self newTemporaryIn:(self tempDirectory) pathName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   451
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   452
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   453
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   454
     Filename newTemporary     
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   455
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   456
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   457
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   458
    "Modified: 7.3.1996 / 14:51:33 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   459
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   460
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   461
newTemporaryIn:aDirectoryPrefix
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   462
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   463
     The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn',
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   464
     where xx is our unix process id, and nn is a unique number, incremented 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   465
     with every call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   466
     Notice: only a unique filename object is created and returned - no physical
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   467
     file is created by this method (i.e. you have to send #writeStream or
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   468
     whatever to it in order to really create something).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   469
     See also: #newTemporary which looks for a good temp directory."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   470
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   471
    ^ self newTemporaryIn:aDirectoryPrefix nameTemplate:self tempFileNameTemplate
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   472
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   473
    "temp files in '/tmp':
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   474
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   475
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   476
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   477
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   478
    "temp files somewhere 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   479
     (not recommended - use above since it can be controlled via shell variables):
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   480
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   481
     UnixFilename newTemporaryIn:'/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   482
     UnixFilename newTemporaryIn:'/tmp'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   483
     UnixFilename newTemporaryIn:'/usr/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   484
     UnixFilename newTemporaryIn:'/'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   485
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   486
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   487
    "a local temp file:
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   488
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   489
     Filename newTemporaryIn:''         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   490
     Filename newTemporaryIn:nil         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   491
     Filename newTemporaryIn:'.'         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   492
     Filename newTemporaryIn:('source' asFilename) 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   493
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   494
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   495
    "Modified: / 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   496
    "Modified: / 11.8.1998 / 22:51:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   497
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   498
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   499
newTemporaryIn:aDirectoryPrefix nameTemplate:template
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   500
    "return a new unique filename - use this for temporary files.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   501
     The filenames returned are in aDirectoryPrefix and named after the given template,
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   502
     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
   503
     with every call to this method respectively.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   504
     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
   505
     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
   506
     whatever to it in order to really create something).
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   507
     See also: #newTemporary which looks for a good temp directory."
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   508
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   509
    |pid nameString fn|
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   510
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   511
    (self ~~ ConcreteClass) ifTrue:[
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   512
        ^ ConcreteClass newTemporaryIn:aDirectoryPrefix nameTemplate:template
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   513
    ].
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   514
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   515
    "/ care for existing leftOver tempFiles
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   516
    "/ from a previous boot of the OS
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   517
    "/ (i.e. my pid could be the same as when executed
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   518
    "/  the last time before system reboot ...)
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   519
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   520
    [fn isNil or:[fn exists]] whileTrue:[
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   521
        "/ although the above allows things to be redefined in concrete classes,
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   522
        "/ the following should work on all systems ...
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   523
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   524
        NextTempFilenameIndex isNil ifTrue:[
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   525
            NextTempFilenameIndex := 1.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   526
        ].
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   527
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   528
        pid := OperatingSystem getProcessId printString.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   529
        nameString := template bindWith:pid with:(NextTempFilenameIndex printString).
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   530
        NextTempFilenameIndex := NextTempFilenameIndex + 1.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   531
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   532
        (aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   533
            fn := aDirectoryPrefix asFilename construct:nameString
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   534
        ] ifTrue:[
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   535
            fn := self named:nameString
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   536
        ]
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   537
    ].
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   538
    ^ fn
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   539
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   540
    "temp files in '/tmp':
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   541
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   542
     Filename newTemporary    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   543
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   544
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   545
    "temp files somewhere 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   546
     (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
   547
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   548
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   549
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'  
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   550
     UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2'    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   551
     UnixFilename newTemporaryIn:'/'        nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   552
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   553
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   554
    "a local temp file:
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   555
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   556
     Filename newTemporaryIn:''             nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   557
     Filename newTemporaryIn:nil            nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   558
     Filename newTemporaryIn:'.'            nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   559
     Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   560
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   561
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   562
    "Modified: / 7.9.1995 / 10:48:31 / claus"
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   563
    "Modified: / 11.8.1998 / 22:51:43 / cg"
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   564
!
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   565
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   566
nullDevice
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   567
    "return the filename of the nullDevice (if available).
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   568
     returns nil, if the OperatingSystem does not support this."
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   569
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   570
    |s|
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   571
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   572
    s := OperatingSystem getNullDevice.
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   573
    s isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   574
	^ nil
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   575
    ].
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   576
    ^ self named:s
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   577
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   578
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   579
     Filename nullDevice        
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   580
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   581
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   582
    "Created: / 19.5.1999 / 12:24:26 / cg"
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   583
!
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   584
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   585
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   586
    "create & return a new filename from components given in
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   587
     aCollectionOfDirectoryNames on a host named remoteHostString. 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   588
     An absolute network-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   589
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   590
    self ~~ ConcreteClass ifTrue:[
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   591
        ^ ConcreteClass remoteHost:remoteHostString 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   592
                        rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   593
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   594
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   595
    self error:'remote hosts not supported by OS'.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   596
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   597
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   598
rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   599
    "create & return a new filename from components given in
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   600
     aCollectionOfDirectoryNames. 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   601
     An absolute path-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   602
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   603
    |sep s|
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   604
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   605
    (self ~~ ConcreteClass) ifTrue:[
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   606
        ^ ConcreteClass rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   607
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   608
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   609
    "/ fallBack - works on Unix & MSDOS
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   610
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   611
    sep := self separator asString.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   612
    s := WriteStream on:''.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   613
    aCollectionOfDirectoryNames do:[:component |
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   614
        component ~= sep ifTrue:[
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   615
            s nextPutAll:sep; nextPutAll:component
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   616
        ]
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   617
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   618
    s := s contents.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   619
    s size == 0 ifTrue:[s := sep].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   620
    ^ self named:s
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   621
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   622
    "
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   623
     Filename rootComponents:#('/' 'foo' 'bar' 'baz')  
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   624
     Filename rootComponents:#('foo' 'bar' 'baz')  
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   625
     Filename rootComponents:#('/')  
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   626
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   627
     Filename rootComponents:
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   628
         (Filename components:('.' asFilename pathName))
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   629
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   630
     Filename rootComponents:
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   631
         (Filename components:('.' asFilename name)) 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   632
    "
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   633
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   634
    "Modified: 8.9.1997 / 00:23:16 / cg"
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   635
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   636
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   637
rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   638
    "return a filename for the root directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   639
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   640
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   641
	^ ConcreteClass rootDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   642
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   643
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   644
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   645
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   646
    ^ self named:(self separator asString)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   647
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   648
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   649
     Filename rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   650
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   651
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   652
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   653
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   654
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   655
rootDirectoryOnVolume:aVolumeName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   656
    "return a filename for the root directory on some volume"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   657
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   658
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   659
	^ ConcreteClass rootDirectoryOnVolume:aVolumeName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   660
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   661
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   662
    "/ fallBack - works on Unix (not on MSDOS or VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   663
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   664
    ^ self rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   665
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   666
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   667
     Filename rootDirectoryOnVolume:'/phys/idefix'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   668
     Filename rootDirectoryOnVolume:'d:'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   669
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   670
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   671
    "Modified: / 5.10.1998 / 12:45:39 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   672
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   673
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   674
tempDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   675
    "return the temp directory as a filename.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   676
     If any of the environment variables STX_TMPDIR, ST_TMPDIR,
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   677
     TMPDIR or TEMPDIR is set, its value defines the name, 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   678
     otherwise, '/tmp' is used. (at least on unix ...).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   679
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   680
     Notice: do not hardcode '/tmp' into your programs - things may be
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   681
	     different on other OS's. Also, the user may want to set the
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   682
	     TMPDIR environment variable to have her temp files somewhere else.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   683
	     (especially on SUNOS, the root partition is ALWAYS too small ..."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   684
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   685
    |tempDir|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   686
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   687
    #('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   688
	tempDir isNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   689
	    tempDir := OperatingSystem getEnvironment:envVar.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   690
	].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   691
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   692
    tempDir isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   693
	tempDir := self defaultTempDirectoryName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   694
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   695
    ^ self named:tempDir
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   696
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   697
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   698
     Filename tempDirectory           
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   699
     Filename tempDirectory pathName   
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   700
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   701
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   702
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   703
    "Created: 7.3.1996 / 14:51:18 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   704
    "Modified: 8.9.1997 / 00:08:11 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   705
! !
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   706
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   707
!Filename class methodsFor:'defaults'!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   708
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   709
concreteClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   710
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   711
     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
   712
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   713
    ^ ConcreteClass ? self
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   714
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   715
    "Created: 14.2.1997 / 16:36:13 / cg"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   716
    "Modified: 7.9.1997 / 23:29:20 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   717
!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   718
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   719
defaultClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   720
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   721
     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
   722
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   723
    ^ ConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   724
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   725
    "Modified: 8.9.1997 / 00:36:01 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   726
! !
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   727
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   728
!Filename class methodsFor:'misc'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   729
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   730
canonicalize:aPathString
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   731
    "convert the argument, aPathString to a good format.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   732
     This should eliminate useless directory components (i.e. '././')
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   733
     and useless tree walks (i.e. '../foo/..')."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   734
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   735
    |comps newComps parentName currentName rootName|
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   736
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   737
    parentName := self parentDirectoryName.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   738
    currentName := self currentDirectoryName.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   739
    rootName := self rootDirectory name.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   740
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   741
    comps := self components:aPathString.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   742
    newComps := OrderedCollection new.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   743
    comps do:[:eachComponent |
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   744
        eachComponent = currentName ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   745
            eachComponent = parentName ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   746
               (newComps isEmpty 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   747
               or:[ newComps = (Array with:rootName) 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   748
               or:[newComps last = parentName]]) ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   749
                   newComps add:eachComponent
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   750
               ] ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   751
                   newComps removeLast
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   752
               ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   753
            ] ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   754
                newComps add:eachComponent
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   755
            ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   756
        ]
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   757
    ].                               
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   758
    ^ self nameFromComponents:newComps
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   759
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   760
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   761
     Filename canonicalize:'/etc/../etc'      
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   762
     Filename canonicalize:'/home/cg/../'     
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   763
     Filename canonicalize:'/home/cg/../././'  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   764
     Filename canonicalize:'/home/cg/../././'  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   765
     Filename canonicalize:'/home/././cg/../././'   
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   766
     Filename canonicalize:'/home/././cg/././'    
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   767
     Filename canonicalize:'/home/cg/../../..'    
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   768
     Filename canonicalize:'cg/../../..'    
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   769
     Filename canonicalize:'../../..'   
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
   770
     Filename canonicalize:'/home/.'   
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   771
    "
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   772
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   773
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   774
filterSeps:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   775
    "ST80 compatibility:
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   776
     filter out (invalid) separators in aFilenameString.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   777
     We recommend using #makeLegalFilename"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   778
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   779
    ^ aFilenameString copyReplaceAll:(Character space) with:$_.
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   780
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   781
    "Created: / 1.11.1997 / 12:39:50 / cg"
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   782
    "Modified: / 18.7.1998 / 22:53:24 / cg"
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   783
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   784
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   785
suggest:aFilenameString 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   786
    "return a fileNamestring based on the argument, 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   787
     which is legal on the current platform."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   788
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   789
    ^ self canonicalize:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   790
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   791
    "Created: / 1.11.1997 / 12:42:39 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   792
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   793
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
   794
!Filename class methodsFor:'queries'!
2
claus
parents: 1
diff changeset
   795
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   796
components:aString
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   797
    "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
   798
     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
   799
     the final component.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   800
     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
   801
     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
   802
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   803
    |sep f vol rest components|
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   804
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   805
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   806
	^ ConcreteClass components:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   807
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   808
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   809
    "/ the following works on Unix & MSDOS (but not on openVMS)
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   810
    "/ However, MSDOS drive-letters and network drives are
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   811
    "/ not correctly handled here.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   812
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   813
    sep := self separator.
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   814
    f := aString asFilename.
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   815
    vol := f volume.
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   816
    vol size ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   817
	rest := f localPathName.
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   818
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   819
	rest := aString
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   820
    ].
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   821
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   822
    components := rest asCollectionOfSubstringsSeparatedBy:sep.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   823
    components first isEmpty ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   824
	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
   825
    ].
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   826
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   827
    "/ prepend volume to first component (the root directory)
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   828
    vol size ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   829
	components at:1 put:(vol , (components at:1)).
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   830
    ].
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   831
    components last isEmpty ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   832
	^ components copyWithoutLast:1
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   833
    ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   834
    ^ components
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   835
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   836
    "
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   837
     Filename components:'/foo/bar/baz'      
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   838
     Filename components:'/'     
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   839
     Filename components:'foo/bar/baz'  
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   840
     Filename components:'foo/bar'  
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   841
     Filename components:'foo'     
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   842
     Filename components:'/foo'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   843
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   844
     Filename components:'\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   845
     Filename components:'\foo'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   846
     Filename components:'\foo\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   847
     Filename components:'\foo\bar'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   848
     Filename components:'\foo\bar\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   849
     Filename components:'c:'        
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   850
     Filename components:'c:\'       
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   851
     Filename components:'c:\foo'      
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   852
     Filename components:'c:\foo\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   853
     Filename components:'c:\foo\bar'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   854
     Filename components:'c:\foo\bar\'  
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   855
     Filename components:'\\idefix'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   856
     Filename components:'\\idefix\home'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   857
     Filename components:'\\idefix\home\bar'    
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   858
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   859
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   860
    "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
   861
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   862
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   863
directorySuffix
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   864
    "Return the OS dependent directory suffix string, or nil if there is none.
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   865
     The default is nil here, redefined for VMS"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   866
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   867
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   868
	^ ConcreteClass directorySuffix
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   869
    ].
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   870
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   871
    ^ nil
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   872
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   873
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   874
errorReporter
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   875
    "who knows the signals to report errors?"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   876
        
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   877
    ^ FileStream
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   878
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   879
    "Created: 2.7.1996 / 12:30:25 / stefan"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   880
!
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   881
440
claus
parents: 422
diff changeset
   882
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock
claus
parents: 422
diff changeset
   883
    "perform filename completion on aString in some directory;
claus
parents: 422
diff changeset
   884
     return the longest matching filename prefix as a string.
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   885
     The boolean directoriesOnly and filesOnly control respectively,
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   886
     if only directories or only regular files are to be considered for completion.
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   887
     If multiple files match, the exception block aBlock is evaluated with a 
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   888
     filename representing the directory (where the match was done) as argument.
440
claus
parents: 422
diff changeset
   889
     (this may be different from the inDirectory argument, if aString is absolute
claus
parents: 422
diff changeset
   890
      or starts with ../)"
claus
parents: 422
diff changeset
   891
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   892
    (self ~~ ConcreteClass) ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   893
        ^ ConcreteClass 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   894
            filenameCompletionFor:aString 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   895
            directory:inDirectory       
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   896
            directoriesOnly:directoriesOnly 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   897
            filesOnly:filesOnly 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   898
            ifMultiple:aBlock
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   899
    ].
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   900
    ^ 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
   901
!
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   902
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   903
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
   904
    "perform filename completion on aString in some directory;
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   905
     return the longest matching filename prefix as a string.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   906
     The boolean directoriesOnly and filesOnly control respectively,
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   907
     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
   908
     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
   909
     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
   910
     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
   911
     (list of matched filenames)  as arguments.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   912
     (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
   913
      or starts with ../)"
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   914
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   915
    |s f matchSet nMatch name dir isAbsolute sep|
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   916
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   917
    aString size == 0 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   918
        aBlock value:(self named:'.').
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   919
        ^ ''
440
claus
parents: 422
diff changeset
   920
    ].
claus
parents: 422
diff changeset
   921
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   922
    sep := self separator.
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   923
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   924
    "/ 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
   925
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   926
    f := self named:aString.
3854
a13d0d489365 care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   927
    isAbsolute := f isAbsolute.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   928
    matchSet := f filenameCompletionIn:inDirectory.  "/ BAD DESIGN: has side effect on f
440
claus
parents: 422
diff changeset
   929
    dir := f directory.
claus
parents: 422
diff changeset
   930
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   931
    matchSet := matchSet select:[:aFilename |
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   932
        |f isDir|
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   933
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   934
        isAbsolute ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   935
            f := aFilename asFilename
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   936
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   937
            f := (dir construct:aFilename). 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   938
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   939
        isDir := f isDirectory.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   940
        directoriesOnly ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   941
            isDir
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   942
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   943
            filesOnly ifTrue:[    
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   944
                isDir not
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   945
            ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   946
                true
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   947
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   948
        ]
440
claus
parents: 422
diff changeset
   949
    ].
claus
parents: 422
diff changeset
   950
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
   951
    f := f asCanonicalizedFilename.
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   952
        (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
   953
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   954
         more than one possible completion -
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   955
        "
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   956
        aMultipleBlock notNil ifTrue:[
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   957
            aMultipleBlock value:f value:matchSet.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   958
        ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   959
        aBlock value:f
440
claus
parents: 422
diff changeset
   960
    ].
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   961
440
claus
parents: 422
diff changeset
   962
    "
claus
parents: 422
diff changeset
   963
     even with more than one possible completion,
claus
parents: 422
diff changeset
   964
     f's name is now the common prefix
claus
parents: 422
diff changeset
   965
    "
claus
parents: 422
diff changeset
   966
    name := f asString.
4323
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   967
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   968
    nMatch <= 1 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   969
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   970
         exactly one possible completion -
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   971
        "
3752
cbf9fa32eb28 fixed completion.
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
   972
"/        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
   973
        false "directoriesOnly" ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   974
            (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
   975
                (name endsWith:sep) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   976
                    name := name , sep asString
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   977
                ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   978
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   979
        ]
440
claus
parents: 422
diff changeset
   980
    ].
claus
parents: 422
diff changeset
   981
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   982
    s := name.
440
claus
parents: 422
diff changeset
   983
claus
parents: 422
diff changeset
   984
    "/ special: if there was no change, and the string represented
claus
parents: 422
diff changeset
   985
    "/ 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
   986
    ((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
   987
        (s endsWith:sep) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   988
            (self named:s) isDirectory ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   989
                ^ s , sep asString
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   990
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   991
        ].
440
claus
parents: 422
diff changeset
   992
    ].
claus
parents: 422
diff changeset
   993
claus
parents: 422
diff changeset
   994
    ^ s
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   995
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   996
    "Modified: / 30.4.1999 / 09:40:13 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   997
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   998
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   999
filesMatching:aPattern
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1000
    "return a collection of strings, representing the names
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1001
     of files matching aPattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1002
     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
  1003
     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
  1004
     The returned strings are the expanded names, in the same form
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1005
     as given in pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1006
     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
  1007
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1008
    |basePattern dir d files|
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1009
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1010
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1011
	^ ConcreteClass filesMatching:aPattern
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1012
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1013
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1014
    "/ the following works on Unix & MSDOS (but not on openVMS)
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1015
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1016
    dir := aPattern asFilename directoryName.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1017
    basePattern := aPattern asFilename baseName.
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1018
    d := dir asFilename.
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  1019
    files := dir asFilename filesMatchingWithoutDotDirs:basePattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1020
    dir = '.' ifTrue:[^ files].
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1021
    ^ files collect:[:base | d constructString:base].
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1022
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1023
    "
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1024
     Filename filesMatching:'*'   
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1025
     Filename filesMatching:'/*'
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1026
     Filename filesMatching:'/usr/local/*'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1027
    "
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1028
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1029
    "Modified: 8.9.1997 / 00:32:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1030
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1031
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1032
isBadCharacter:aCharacter
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1033
    "return true, if aCharacter is unallowed in a filename."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1034
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1035
    |ascii|
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1036
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1037
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1038
	^ ConcreteClass isBadCharacter:aCharacter
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1039
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1040
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1041
    ascii := aCharacter asciiValue.
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1042
    ascii < 32 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1043
	^ true  "/ a control character
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1044
    ].
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1045
    ascii == 16rFF ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1046
	^ true  "/ delete character
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1047
    ].
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1048
    ^ false
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1049
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1050
    "Modified: 8.9.1997 / 00:32:59 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1051
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1052
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1053
isCaseSensitive
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1054
    "return true, if filenames are case sensitive.
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1055
     We ask the OS about this, to be independent here."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1056
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1057
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1058
	^ ConcreteClass isCaseSensitive
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1059
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1060
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1061
    ^ OperatingSystem caseSensitiveFilenames
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1062
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1063
    "Modified: 8.9.1997 / 00:33:32 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1064
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1065
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1066
localNameStringFrom:aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1067
    "ST-80 compatibility.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1068
     what does this do ? (used in FileNavigator-goody).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1069
     GUESS: 
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1070
	does it strip off any volume characters and make a path relative ?"
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1071
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1072
    |sep|
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1073
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1074
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1075
	^ ConcreteClass localNameStringFrom:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1076
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1077
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1078
    sep := self separator asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1079
    (aString startsWith:sep) ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1080
	^ aString copyFrom:sep size + 1
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1081
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1082
    ^ aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1083
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1084
    "Modified: 7.9.1995 / 10:44:56 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1085
    "Modified: 8.9.1997 / 00:33:51 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1086
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1087
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1088
maxComponentLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1089
    "return the maximum number of characters a filename component may
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1090
     be in size. This depends on the OperatingSystem."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1091
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1092
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1093
	^ ConcreteClass maxComponentLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1094
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1095
    ^ OperatingSystem maxFileNameLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1096
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1097
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1098
maxLength
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1099
    "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
  1100
     This depends on the OperatingSystem."
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1101
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1102
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1103
	^ ConcreteClass maxLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1104
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1105
    ^ OperatingSystem maxPathLength
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1106
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1107
    "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
  1108
    "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
  1109
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1110
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1111
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1112
    "Return the OS dependent filename for /dev/null, or nil if there is none.
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1113
     The default is nil here"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1114
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1115
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1116
	^ ConcreteClass nullFilename
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1117
    ].
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1118
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1119
    ^ nil
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1120
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1121
    "Created: / 12.1.1998 / 12:15:30 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1122
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1123
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1124
parentDirectoryName 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1125
    "return the name used for the parent directory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1126
     This is '..' for unix and dos-like systems. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1127
     (there may be more in the future."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1128
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1129
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1130
	^ ConcreteClass parentDirectoryName
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1131
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1132
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1133
    ^ OperatingSystem parentDirectoryName
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1134
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1135
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1136
     Filename parentDirectoryName  
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1137
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1138
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1139
    "Modified: 8.9.1997 / 00:34:39 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1140
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1141
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1142
separator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1143
    "return the file/directory separator.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1144
     This is to be redefined in concrete classes;
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1145
     the following default usually leads to a flat view of
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1146
     the fileSystem (huh - BS2000 ?)"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1147
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1148
     (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1149
	^ ConcreteClass separator
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1150
     ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1151
     ^ $_
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1152
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1153
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1154
      Filename separator  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1155
     "
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1156
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1157
    "Modified: 8.9.1997 / 00:20:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1158
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1159
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1160
suffixSeparator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1161
    "return the filename suffix separator.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1162
     Usually, this is $. for unix-like and msdos systems 
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1163
     (there is currently no known system, where this differs)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1164
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1165
     ^ $.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1166
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1167
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1168
      Filename suffixSeparator  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1169
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1170
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1171
    "Modified: 7.9.1995 / 11:10:43 / claus"
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1172
    "Modified: 30.4.1996 / 12:14:25 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1173
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1174
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1175
tempFileNameTemplate
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1176
    "return a template for temporary files.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1177
     This is expanded with the current processID and a sequenceNumber
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1178
     to generate a unique filename."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1179
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1180
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1181
	^ ConcreteClass tempFileNameTemplate
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1182
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1183
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1184
    ^ 'stxtmp_%1_%2'
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1185
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1186
    "Created: 8.9.1997 / 00:01:46 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1187
    "Modified: 8.9.1997 / 00:35:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1188
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1189
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1190
volumes
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1191
    "ST-80 compatibility.
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1192
     GUESS: does it return the available drives on MSDOS systems ?
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1193
     Q: what does this do on Unix systems ? (used in FileNavigator-goody)."
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1194
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1195
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1196
	^ ConcreteClass volumes
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1197
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1198
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1199
    ^ OperatingSystem getDriveList
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1200
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1201
    "Modified: 7.9.1995 / 10:45:25 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1202
    "Modified: 8.9.1997 / 00:35:19 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1203
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1204
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1205
!Filename class methodsFor:'utilities'!
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1206
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1207
nameFromComponents:aCollectionOfDirectoryNames
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1208
    "return a filenameString from components given in aCollectionOfDirectoryNames. 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1209
     If the first component is the name of the root directory (i.e. '/'),
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1210
     an absolute path-string is returned."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1211
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1212
    |sep s|
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1213
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1214
    (self ~~ ConcreteClass) ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1215
        ^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1216
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1217
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1218
    "/ fallBack - works on Unix & MSDOS
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1219
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1220
    sep := self separator asString.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1221
    s := ''.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1222
    aCollectionOfDirectoryNames keysAndValuesDo:[:index :component |
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1223
        index == 1 ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1224
            (component ~= sep 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1225
            or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1226
                s := s , component
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1227
            ]
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1228
        ] ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1229
            s := s , sep , component
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1230
        ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1231
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1232
    ^ s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1233
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1234
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1235
     Filename nameFromComponents:#('/' 'foo' 'bar' 'baz')  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1236
     Filename nameFromComponents:#('foo' 'bar' 'baz')  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1237
     Filename nameFromComponents:#('/')  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1238
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1239
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1240
    "Modified: 8.9.1997 / 00:23:16 / cg"
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1241
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1242
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1243
readingFile:aPathName do:aBlock
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1244
    "create a read-stream on a file, evaluate aBlock, passing that stream,
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1245
     and return the blocks value.
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1246
     Ensures that the stream is closed."
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1247
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1248
    ^ aPathName asFilename readingFileDo:aBlock.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1249
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1250
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1251
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1252
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1253
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1254
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1255
     rslt := 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1256
        Filename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1257
            readingFile:'/etc/passwd'
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1258
            do:[:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1259
                s nextLine
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1260
            ]. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1261
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1262
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1263
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1264
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1265
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1266
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1267
     |rslt|
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1268
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1269
     rslt :=
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1270
        Filename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1271
            readingFile:'/etc/passwd' 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1272
            do:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1273
                [:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1274
                    |shells|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1275
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1276
                    shells := Bag new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1277
                    s linesDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1278
                        [:line |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1279
                            |parts|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1280
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1281
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1282
                            shells add:(parts seventh).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1283
                        ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1284
                    shells contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1285
                ].           
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1286
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1287
    "
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1288
! !
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1289
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1290
!Filename methodsFor:'Compatibility - VW5.4'!
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1291
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1292
asLogicalFileSpecification
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1293
    ^ self
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1294
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1295
    "Created: / 30.10.2001 / 17:31:10 / cg"
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1296
!
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1297
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1298
extension
6454
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1299
    "return the receiver's extension;
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1300
     that is the characters from and including
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1301
     the last period or nil, if there is none."
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1302
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1303
    |string idx|
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1304
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1305
    string := self asString.
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1306
    idx := string lastIndexOf:$..
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1307
    idx > 1 ifTrue:[
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1308
        ^ string copyFrom:idx
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1309
    ].
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1310
    ^ nil
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1311
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1312
    "
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1313
     'foo.html' asFilename extension   
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1314
     'foo.bar' asFilename extension       
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1315
     'foo.bar.baz' asFilename extension   
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1316
     'foo.' asFilename extension          
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1317
     'foo' asFilename extension           
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1318
     '.login' asFilename extension           
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1319
    "
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1320
! !
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1321
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1322
!Filename methodsFor:'comparing'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1323
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1324
= aFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1325
    "return true, if the argument represents the same filename"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1326
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1327
    |str|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1328
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1329
    self species == aFilename species ifTrue:[
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1330
	str := aFilename asString.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1331
	self class isCaseSensitive ifTrue:[
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1332
	    ^ nameString = str
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1333
	].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1334
	^ nameString sameAs:str
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1335
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1336
    ^ false
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1337
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1338
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1339
contentsIsPrefixOf:aFilename
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1340
    "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
  1341
     is the same as or a prefix of the contents of the file represented by the argument, aFilename.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1342
     This compares the files actual contents; not the filenames."
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1343
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1344
    |f2 s1 s2 buffer1 buffer2 rslt n|
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1345
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1346
    f2 := aFilename asFilename.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1347
    self fileSize > f2 fileSize ifTrue:[^ false].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1348
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1349
    buffer1 := ByteArray new:8192.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1350
    buffer2 := ByteArray new:8192.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1351
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1352
    s1 := self readStream.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1353
    s1 isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1354
	^ self error:('cannot open %1 for reading' bindWith:nameString)
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1355
    ].
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1356
    s2 := f2 readStream.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1357
    s2 isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1358
	^ self error:('cannot open %1 for reading' bindWith:aFilename asFilename name)
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1359
    ].
3869
6d7dca488a41 read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1360
    s1 binary.
6d7dca488a41 read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1361
    s2 binary.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1362
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1363
    [s1 atEnd] whileFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1364
	n := s1 nextBytes:8192 into:buffer1 startingAt:1.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1365
	n == 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1366
	    "/ receiver shorter.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1367
	    s1 close. s2 close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1368
	    ^ true
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1369
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1370
	(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1371
	    "/ aFilename shorter
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1372
	    s1 close. s2 close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1373
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1374
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1375
	buffer1 ~= buffer2 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1376
	    s1 close. s2 close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1377
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1378
	]
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1379
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1380
    "/ receiver shorter or same size.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1381
    s1 close. s2 close.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1382
    ^ true
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1383
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1384
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1385
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1386
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1387
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1388
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1389
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1390
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1391
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1392
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1393
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1394
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1395
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1396
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1397
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1398
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1399
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1400
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1401
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1402
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1403
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1404
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1405
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1406
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1407
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1408
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1409
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1410
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1411
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1412
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1413
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1414
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1415
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1416
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1417
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1418
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1419
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1420
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1421
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1422
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1423
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1424
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1425
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1426
!
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1427
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1428
contentsStartsWithContentsOf:aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1429
    "return true if the contents of the file represented by aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1430
     is the same as or a prefix of the contents of the file represented by the receiver.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1431
     This compares the files actual contents; not the filenames."
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1432
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1433
    ^ aFilename asFilename contentsIsPrefixOf:self
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1434
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1435
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1436
     |s|
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1437
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1438
     s := 'testFile1' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1439
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1440
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1441
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1442
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1443
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1444
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1445
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1446
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1447
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1448
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1449
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1450
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1451
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1452
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1453
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1454
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1455
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1456
     s nextPutAll:'44444'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1457
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1458
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1459
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1460
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1461
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1462
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1463
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1464
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1465
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1466
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1467
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1468
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1469
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1470
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1471
     s nextPutAll:'33334'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1472
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1473
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1474
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1475
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1476
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1477
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1478
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1479
hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1480
    "return an integer useful as a hash-key"
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1481
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1482
    ^ nameString hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1483
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1484
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1485
sameContentsAs:aFilename
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1486
    "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
  1487
     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
  1488
     This compares the files actual contents; not the filenames."
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1489
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1490
    |f2|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1491
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1492
    f2 := aFilename asFilename.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1493
    f2 fileSize = self fileSize ifFalse:[^ false].
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1494
    ^ self contentsIsPrefixOf:f2.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1495
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1496
    "
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1497
     'Make.proto' asFilename sameContentsAs:'Makefile'  
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1498
    "
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1499
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1500
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1501
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1502
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1503
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1504
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1505
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1506
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1507
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1508
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1509
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1510
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1511
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1512
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1513
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1514
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1515
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifFalse:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1516
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1517
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1518
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1519
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1520
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1521
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1522
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1523
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1524
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1525
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1526
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1527
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1528
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1529
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1530
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1531
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1532
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1533
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1534
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1535
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1536
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1537
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1538
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1539
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1540
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1541
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1542
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1543
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1544
!Filename methodsFor:'converting'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1545
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1546
asAbsoluteFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1547
    "return the receiver converted to a filename with
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1548
     an absolute pathname."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1549
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  1550
    ^ self class named:self pathName
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1551
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1552
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1553
asCanonicalizedFilename
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1554
    "return the receiver converted to a filename without intermediate ..'s and .'s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1555
     (similar to an absolute pathname, but symlinks are not resolved)."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1556
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1557
    ^ self class named:(self class canonicalize:nameString)
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1558
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1559
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1560
asFilename
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1561
    "return the receiver converted to a filename; here, thats the receiver itself."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1562
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1563
    "Thats pretty easy here :-)"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1564
    ^ self
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1565
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1566
    "Modified: 12.11.1996 / 12:40:03 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1567
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1568
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1569
asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1570
    "return the receiver converted to a string"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1571
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1572
    ^ nameString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1573
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1574
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1575
asURI
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1576
    "return the receiver converted to a string"
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1577
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1578
    ^ FileURI fromFilename:self.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1579
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1580
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1581
components
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1582
    "return the receivers filename components - that is the name of each directory
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1583
     along the pathName (that DOES include the root directory)"
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1584
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1585
    ^ self class components:self name
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1586
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1587
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1588
     '.' asFilename asAbsoluteFilename components 
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1589
     'Makefile' asFilename asAbsoluteFilename components     
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1590
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1591
!
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1592
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1593
makeLegalFilename 
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1594
    "convert the receivers name to be a legal filename.
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1595
     This removes/replaces invalid characters and/or compresses
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1596
     the name as required by the OS.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1597
     The implementation may change in the future to be more
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1598
     OS specific."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1599
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1600
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1601
     actually, in Unix spaces are allowed - but it makes life
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1602
     so hard; therefore, replace them by underscores ...
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1603
    "
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1604
    (nameString includes:Character space) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1605
	nameString := nameString copyReplaceAll:(Character space) with:$_.
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1606
    ].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1607
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1608
     need more - especially on SYS5.3 type systems, 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1609
     we may want to contract the fileName to 14 characters.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1610
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1611
    ^ self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1612
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1613
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1614
     'hello world' asFilename makeLegalFilename 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1615
    "
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1616
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1617
    "Modified: / 20.7.1998 / 13:16:51 / cg"
2707
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1618
!
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1619
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1620
withEncoding:encodingSymbol
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1621
    "dummy for now - for ST80 compatibility"
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1622
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1623
    ^ self
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1624
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1625
    "Created: 20.6.1997 / 17:01:28 / cg"
2
claus
parents: 1
diff changeset
  1626
! !
claus
parents: 1
diff changeset
  1627
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1628
!Filename methodsFor:'enumerating-contents'!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1629
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1630
allDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1631
    "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
  1632
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1633
     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
  1634
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1635
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1636
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1637
     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
  1638
     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
  1639
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1640
    self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1641
	|eachFileOrDirectory|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1642
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1643
	eachFileOrDirectory := self construct:eachFileOrDirectoryName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1644
	eachFileOrDirectory isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1645
	    aBlock value:eachFileOrDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1646
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1647
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1648
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1649
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1650
     '.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1651
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1652
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1653
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1654
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1655
allParentDirectoriesDo:aBlock
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1656
    "evaluate aBlock for all (recursive) directories along the parent directory path.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1657
     The block is invoked with a filename-arguments."
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1658
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1659
    |parent here|
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1660
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1661
    here := self.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1662
    parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1663
    [here notNil and:[parent ~= here]] whileTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1664
        aBlock value:parent.    
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1665
        here := parent.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1666
        parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1667
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1668
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1669
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1670
     '.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1671
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1672
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1673
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1674
directoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1675
    "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
  1676
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1677
     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
  1678
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1679
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1680
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1681
     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
  1682
     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
  1683
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1684
    self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1685
	eachFileOrDirectory isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1686
	    aBlock value:eachFileOrDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1687
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1688
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1689
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1690
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1691
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1692
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1693
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1694
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1695
directoryContentsAsFilenamesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1696
    "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
  1697
     The block is invoked with a filename-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1698
     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
  1699
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1700
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1701
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1702
     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
  1703
     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
  1704
     Notice: this enumerates fileName objects; see also
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1705
     #directoryContentsDo:, which enumerates strings."
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1706
6776
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  1707
    self directoryContentsDo:[:entry |
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  1708
        aBlock value:(self construct:entry).
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  1709
    ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1710
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1711
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1712
     '.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1713
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1714
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1715
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1716
    "Modified: / 23.12.1999 / 20:56:35 / cg"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1717
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1718
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1719
recursiveDirectoryContentsDo:aBlock 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1720
    "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
  1721
     The block is invoked with a string-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1722
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1723
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1724
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1725
     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
  1726
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1727
    self recursiveDirectoryContentsDo:aBlock directoryPrefix:''
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1728
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1729
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1730
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1731
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1732
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1733
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1734
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1735
    "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
  1736
     The block is invoked with a string-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1737
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1738
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1739
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1740
     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
  1741
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1742
    |fileNames dirNames p|
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1743
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1744
    fileNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1745
    dirNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1746
    self directoryContentsDo:[:f | |t|
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1747
	t := self construct:f.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1748
	t isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1749
	    t isSymbolicLink ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1750
		dirNames add:f
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1751
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1752
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1753
	    fileNames add:f
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1754
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1755
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1756
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1757
    aPrefix size > 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1758
	p := aPrefix , self separator asString
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1759
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1760
	p := ''
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1761
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1762
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1763
    fileNames do:[:aFile | aBlock value:(p , aFile)].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1764
    dirNames do:[:dN |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1765
	aBlock value:(p , dN).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1766
	(self construct:dN)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1767
	    recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN)
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1768
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1769
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1770
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1771
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1772
     '/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1773
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1774
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1775
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1776
withAllDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1777
    "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
  1778
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1779
     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
  1780
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1781
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1782
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1783
     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
  1784
     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
  1785
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1786
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1787
	aBlock value:self.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1788
	self allDirectoriesDo:aBlock
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1789
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1790
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1791
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1792
     '.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1793
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1794
! !
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1795
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1796
!Filename methodsFor:'error handling'!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1797
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1798
accessDeniedError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1799
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1800
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1801
    "report an error that access to some file was denied"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1802
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1803
    |errNo errString|
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1804
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1805
    errNo := OperatingSystem lastErrorNumber.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1806
    errString := OperatingSystem lastErrorString.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1807
    errString size == 0 ifTrue:[
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1808
        errString := ''.
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1809
    ] ifFalse:[
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1810
        errString := ' (' , errString , ')'
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1811
    ].
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1812
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1813
    ^ OperatingSystem accessDeniedErrorSignal
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1814
        raiseRequestWith:filename
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1815
        errorString:(' : ' , filename asString , errString)
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1816
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1817
    "Modified: / 26.9.1999 / 16:11:44 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1818
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1819
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1820
fileCreationError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1821
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1822
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1823
    "report an error that some file could not be created"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1824
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1825
    ^ OperatingSystem accessDeniedErrorSignal
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1826
        raiseRequestWith:filename
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1827
        errorString:(' - cannot create/write file: ' , filename asString)
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1828
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1829
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1830
fileNotFoundError:filename 
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1831
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1832
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1833
    "report an error that some file was not found"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1834
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1835
    ^ OperatingSystem fileNotFoundErrorSignal
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1836
	raiseRequestWith:filename
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1837
	errorString:('file not found: ' , filename asString)
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1838
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1839
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1840
removeError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1841
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1842
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1843
    "report an error that some file could not be removed"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1844
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1845
    ^ OperatingSystem accessDeniedErrorSignal
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1846
	raiseRequestWith:filename
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1847
	errorString:('cannot remove: ' , filename asString)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1848
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1849
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1850
reportError:string with:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1851
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1852
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1853
    "report an error"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1854
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1855
    ^ OperatingSystem errorSignal
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1856
	raiseRequestWith:filename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1857
	errorString:string
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1858
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1859
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1860
!Filename methodsFor:'file access'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1861
3015
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1862
appendStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1863
    "return a stream for appending to the file represented by the receiver.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1864
     If the file does not already exist, it is created.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1865
     Same as #appendingWriteStream for ST-80 compatibility."
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1866
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1867
    ^ self appendingWriteStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1868
!
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1869
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1870
appendingWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1871
    "return a stream for appending to the file represented by the receiver.
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1872
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1873
     if it does exist, writes are appended at the end."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1874
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1875
    ^ FileStream appendingOldFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1876
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1877
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1878
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1879
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1880
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1881
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1882
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1883
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1884
     s := '/tmp/foo' asFilename appendingWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1885
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1886
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1887
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1888
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1889
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1890
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1891
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1892
newReadWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1893
    "return a stream for read/write the file represented by the receiver.
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1894
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1895
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1896
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1897
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1898
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1899
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1900
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1901
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1902
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1903
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1904
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1905
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1906
     s := '/tmp/foo' asFilename newReadWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1907
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1908
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1909
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1910
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1911
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1912
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1913
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1914
readStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1915
    "return a stream for reading from the file represented by the receiver.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1916
     If the file does not already exist, nil is returned."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1917
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1918
    ^ FileStream readonlyFileNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1919
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1920
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1921
     '/tmp/foo' asFilename readStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1922
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1923
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1924
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1925
readWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1926
    "return a stream for read/write the file represented by the receiver.
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1927
     If the file does not already exist, nil is returned.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1928
     If the file does exist, it is NOT truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1929
5208
7cdbf4e22374 oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents: 5200
diff changeset
  1930
    self exists ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1931
	^ FileStream oldFileNamed:(self osNameForAccess)
5208
7cdbf4e22374 oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents: 5200
diff changeset
  1932
    ].
7cdbf4e22374 oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents: 5200
diff changeset
  1933
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1934
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1935
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1936
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1937
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1938
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1939
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1940
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1941
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1942
     s := '/tmp/foo' asFilename readWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1943
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1944
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1945
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1946
     '/tmp/foo' asFilename contents      
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1947
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1948
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1949
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1950
writeStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1951
    "return a stream for writing to the file represented by the receiver.
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1952
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1953
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1954
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1955
    ^ FileStream newFileForWritingNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1956
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1957
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1958
     '/tmp/foo' asFilename writeStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1959
    "
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1960
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1961
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1962
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1963
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1964
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1965
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1966
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1967
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1968
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1969
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1970
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1971
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1972
     '/tmp/foo' asFilename contents  
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1973
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1974
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1975
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  1976
!Filename methodsFor:'file accessRights'!
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1977
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1978
addAccessRights:aCollection
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1979
    "add the access rights as specified in aCollection for the file represented
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1980
     by the receiver. The argument must be a collection of symbols,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1981
     such as #readUser, #writeGroup etc."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1982
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1983
    |access osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1984
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1985
    osName := self osNameForFile.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1986
    access := OperatingSystem accessModeOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1987
    aCollection do:[:accessSymbol |
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1988
	access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1989
    ].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1990
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1991
	^ self accessDeniedError:self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1992
    ]
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1993
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1994
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1995
     'foo' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1996
     'foo' asFilename addAccessRights:#(readUser readGroup readOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1997
     'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1998
     'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1999
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2000
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2001
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2002
makeExecutable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2003
    "make the file executable - you must have permission to do so.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2004
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2005
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2006
    ^ self addAccessRights:#(executeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2007
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2008
    "Created: 9.1.1996 / 15:32:47 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2009
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2010
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2011
makeExecutableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2012
    "make the file executable for all - you must have permission to do so.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2013
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2014
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2015
    ^ self addAccessRights:#(executeUser executeGroup executeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2016
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2017
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2018
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2019
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2020
makeExecutableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2021
    "make the file executable for the group - you must have permission to do so.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2022
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2023
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2024
    ^ self addAccessRights:#(executeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2025
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2026
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2027
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2028
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2029
makeReadable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2030
    "make the file readable for  the owner - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2031
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2032
    ^ self addAccessRights:#(readUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2033
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2034
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2035
makeReadableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2036
    "make the file readable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2037
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2038
    ^ self addAccessRights:#(readUser readGroup readOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2039
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2040
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2041
makeReadableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2042
    "make the file readable for the group - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2043
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2044
    ^ self addAccessRights:#(readGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2045
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2046
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2047
makeUnwritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2048
    "make the file unwritable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2049
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2050
    ^ self removeAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2051
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2052
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2053
makeWritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2054
    "make the file writableable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2055
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2056
    ^ self addAccessRights:#(writeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2057
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2058
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2059
makeWritableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2060
    "make the file writable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2061
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2062
    ^ self addAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2063
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2064
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2065
makeWritableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2066
    "make the file writable for the group - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2067
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2068
    ^ self addAccessRights:#(writeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2069
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2070
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2071
removeAccessRights:aCollection
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2072
    "remove the access rights as specified in aCollection for the file represented
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2073
     by the receiver. The argument must be a collection of symbols,
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2074
     such as #readUser, #writeGroup etc.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2075
     Raises an exception if not successful."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2076
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2077
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2078
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2079
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2080
    access := OperatingSystem accessModeOf:osName.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2081
    aCollection do:[:accessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2082
	access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2083
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2084
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2085
	^ self accessDeniedError:self
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2086
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2087
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2088
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2089
     'foo' asFilename writeStream close.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2090
     'foo' asFilename removeAccessRights:#(readUser readGroup readOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2091
     'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2092
     'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2093
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2094
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2095
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2096
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2097
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2098
symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2099
    "return the access rights of the file as a aCollection of access symbols.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2100
     The returned collection consists of symbols like:
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2101
        #readUser, #writeGroup etc."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2102
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2103
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2104
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2105
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2106
    access := OperatingSystem accessModeOf:osName.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2107
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2108
    ^ 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2109
        #(  readUser writeUser executeUser
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2110
            readGroup writeGroup executeGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2111
            readOthers writeOthers executeOthers
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2112
          ) select:[:eachSymbolicAccessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2113
                access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2114
            ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2115
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2116
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2117
     'Makefile' asFilename symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2118
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2119
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2120
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2121
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2122
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2123
symbolicAccessRights:aCollectionOfSymbols
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2124
    "set the access rights of the file given a aCollection of access symbols.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2125
     The collection must consist of symbols like:
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2126
        #readUser, #writeGroup etc."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2127
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2128
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2129
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2130
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2131
    access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2132
                bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2133
              ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2134
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2135
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2136
        ^ self accessDeniedError:self
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2137
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2138
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2139
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2140
     |rights|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2141
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2142
     rights := 'Makefile' asFilename symbolicAccessRights. 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2143
     'Makefile' asFilename symbolicAccessRights:(rights , #(executeOthers)). 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2144
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2145
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2146
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2147
! !
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2148
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2149
!Filename methodsFor:'file operations'!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2150
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2151
basicMakeDirectory
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2152
    "create a directory with the receivers name.
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2153
     Return true if successful, false if not."
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2154
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2155
    ^ OperatingSystem createDirectory:(self osNameForDirectory)
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2156
!
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2157
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2158
copyTo:newName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2159
    "copy the file - the argument must be convertable to a filename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2160
     Raises an exception, if an error occurs."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2161
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2162
    |inStream outStream newFile|
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2163
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2164
    inStream := self readStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2165
    inStream isNil ifTrue:[
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2166
        ^ self fileNotFoundError:self 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2167
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2168
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2169
    outStream := (newFile := newName asFilename) writeStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2170
    outStream isNil ifTrue:[
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2171
        inStream close.
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2172
        ^ self fileCreationError:newFile
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2173
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2174
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2175
    [
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2176
        OperatingSystem errorSignal handle:[:ex |
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2177
            ^ self fileCreationError:newFile
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2178
        ] do:[
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2179
            inStream copyToEndInto:outStream.
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2180
        ]
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2181
    ] ensure:[
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2182
        outStream close.
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2183
        inStream close.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2184
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2185
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2186
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2187
     'Makefile' asFilename copyTo:'Makefile.foo'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2188
     'smalltalk' asFilename copyTo:'/dev/null'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2189
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2190
5134
48758d82be48 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5132
diff changeset
  2191
    "Modified: / 23.12.1999 / 21:52:36 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2192
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2193
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2194
delete
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2195
    "remove the file - same as remove, for ST-80 compatibility"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2196
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2197
    self remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2198
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2199
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2200
makeDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2201
    "create a directory with the receivers name.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2202
     Raises an exception if not successful"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2203
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2204
    (self basicMakeDirectory) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2205
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2206
	"/ could have existed before ...
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2207
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2208
	(self exists and:[self isDirectory]) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2209
	    self fileCreationError:self.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2210
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2211
	]
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2212
    ].
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2213
    ^ true
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2214
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2215
    "Modified: / 5.5.1999 / 13:36:33 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2216
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2217
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2218
moveTo:newName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2219
    "copy the file represented by the receiver, then delete it.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2220
     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
  2221
     Raise an exception if not successful.
3d801043be3f dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 5577
diff changeset
  2222
     (Notice, that a rename is tried first, in case of non-cross device move)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2223
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2224
    [self renameTo:newName] 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2225
        on:(OperatingSystem errorSignal) 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2226
        do:[ 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2227
            self copyTo:newName. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2228
            self remove
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2229
        ].
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2230
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2231
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2232
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2233
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2234
     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
  2235
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2236
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2237
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2238
     f renameTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2239
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2240
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2241
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2242
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2243
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2244
     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
  2245
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2246
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2247
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2248
     f moveTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2249
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2250
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2251
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2252
recursiveCopyTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2253
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2254
     Otherwise, copy the directory and recursively
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2255
     and recursively all of its subfiles/subdirectories.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2256
     Raises an exception if not successful."
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2257
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2258
    |ok d|
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2259
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2260
    self isDirectory ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2261
	d := destination asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2262
	(d exists and:[d isDirectory]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2263
	    d := d construct:self baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2264
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2265
	^ self copyTo:d
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2266
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2267
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2268
    "/ typically, an 'cp -r' is faster;
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2269
    "/ 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
  2270
    "/ fallBack doing a manual directory walk.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2271
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2272
    ok := OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2273
	    recursiveCopyDirectory:(self osNameForDirectory)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2274
	    to:(destination asFilename osNameForDirectory).
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2275
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2276
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2277
	self recursiveCopyWithoutOSCommandTo:destination
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2278
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2279
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2280
    "Created: / 5.5.1999 / 13:35:01 / cg"
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2281
    "Modified: / 31.5.1999 / 13:11:34 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2282
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2283
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2284
recursiveCopyWithoutOSCommandTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2285
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2286
     Otherwise, copy the directory and all of its subfiles/subdirectories.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2287
     This one walks down the directory hierarchy, not using any OS
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2288
     command to do the copy.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2289
     Raises an exception if not successful."
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2290
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2291
    |destinationFilename d|
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2292
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2293
    d := destination asFilename.
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2294
"/    (d exists and:[d isDirectory]) ifTrue:[
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2295
"/        d := d construct:self baseName.
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2296
"/    ].
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2297
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2298
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2299
	destinationFilename := d asFilename construct:self baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2300
	destinationFilename makeDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2301
	self directoryContents do:[:aFilenameString |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2302
	    |src dst|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2303
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2304
	    src := self construct:aFilenameString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2305
	    src isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2306
		src recursiveCopyWithoutOSCommandTo:destinationFilename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2307
	    ] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2308
		src copyTo:(destinationFilename construct:aFilenameString)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2309
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2310
	]
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2311
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2312
	self copyTo:d
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2313
    ]
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2314
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2315
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2316
     '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2317
     'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2318
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2319
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2320
    "Modified: / 31.5.1999 / 18:12:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2321
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2322
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2323
recursiveMakeDirectory
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2324
    "create a directory with the receivers name and all required intermediate
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2325
     directories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2326
     Raises an exception if not successful."
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2327
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2328
    (OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2329
	^ self fileCreationError:self
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2330
    ]
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2331
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2332
    "Created: / 27.11.1995 / 23:36:40 / cg"
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2333
    "Modified: / 5.5.1999 / 13:38:42 / cg"
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2334
!
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2335
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2336
recursiveRemove
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2337
    "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
  2338
     Otherwise, remove the directory and all of its subfiles/subdirectories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2339
     Raise an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2340
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2341
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2342
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2343
    "/ typically, an 'rm -rf' is faster and removes better;
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2344
    "/ 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
  2345
    "/ fallBack doing a manual directory walk.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2346
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2347
    ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory).
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2348
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2349
	self recursiveRemoveWithoutOSCommand
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2350
    ].
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2351
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2352
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2353
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2354
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2355
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2356
	Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2357
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2358
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2359
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2360
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2361
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2362
     ('foo' asFilename recursiveRemove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2363
	Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2364
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2365
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2366
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2367
    "Created: / 14.11.1995 / 11:19:29 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2368
    "Modified: / 5.5.1999 / 13:43:35 / cg"
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2369
!
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2370
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2371
recursiveRemoveWithoutOSCommand
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2372
    "if I represent a regular file, remove it.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2373
     Otherwise, remove the directory and all of its subfiles/subdirectories.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2374
     Raise an error if not successful.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2375
     This one walks down the directory hierarchy, not using any OS
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2376
     command to do the remove."
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2377
4939
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  2378
    |files|
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  2379
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2380
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2381
	(files := self directoryContents) size > 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2382
	    files do:[:aFilenameString |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2383
		|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2384
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2385
		f := self construct:aFilenameString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2386
		f isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2387
		    f recursiveRemoveWithoutOSCommand
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2388
		] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2389
		    f remove
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2390
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2391
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2392
	]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2393
    ].
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2394
    self remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2395
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2396
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2397
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2398
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  2399
     'foo' asFilename remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2400
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2401
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2402
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2403
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  2404
     'foo' asFilename recursiveRemove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2405
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2406
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2407
    "Created: / 25.2.1998 / 19:50:40 / cg"
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2408
    "Modified: / 25.2.1998 / 19:52:08 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2409
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2410
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2411
remove
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  2412
    "remove the file/directory.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2413
     Raises an exception if not successful.
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  2414
     Use #recursiveRemove in order to (recursively) remove non empty directories."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2415
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2416
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2417
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2418
3113
43e75ed892cf Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents: 3077
diff changeset
  2419
    (self isSymbolicLink not and:[self isDirectory]) ifTrue:[
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2420
        ok := OperatingSystem removeDirectory:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2421
    ] ifFalse:[
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2422
        ok := OperatingSystem removeFile:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2423
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2424
    ok ifFalse:[
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2425
        self exists ifTrue:[
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2426
            self removeError:self
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2427
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2428
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2429
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2430
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2431
     (FileStream newFileNamed:'foo') close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2432
     'foo' asFilename remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2433
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2434
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2435
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2436
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2437
     'foo/bar' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2438
     ('foo' asFilename remove) ifFalse:[
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2439
        Transcript showCR:'could not remove foo'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2440
     ]
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2441
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2442
3113
43e75ed892cf Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents: 3077
diff changeset
  2443
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2444
    "Modified: / 5.5.1999 / 13:41:12 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2445
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2446
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2447
removeDirectory
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2448
    "remove the directory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2449
     Raises an exception if not successful (or if its not a directory).
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2450
     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
  2451
     Use #recursiveRemove in order to (recursively) remove non empty directories."
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2452
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2453
    |ok|
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2454
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2455
    ok := OperatingSystem removeDirectory:(self osNameForFile).
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2456
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2457
	self exists ifFalse:[ ^ self].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2458
	self removeError:self
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2459
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2460
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2461
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2462
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2463
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2464
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2465
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2466
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2467
     'foo' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2468
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2469
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2470
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2471
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2472
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2473
     'foo/bar' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2474
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2475
	Transcript showCR:'could not remove foo'
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2476
     ]
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2477
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2478
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2479
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2480
    "Modified: / 5.5.1999 / 13:41:12 / cg"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2481
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2482
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2483
removeFile
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2484
    "remove the file.
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2485
     Raises an exception if not successful (or if its not a file).
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2486
     Use #remove if it is not known if the receiver is a directory or file.
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2487
     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
  2488
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2489
    |ok|
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2490
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2491
    ok := OperatingSystem removeFile:(self osNameForFile).
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2492
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2493
	self exists ifFalse:[ ^ self].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2494
	self removeError:self
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2495
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2496
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2497
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2498
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2499
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2500
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2501
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2502
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2503
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2504
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2505
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2506
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2507
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2508
renameOrCopyTo:newName
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2509
    "rename or copy the file - the argument must be convertable to a String.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2510
     Raises an exception if not successful.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2511
     This does basically the same as #renameTo:, with one exception:
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2512
     if, under unix, the new fileName is on another device, a rename operation
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2513
     fails, and #renameTo: raises an exception;
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2514
     in contrast, this method falls back to copying the file."
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2515
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2516
    |newFilename|
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2517
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2518
    newFilename := newName asFilename.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2519
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2520
    (OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2521
	renameFile:(self osNameForFile) 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2522
	to:(newFilename osNameForFile)
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2523
    ) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2524
	self exists ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2525
	    ^ self fileNotFoundError:self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2526
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2527
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2528
	OperatingSystem isUNIXlike ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2529
	    OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2530
		"/ try to copy - and remove the original
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2531
		"/ this helps with cross-device renames.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2532
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2533
	      self copyTo:newName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2534
	      ^ self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2535
	  ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2536
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2537
	^ self accessDeniedError:newName asFilename.
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2538
    ].
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2539
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2540
    "
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2541
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2542
    "
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2543
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2544
    "Modified: / 5.5.1999 / 13:41:27 / cg"
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2545
!
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2546
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2547
renameTo:newName
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 659
diff changeset
  2548
    "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
  2549
     Raises an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2550
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2551
    (OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2552
	renameFile:(self osNameForFile) 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2553
	to:(newName asFilename osNameForFile)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2554
    ) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2555
	self exists ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2556
	    ^ self fileNotFoundError:self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2557
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2558
	^ self accessDeniedError:newName asFilename.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2559
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2560
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2561
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2562
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2563
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2564
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2565
    "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
  2566
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2567
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2568
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2569
    "change the files size.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2570
     This may not be supported on all operating systems
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2571
     (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
  2572
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2573
    (OperatingSystem truncateFile:(self osNameForFile) to:newSize) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2574
	^ 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
  2575
    ]
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2576
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2577
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2578
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2579
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2580
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2581
     s next:1000 put:$1.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2582
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2583
     ('test' asFilename fileSize) printNL.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2584
     'test' asFilename truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2585
     ('test' asFilename fileSize) printNL.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2586
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2587
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2588
    "Modified: / 5.5.1999 / 13:41:59 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2589
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2590
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2591
!Filename methodsFor:'file queries'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2592
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2593
accessTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2594
    "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
  2595
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2596
    | i |
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2597
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2598
    (i := self info) isNil ifTrue:[^ nil].
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2599
    ^ i accessTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2600
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2601
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2602
     Filename currentDirectory accessTime 
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2603
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2604
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2605
    "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
  2606
    "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
  2607
    "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
  2608
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2609
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2610
dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2611
    "return the files modification and access times as an object (currently a dictionary)
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2612
     that responds to the at: message with arguments 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2613
     #modified, #accessed or #statusChanged."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2614
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2615
    |info dates osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2616
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2617
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2618
    info := OperatingSystem infoOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2619
    info isNil ifTrue:[
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2620
        info := OperatingSystem linkInfoOf:osName.
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2621
        info isNil ifTrue:[
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2622
            ^ nil
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2623
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2624
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2625
    dates := IdentityDictionary new.
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2626
    dates at:#modified put:(info modificationTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2627
    dates at:#accessed put:(info accessTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2628
    dates at:#statusChanged put:(info statusChangeTime).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2629
    ^ dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2630
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2631
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2632
     Filename currentDirectory dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2633
     '../regression' asFilename dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2634
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2635
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2636
    "Modified: 1.11.1996 / 20:19:24 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2637
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2638
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2639
fileSize
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2640
    "return the size of the file in bytes"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2641
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2642
    |i|
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2643
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2644
    (i := self info) isNil ifTrue:[^ nil].
6794
498d85323172 use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents: 6793
diff changeset
  2645
    ^ i fileSize
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2646
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2647
    "Modified: / 17.8.1998 / 10:23:46 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2648
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2649
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2650
fileType
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2651
    "this returns a string describing the type of contents of
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2652
     the file. This is done using the unix 'file' command,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2653
     (which usually is configurable by /etc/magic).
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2654
     On non-unix systems, this may simply return 'file', 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2655
     not knowning about the contents.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2656
     Warning:
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2657
         Since the returned string differs among systems (and language settings),
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2658
         it is only useful for user-information; 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2659
         NOT as a tag to be used by a program."
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2660
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2661
    |type buffer s n suffix idx baseNm|
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2662
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2663
    "/ since we cannot depend on a 'file' command being available,
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2664
    "/ do the most obvious ones here. 
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2665
    "/ (also useful since the 'file' command takes some time, and the code
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2666
    "/  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
  2667
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2668
    self isSymbolicLink ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2669
        ^ 'symbolic link to ' , (self linkInfo path)
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2670
    ].
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  2671
    self isDirectory ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2672
        self isReadable ifFalse:[^ 'directory, unreadable'].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2673
        self isExecutable ifFalse:[^ 'directory, locked'].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2674
        ^ 'directory'
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  2675
    ].
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2676
    (type := self type) == #characterSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2677
        ^ 'character device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2678
    ].
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2679
    type == #blockSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2680
        ^ 'block device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2681
    ].
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2682
    type == #socket ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2683
        ^ 'socket'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2684
    ].
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2685
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  2686
    self isReadable ifFalse:[^ 'unreadable'].
1612
730781a80e2a inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents: 1602
diff changeset
  2687
    self fileSize == 0 ifTrue:[^ 'empty'].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  2688
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2689
    suffix := self suffix asLowercase.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2690
    baseNm := self withoutSuffix baseName asLowercase.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2691
6826
debb693dd98a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6804
diff changeset
  2692
    ((#('st' 'rc' 'chg' 'htm' 'html' 'ps' 'cls' 'pac') includes:suffix)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2693
    or:[#('makefile') includes:baseNm]) ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2694
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2695
        buffer := String new:2024.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2696
        s := self readStream.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2697
        s notNil ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2698
            n := s nextBytes:buffer size into:buffer.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2699
            s close.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2700
            buffer := buffer asLowercase.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2701
            (#('st' 'cls') includes:suffix) ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2702
                #(
6826
debb693dd98a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6804
diff changeset
  2703
                        ('from squeak'        'smalltalk source (Squeak)')
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2704
                        ('from dolphin'       'smalltalk source (Dolphin)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2705
                        ('from visualworks'   'smalltalk source (VisualWorks)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2706
                        ('categoriesforclass' 'smalltalk source (Dolphin)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2707
                        ('methodsfor!!'        'smalltalk source (Dolphin, ST/V or V''age)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2708
                        ('subclass:'          'smalltalk source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2709
                        ('methodsfor:'        'smalltalk source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2710
                 ) pairsDo:[:pattern :what | 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2711
                    (buffer findString:pattern) ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2712
                        ^ what
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2713
                    ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2714
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2715
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2716
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2717
            (buffer findString:'methodsfor:') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2718
                ^ 'smalltalk changes / method source'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2719
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2720
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2721
            (suffix = 'rc') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2722
                (buffer findString:'st/x startup') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2723
                    ^ 'smalltalk startup script'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2724
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2725
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2726
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2727
            (suffix = 'htm' or:[suffix = 'html']) ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2728
                (idx := buffer findString:'<h') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2729
                    ((buffer continuesWith:'<head' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2730
                    or:[(buffer continuesWith:'<html' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2731
                    or:[(buffer continuesWith:'<h1' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2732
                    or:[(buffer continuesWith:'<h2' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2733
                    or:[(buffer continuesWith:'<h3' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2734
                    or:[(buffer continuesWith:'<h4' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2735
                    or:[(buffer continuesWith:'<h5' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2736
                    or:[(buffer continuesWith:'<h6' startingAt:idx)]]]]]]])
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2737
                    ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2738
                        ^ 'HTML document text'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2739
                    ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2740
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2741
            ].
1614
4e1a64b19247 inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents: 1612
diff changeset
  2742
        
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2743
            (suffix = 'ps') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2744
                (buffer findString:'%!!ps-adobe') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2745
                    ^ 'PostScript document'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2746
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2747
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2748
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2749
            (baseNm = 'makefile') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2750
                (buffer startsWith:'#') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2751
                    ^ 'make rules'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2752
                ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2753
            ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2754
        ]
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  2755
    ].
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2756
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2757
    ^ 'file'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2758
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2759
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2760
     'Makefile' asFilename fileType 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2761
     '.' asFilename fileType     
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2762
     '/dev/null' asFilename fileType 
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2763
     '/tmp/.X11-unix/X0' asFilename fileType 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2764
     'smalltalk.rc' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2765
     'bitmaps/SBrowser.xbm' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2766
    "
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2767
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2768
    "Modified: / 21.7.1998 / 11:25:56 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2769
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2770
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2771
id
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2772
    "return the files/directories file-id (inode number)"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2773
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2774
    ^ OperatingSystem idOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2775
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2776
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2777
     Filename currentDirectory id 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2778
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2779
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2780
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2781
    "Created: 5.8.1997 / 19:26:01 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2782
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2783
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2784
info
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2785
    "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
  2786
     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
  2787
     the returned object) is:
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2788
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2789
	 type  - a symbol giving the files fileType
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2790
	 mode  - numeric access mode 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2791
	 uid   - owners user id
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2792
	 gid   - owners group id
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2793
	 size  - files size
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2794
	 id    - files number (i.e. inode number)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2795
	 accessed      - last access time (as osTime-stamp)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2796
	 modified      - last modification time (as osTime-stamp)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2797
	 statusChanged - last staus change (as osTime-stamp)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2798
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2799
     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
  2800
     all of the information.
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2801
     The minimum returned info (i.e. on all OS's) will consist of at least:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2802
	modified
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2803
	size
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2804
	type
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2805
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2806
     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
  2807
     to either handle nil values,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2808
     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
  2809
     (i.e. instead of:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2810
	someFilename type == #directory
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2811
      use
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2812
	someFilename isDirectory
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2813
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2814
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2815
    ^ OperatingSystem infoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2816
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2817
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2818
     Filename currentDirectory info
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2819
     '/dev/null' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2820
     '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
  2821
     '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
  2822
     '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
  2823
     '../../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
  2824
     '.' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2825
     '..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2826
     '..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2827
     '..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2828
     '..\..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2829
     'c:\' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2830
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2831
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2832
    "Modified: / 17.8.1998 / 10:24:10 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2833
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2834
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2835
linkInfo
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2836
    "return the files info if its a symbolic link; nil otherwise.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2837
     On OS's which do not support symbolic links, nil is always returned.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2838
     The information is the same as returned by #info, except that if the
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2839
     receiver represents a symbolic link, the links information 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2840
     is returned 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2841
     (while in this case, #info returns the info of the target file, 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2842
      which is accessed via the symbolic link).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2843
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2844
     In addition to the normal entries, Unix returns an additional entry:
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2845
	 path -> the target files pathname
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2846
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2847
     See the comment in #info for more details."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2848
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2849
    ^ OperatingSystem linkInfoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2850
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2851
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2852
     Filename currentDirectory linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2853
     '/dev/null' asFilename linkInfo    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2854
     'Make.proto' asFilename linkInfo   
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  2855
     'Make.proto' asFilename linkInfo path  
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2856
     'source/Point.st' asFilename linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2857
     '../../libbasic/Point.st' asFilename linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2858
    "
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  2859
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  2860
    "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
  2861
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2862
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2863
modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2864
    "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
  2865
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2866
    |i|
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2867
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2868
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2869
    ^ i modificationTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2870
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2871
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2872
     Filename currentDirectory modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2873
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2874
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2875
    "Created: / 9.7.1996 / 10:18:59 / cg"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2876
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2877
    "Modified: / 14.8.1998 / 17:42:50 / cg"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2878
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2879
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2880
type
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2881
    "return the symbolic type of the file"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2882
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2883
    ^ OperatingSystem typeOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2884
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2885
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2886
     Filename currentDirectory type 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2887
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2888
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2889
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2890
    "Created: 5.8.1997 / 19:31:26 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2891
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2892
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2893
!Filename methodsFor:'file utilities'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2894
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2895
edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2896
    "start an editView on the file represented by the receiver"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2897
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2898
    EditTextView openOn:self asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2899
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2900
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2901
     'smalltalk.rc' asFilename edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2902
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2903
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2904
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2905
fileIn
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2906
    "load smalltalk code from the file"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2907
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2908
    |s rslt|
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2909
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2910
    s := self readStream.
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2911
    [
6422
d91c6082c200 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6402
diff changeset
  2912
        rslt := s fileIn.
d91c6082c200 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6402
diff changeset
  2913
    ] ensure:[
d91c6082c200 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6402
diff changeset
  2914
        s close.
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2915
    ].
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2916
    ^ rslt.
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2917
! !
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2918
2
claus
parents: 1
diff changeset
  2919
!Filename methodsFor:'instance creation'!
claus
parents: 1
diff changeset
  2920
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2921
construct:subname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2922
    "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
  2923
     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
  2924
     (i.e. for a file or a subdirectory in that directory).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2925
     The argument may not specify an absolute path name.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2926
     Please do not use this to create filenames with suffixes,
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2927
     since some systems require special naming conventions.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2928
     See also: #withSuffix: (which is different, but often needed)."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2929
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  2930
    ^ self class named:(self constructString:subname)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2931
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2932
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2933
     '/tmp' asFilename construct:'foo'    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2934
     '/' asFilename construct:'foo'         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2935
     '/usr/tmp' asFilename construct:'foo'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2936
     '/foo/bar' asFilename construct:'baz' 
6670
7792348f31e7 Comments
Stefan Vogel <sv@exept.de>
parents: 6662
diff changeset
  2937
     '/foo/bar' asFilename construct:'baz' asFilename 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2938
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2939
     Bad example; works on UNIX, but may not on others:
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2940
       'foo/bar.baz' construct:'.suff'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2941
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2942
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2943
    "Modified: 29.2.1996 / 20:55:06 / cg"
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2944
!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2945
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2946
constructDirectory:subname
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2947
    "same as #construct: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2948
     (may allow different/relaxed name syntax of the argument on some systems)"
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2949
     
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2950
    ^ self class named:(self constructDirectoryString:subname)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2951
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2952
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2953
constructDirectoryString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2954
    "same as #constructString: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2955
     (may allow different/relaxed name syntax of the argument on some systems)"
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2956
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2957
    ^ self constructString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2958
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2959
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2960
constructString:subName
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2961
    "taking the receiver as a directory name, construct a new
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2962
     filename-string for an entry within this directory 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2963
     (i.e. for a file or a subdirectory in that directory).
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2964
     The argument may not specify an absolute path name.
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2965
     The code below works for UNIX & MSDOS; 
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2966
     other filename classes (i.e. VMS) may want to redefine this method."
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2967
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2968
    |sepString sub|
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2969
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2970
    sub := subName asString.
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2971
    sepString := self class separator asString.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2972
    nameString = sepString ifTrue:[
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2973
        "I am the root"
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2974
        ^ sepString  , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2975
    ].
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2976
    (nameString endsWith:sepString) ifTrue:[
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2977
        ^ nameString , sub
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2978
    ].
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2979
    nameString size == 0 ifTrue:[
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2980
        ^ sub
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2981
    ].
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2982
    ^ nameString , sepString , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2983
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2984
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2985
     '/tmp' asFilename constructString:'foo'   
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2986
     '/' asFilename constructString:'foo'         
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2987
     '/usr/tmp' asFilename constructString:'foo'
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2988
     '/foo/bar' asFilename constructString:'baz' 
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  2989
     '' asFilename constructString:'baz' 
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2990
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2991
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2992
    "Modified: / 7.9.1995 / 10:15:22 / claus"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2993
    "Created: / 9.9.1997 / 08:57:08 / cg"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2994
    "Modified: / 20.1.1998 / 15:58:23 / md"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2995
    "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
  2996
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2997
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2998
filenameFor:fileName
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2999
    "taking the receiver as a directory name, construct a new
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3000
     filename for an entry within this directory 
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3001
     (i.e. for a file or a subdirectory in that directory).
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3002
     If the argument specifies an absolute path name, the argument is returned."
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3003
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3004
    |f|
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3005
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3006
    f := fileName asFilename.
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3007
    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
  3008
    ^ (self construct:fileName)
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3009
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3010
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3011
     '/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
  3012
     '/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
  3013
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3014
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3015
    "Created: 18.9.1997 / 14:34:14 / stefan"
2
claus
parents: 1
diff changeset
  3016
! !
claus
parents: 1
diff changeset
  3017
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3018
!Filename methodsFor:'misc'!
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3019
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3020
, aString
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3021
    "this allows filenames to understand how names are concatenated.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  3022
     Returns a string consisting of the receivers name, concatenated
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3023
     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
  3024
     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
  3025
     See also: #withSuffix: which is new and better."
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3026
5866
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  3027
    <resource:#obsolete>
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  3028
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3029
    self obsoleteMethodWarning:'use #construct:'.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  3030
    ^ (nameString , aString asString)
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3031
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3032
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3033
     'Makefile' asFilename , '.bak'        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3034
     ('Makefile' asFilename , '.bak') asFilename  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3035
     'Makefile' asFilename withSuffix:'bak' 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3036
     'Makefile' asFilename construct:'.bak'     
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3037
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3038
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3039
    "Modified: 7.9.1997 / 23:45:36 / cg"
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3040
! !
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3041
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3042
!Filename methodsFor:'printing & storing'!
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3043
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3044
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  3045
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  3046
     The format is suitable for a human - not meant to be read back."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3047
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3048
    aStream nextPutAll:(self class name).
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3049
    aStream nextPutAll:'('''.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3050
    nameString printOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3051
    aStream nextPutAll:''')'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3052
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3053
    "Modified: 7.9.1997 / 23:46:20 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3054
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3055
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3056
storeOn:aStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3057
    "append a printed representation of the receiver to aStream,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3058
     which allows reconstructing it via readFrom:"
328
claus
parents: 326
diff changeset
  3059
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3060
    aStream nextPut:$(.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3061
    nameString storeOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3062
    aStream nextPutAll:' asFilename)'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3063
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3064
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 195
diff changeset
  3065
!Filename methodsFor:'private accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3066
6227
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3067
getName
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3068
    "get the raw filename"
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3069
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3070
    ^ nameString 
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3071
!
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3072
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3073
setName:aString
38
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  3074
    "set the filename"
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  3075
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3076
    nameString := self nameWithSpecialExpansions:aString.
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3077
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3078
    "Modified: / 21.7.1998 / 10:44:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3079
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3080
2
claus
parents: 1
diff changeset
  3081
!Filename methodsFor:'queries'!
claus
parents: 1
diff changeset
  3082
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3083
canBeWritten
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3084
    "same as isWritable - for ST-80 compatibility"
328
claus
parents: 326
diff changeset
  3085
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3086
    ^ self isWritable
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3087
328
claus
parents: 326
diff changeset
  3088
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3089
     '/foo/bar' asFilename canBeWritten 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3090
     '/tmp' asFilename canBeWritten   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3091
     'Makefile' asFilename canBeWritten   
328
claus
parents: 326
diff changeset
  3092
    "
claus
parents: 326
diff changeset
  3093
!
claus
parents: 326
diff changeset
  3094
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3095
exists
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3096
    "return true, if such a file exists."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3097
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3098
    ^ OperatingSystem isValidPath:(self osNameForAccess)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3099
85
claus
parents: 77
diff changeset
  3100
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3101
     '/foo/bar' asFilename exists 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3102
     '/tmp' asFilename exists  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3103
     'Makefile' asFilename exists   
85
claus
parents: 77
diff changeset
  3104
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3105
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3106
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3107
filenamesMatching:aPattern
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3108
    "VW compatibility"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3109
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3110
    ^ (self filesMatching:aPattern) asOrderedCollection
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3111
	    collect:[:eachName | self construct:eachName]
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3112
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3113
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3114
     '/etc' asFilename filenamesMatching:'a*;c*' 
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3115
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3116
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3117
    "Created: / 15.4.1997 / 15:40:02 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3118
    "Modified: / 3.8.1998 / 21:22:15 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3119
!
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3120
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3121
filesMatching:aPattern
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3122
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3123
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3124
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3125
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3126
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3127
    |matchers notCaseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3128
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3129
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3130
    notCaseSensitive := self class isCaseSensitive not.
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3131
    ^ self directoryContents
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3132
	select:[:name | 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3133
		(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3134
	       ]
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3135
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3136
    "
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3137
     '/etc' asFilename filesMatching:'a*;c*' 
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3138
    "
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3139
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3140
    "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
  3141
    "Modified: / 3.8.1998 / 21:22:15 / cg"
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3142
!
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3143
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3144
filesMatchingWithoutDotDirs:aPattern
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3145
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3146
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3147
     Exclude '.' and '..' from the returned list.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3148
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3149
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3150
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3151
    |matchers notCaseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3152
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3153
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3154
    notCaseSensitive := self class isCaseSensitive not.
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3155
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3156
    ^ self directoryContents 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3157
	select:[:name | 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3158
		name ~= '.'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3159
		and:[name ~= '..'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3160
		and:[(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0]]
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3161
      ]
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3162
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3163
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3164
     Filename currentDirectory filesMatching:'M*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3165
     '/etc' asFilename filesMatching:'[a-z]*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3166
     '../../libbasic' asFilename filesMatching:'[A-D]*.st'  
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3167
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3168
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3169
    "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
  3170
    "Modified: / 3.8.1998 / 21:22:30 / cg"
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3171
!
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3172
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3173
isAbsolute
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3174
    "return true, if the receiver represents an absolute pathname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3175
     (in contrast to one relative to the current directory)."
356
claus
parents: 328
diff changeset
  3176
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3177
    (nameString startsWith:self class separator) ifTrue:[^ true].
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3178
    ^ self isVolumeAbsolute
328
claus
parents: 326
diff changeset
  3179
claus
parents: 326
diff changeset
  3180
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3181
     '/foo/bar' asFilename isAbsolute   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3182
     '..' asFilename isAbsolute         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3183
     '..' asAbsoluteFilename isAbsolute         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3184
     'source/SBrowser.st' asFilename isAbsolute  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3185
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3186
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3187
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3188
isDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3189
    "return true, if the receiver represents an existing,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3190
     readable directories pathname."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3191
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3192
    ^ OperatingSystem isDirectory:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3193
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3194
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3195
     '/foo/bar' asFilename isDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3196
     '/tmp' asFilename isDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3197
     'Makefile' asFilename isDirectory   
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3198
     'c:\' asFilename isDirectory   
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3199
     'd:\' asFilename isDirectory   
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3200
    "
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3201
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3202
    "Modified: / 21.9.1998 / 15:53:10 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3203
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3204
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3205
isExecutable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3206
    "return true, if such a file exists and is executable (by Unix's definition).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3207
     For directories, true is returned if the directory can be entered.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3208
     See isExecutableProgram for a related check."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3209
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3210
    ^ OperatingSystem isExecutable:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3211
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3212
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3213
     '/foo/bar' asFilename isExecutable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3214
     '/tmp' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3215
     'Makefile' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3216
     '/bin/ls' asFilename isExecutable   
356
claus
parents: 328
diff changeset
  3217
    "
claus
parents: 328
diff changeset
  3218
!
claus
parents: 328
diff changeset
  3219
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3220
isExecutableProgram
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3221
    "return true, if such a file exists and is an executable program.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3222
     (i.e. for directories, false is returned.)"
356
claus
parents: 328
diff changeset
  3223
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3224
    |osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3225
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3226
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3227
    ^ (OperatingSystem isExecutable:osName)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3228
      and:[(OperatingSystem isDirectory:osName) not]
356
claus
parents: 328
diff changeset
  3229
claus
parents: 328
diff changeset
  3230
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3231
     '/tmp' asFilename isExecutable         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3232
     '/bin/ls' asFilename isExecutable       
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3233
     '/tmp' asFilename isExecutableProgram   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3234
     '/bin/ls' asFilename isExecutableProgram    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3235
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3236
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3237
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3238
isExplicitRelative
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3239
    "return true, if this name is an explicit relative name
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3240
     (i.e. starts with './' or '../', to avoid path-prepending)"
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3241
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3242
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3243
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3244
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3245
isHidden
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3246
    "return true, if the receiver represents a hidden file.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3247
     The definitions of hidden files depends on the OS used;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3248
     on UNIX, a name starting with a period is considered hidden;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3249
     on MSDOS, the files hidden attribute is used.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3250
     VMS has no concept of hidden files."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3251
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3252
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3253
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3254
2944
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3255
isImplicit
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3256
    "return true, if the receiver represents a builtin file.
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3257
     The definitions of builtin files depends on the OS used;
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3258
     on UNIX, '.' and '..' are builtin names."
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3259
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3260
    ^ false
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3261
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3262
    "Created: 18.9.1997 / 18:04:51 / stefan"
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3263
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3264
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3265
isMountPoint:aPathName
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3266
    "return true, if I represent a mount-point.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3267
     Warning: 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3268
        the receiver must be an absolute pathname, 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3269
        because a realPath is not used/generated for the query (to avoid automounting).
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3270
        Aka: do not ask: '../../' asFilename isMountPoint;
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3271
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3272
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3273
    self isAbsolute ifFalse:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3274
        self error:'this query must be done on an absolute pathname'.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3275
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3276
    ^ OperatingSystem isMountPoint:(self name)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3277
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3278
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3279
isReadable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3280
    "return true, if such a file exists and is readable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3281
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3282
    ^ OperatingSystem isReadable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3283
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3284
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3285
     '/foo/bar' asFilename isReadable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3286
     '/tmp' asFilename isReadable      
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3287
     'Makefile' asFilename isReadable   
328
claus
parents: 326
diff changeset
  3288
    "
claus
parents: 326
diff changeset
  3289
!
claus
parents: 326
diff changeset
  3290
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3291
isRelative
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3292
    "return true, if this name is interpreted relative to some
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3293
     directory (opposite of absolute)"
328
claus
parents: 326
diff changeset
  3294
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3295
    ^ self isAbsolute not
2175
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3296
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3297
    "
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3298
     './foo/bar' asFilename isRelative
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3299
     '../../foo/bar' asFilename isRelative
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3300
     '/foo/bar' asFilename isRelative     
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3301
     'bar' asFilename isRelative          
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3302
    "
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3303
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  3304
    "Modified: 16.1.1997 / 01:19:14 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3305
!
328
claus
parents: 326
diff changeset
  3306
3045
fb2d17c7a360 fixed fullDirectoryContents (mounted volumes)
ca
parents: 3015
diff changeset
  3307
isRootDirectory
3046
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3308
    "return true, if I represent the root directory 
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3309
     (i.e. I have no parentDir)"
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3310
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3311
    "/ mhmh - should we use:
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3312
    "/
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3313
    "/ parentDir := self construct:'..'.
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3314
    "/ (parentDir exists
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3315
    "/ and:[parentDir isDirectory
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3316
    "/ and:[parentDir id ~= self id]]) ifTrue:[
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3317
    "/    ^ false
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3318
    "/ ].
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3319
    "/ ^ true
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3320
    "/
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3321
3046
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3322
    ^ self pathName = Filename rootDirectory pathName
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3323
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3324
    "Modified: 23.10.1997 / 00:38:35 / cg"
3045
fb2d17c7a360 fixed fullDirectoryContents (mounted volumes)
ca
parents: 3015
diff changeset
  3325
!
fb2d17c7a360 fixed fullDirectoryContents (mounted volumes)
ca
parents: 3015
diff changeset
  3326
6729
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3327
isSpecialFile
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3328
    "return true, if the receiver represents a socket, named pipe, fifo
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3329
     or device special file (i.e. anything non regular and non-directory)"
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3330
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3331
    |t|
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3332
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3333
    t := self type.
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3334
    ^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]])
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3335
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3336
    "
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3337
     '/foo/bar' asFilename isSpecialFile
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3338
     '/tmp' asFilename isSpecialFile
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3339
     'Makefile' asFilename isSpecialFile   
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3340
     'c:\' asFilename isSpecialFile   
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3341
     'd:\' asFilename isSpecialFile   
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3342
     '/dev/null' asFilename isSpecialFile   
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3343
    "
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3344
!
ce3a5460987a added #isSpecialFile
Claus Gittinger <cg@exept.de>
parents: 6670
diff changeset
  3345
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3346
isSymbolicLink
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3347
    "return true, if the file represented by the receiver is a symbolic
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3348
     link. Notice that not all OS's support symbolic links; those that do
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3349
     not will always return false."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3350
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3351
    ^ OperatingSystem isSymbolicLink:(self osNameForFile)
328
claus
parents: 326
diff changeset
  3352
claus
parents: 326
diff changeset
  3353
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3354
     'Make.proto' asFilename isSymbolicLink  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3355
     'Makefile' asFilename isSymbolicLink   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3356
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3357
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3358
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3359
isVolumeAbsolute
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3360
    "return true, if the receiver represents an absolute pathname
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3361
     on some disk volume (MSDOS only)"
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3362
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3363
    ^ false
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3364
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3365
    "Modified: 7.9.1997 / 23:54:33 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3366
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3367
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3368
isWritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3369
    "return true, if such a file exists and is writable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3370
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3371
    ^ OperatingSystem isWritable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3372
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3373
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3374
     '/foo/bar' asFilename isWritable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3375
     '/tmp' asFilename isWritable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3376
     'Makefile' asFilename isWritable   
328
claus
parents: 326
diff changeset
  3377
    "
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3378
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3379
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3380
separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3381
    "return the directory-separator character"
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3382
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3383
    ^ self class separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3384
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3385
    "Modified: 29.2.1996 / 20:52:01 / cg"
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3386
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3387
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3388
!Filename methodsFor:'queries-contents'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3389
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3390
mimeTypeOfContents
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3391
    "this tries to guess the mime type of contents of
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3392
     the file. Returns nil, if the file is unreadable, not a plain file
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3393
     or the contents is unknown.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3394
     This is done using some heuristics, and may need some improvement"
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3395
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3396
    |type buffer s size suffix idx idx2 baseNm|
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3397
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3398
    self isDirectory ifTrue:[
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3399
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3400
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3401
    (type := self type) == #characterSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3402
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3403
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3404
    type == #blockSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3405
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3406
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3407
    type == #socket ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3408
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3409
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3410
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3411
    self isReadable ifFalse:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3412
    self fileSize == 0 ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3413
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3414
    suffix := self suffix asLowercase.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3415
    baseNm := self withoutSuffix baseName asLowercase.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3416
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3417
    "/ read some data from the file ...
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3418
    buffer := String new:2024.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3419
    s := self readStream.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3420
    s isNil ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3421
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3422
    size := s nextBytes:buffer size into:buffer.
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3423
    s close.
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3424
    buffer := buffer asLowercase.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3425
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3426
    (idx := buffer findString:'mimetype:') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3427
        idx := idx + 'mimetype:' size.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3428
        idx := buffer indexOfNonSeparatorStartingAt:idx.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3429
        idx2 := buffer indexOfSeparatorStartingAt:idx.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3430
        idx2 > idx ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3431
            ^ buffer copyFrom:idx to:idx2-1
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3432
        ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3433
    ].
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3434
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3435
    #(
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3436
            ('interchangeversion:'       'application/x-smalltalk-source-sif')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3437
            ('subclass:'                 'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3438
            ('methodsfor:'               'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3439
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3440
            ('<body:'                    'text/html')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3441
            ('%!!ps-adobe'                'application/postscript')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3442
            ('#!! /bin/sh'                'application/x-sh')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3443
            ('#!!/bin/sh'                 'application/x-sh')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3444
            "/ ('#!! /bin/bash'              'application/x-bash')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3445
            "/ ('#!!/bin/bash'               'application/x-bash')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3446
            ('<?xml version='            'text/xml')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3447
        
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3448
            ('from dolphin'              'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3449
            ('from visualworks'          'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3450
            ('categoriesforclass' 'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3451
            ('methodsfor!!'        'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3452
            ('subclass:'          'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3453
            ('methodsfor:'        'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3454
     ) pairsDo:[:pattern :what | 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3455
        (buffer findString:pattern) ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3456
            ^ what
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3457
        ]
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3458
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3459
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3460
    (idx := buffer findString:'<H') ~~ 0 ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3461
        ((buffer continuesWith:'<HEAD' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3462
        or:[(buffer continuesWith:'<HTML' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3463
        or:[(buffer continuesWith:'<H1' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3464
        or:[(buffer continuesWith:'<H2' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3465
        or:[(buffer continuesWith:'<H3' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3466
        or:[(buffer continuesWith:'<H4' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3467
        or:[(buffer continuesWith:'<H5' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3468
        or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]])
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3469
        ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3470
            ^ 'text/html'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3471
        ]
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3472
    ].
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3473
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3474
    [size ~~ 0 and:[(buffer at:size) isPrintable]] whileTrue:[size := size - 1].
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3475
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3476
    size == 0 ifTrue:[
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3477
        ^ 'text/plain'
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3478
    ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3479
    ^ nil
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3480
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3481
    "
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3482
     'Makefile' asFilename mimeTypeOfContents     
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3483
     '.' asFilename mimeTypeOfContents            
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3484
     '/dev/null' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3485
     '/tmp/.X11-unix/X0' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3486
     'smalltalk.rc' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3487
     'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3488
     '../../rules/stmkmf' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3489
    "
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3490
5012
3134cc1bd02b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5011
diff changeset
  3491
    "Modified: / 19.11.1999 / 15:58:29 / cg"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3492
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3493
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3494
!Filename methodsFor:'queries-path & name'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3495
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3496
baseName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3497
    "return my baseName as a string.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3498
     - thats the file/directory name without leading parent-dirs.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3499
     (i.e. '/usr/lib/st/file' asFilename baseName -> 'file'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3500
       and '/usr/lib'         asFilename baseName -> lib).
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3501
     This method does not check if the path is valid
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3502
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3503
     See also: #pathName, #directoryName and #directoryPathName.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3504
     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
  3505
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3506
    |len index sep endIdx|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3507
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3508
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3509
    len := nameString size.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3510
    ((len == 1) and:[(nameString at:1) == sep]) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3511
	^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3512
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3513
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3514
    endIdx := len.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3515
    len > 1 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3516
	(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3517
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3518
    index := nameString lastIndexOf:sep startingAt:len-1.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3519
    index == 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3520
	^ nameString copyTo:endIdx
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3521
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3522
    ^ 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
  3523
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3524
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3525
     '/foo/bar' asFilename baseName  
4903
1487c740eaba comment
Claus Gittinger <cg@exept.de>
parents: 4901
diff changeset
  3526
     '/foo/bar.cc' asFilename baseName  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3527
     '.' asFilename baseName          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3528
     '..' asFilename baseName         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3529
     '../..' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3530
     '../../libbasic' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3531
     '../../libpr' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3532
     '../../libbasic/Object.st' asFilename baseName        
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3533
     '/' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3534
     '\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3535
     'c:\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3536
     '\\idefix' asFilename baseName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3537
    "
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3538
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3539
    "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
  3540
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3541
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3542
directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3543
    "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
  3544
     - 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
  3545
       the receiver is contained in.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3546
     (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
  3547
      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
  3548
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  3549
    ^ self class named:(self directoryName)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3550
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3551
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3552
     '/foo/bar' asFilename directory      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3553
     '/foo/bar' asFilename directoryName  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3554
     '/foo/bar' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3555
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3556
     '.' asFilename directory        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3557
     '..' asFilename directory       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3558
     '../..' asFilename directory     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3559
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3560
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3561
    "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
  3562
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3563
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3564
directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3565
    "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
  3566
     - 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
  3567
       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
  3568
     This method does not check if the path is valid.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3569
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3570
     (i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3571
       and '/usr/lib' asFilename directoryName         -> /usr').
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3572
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3573
     (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
  3574
      a string instead of a Filename instance).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3575
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3576
     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
  3577
     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
  3578
3954
20cc39f4e75c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  3579
    |index sep sepString p rest|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3580
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3581
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3582
    sepString := sep asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3583
    (nameString = sepString) ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3584
        "/
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3585
        "/ the trivial '/' case
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3586
        "/
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3587
        ^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3588
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3589
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3590
    "/
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3591
    "/ strip off multiple trailing slashes
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3592
    "/
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3593
    p := nameString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3594
    [p endsWith:sepString] whileTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3595
        (p = sepString) ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3596
            ^ p
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3597
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3598
        p := p copyWithoutLast:1
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3599
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3600
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3601
    "/ strip off trailing components
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3602
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3603
    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
  3604
    index == 0 ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3605
        "/ no separator found
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3606
        p = '.' ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3607
            ^ '..'
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3608
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3609
        p = '..' ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3610
            ^ '../..'
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3611
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3612
        ^ '.'
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3613
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3614
    rest := p copyFrom:(index+1).
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3615
    (rest = '.' or:[rest = '..']) ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3616
        ^ self pathName asFilename directoryName
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3617
    ].
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3618
    index == 1 ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3619
        ^ '/'
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3620
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3621
    ^ p copyTo:(index - 1)
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
    "
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3624
     '/home' asFilename directoryName          
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3625
     '/foo/bar/' asFilename directoryName    
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3626
     '/foo/bar/' asFilename directory      
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3627
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3628
     '/foo/bar' asFilename directoryName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3629
     'bitmaps' asFilename directoryName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3630
     'bitmaps' asFilename directoryPathName        
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3631
     '.' asFilename directoryName           
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3632
     '.' asFilename directoryPathName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3633
     '..' asFilename directoryName       
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3634
     '..' asFilename directoryPathName       
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3635
     '../..' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3636
     '../..' asFilename directoryPathName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3637
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3638
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3639
    "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
  3640
    "Modified: / 21.10.1998 / 22:52:25 / cg"
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3641
    "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
  3642
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3643
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3644
directoryPathName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3645
    "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
  3646
     - 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
  3647
       the receiver is contained in.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3648
     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
  3649
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  3650
    ^ (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
  3651
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3652
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3653
     '/foo/bar/' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3654
     '/foo/bar' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3655
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3656
     '.' asFilename directoryPathName      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3657
     '.' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3658
     '.' asFilename directory          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3659
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3660
     '..' asFilename directoryPathName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3661
     '..' asFilename directoryName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3662
     '..' asFilename directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3663
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3664
     '../..' asFilename directoryPathName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3665
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3666
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3667
    "Modified: 7.9.1995 / 10:42:13 / claus"
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3668
    "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
  3669
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3670
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3671
filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3672
    "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
  3673
     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
  3674
     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
  3675
       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
  3676
       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
  3677
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3678
     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
  3679
     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
  3680
     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
  3681
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3682
    ^ self filenameCompletionIn:nil
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3683
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3684
    " 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3685
     'mak' asFilename filenameCompletion  
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3686
     'Make' asFilename filenameCompletion  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3687
     'Makef' asFilename filenameCompletion;yourself  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3688
     '/u' asFilename filenameCompletion             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3689
     '../../libpr' asFilename inspect filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3690
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3691
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3692
    "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
  3693
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3694
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3695
filenameCompletionIn:aDirectory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3696
    "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
  3697
     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
  3698
     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
  3699
       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
  3700
       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
  3701
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3702
     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
  3703
     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
  3704
     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
  3705
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3706
    |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
  3707
     sepString parentString prefix nMatch nm caseless lcBaseName|
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3708
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3709
    caseless := self class isCaseSensitive not.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3710
    matching := OrderedCollection new.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3711
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3712
    nm := self nameWithSpecialExpansions:nameString.
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
  3713
    nm := self class canonicalize:nm.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3714
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3715
    sepString := self class separator asString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3716
    (nm endsWith:sepString) ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3717
        "/ two exceptions here: 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3718
        "/   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
  3719
        "/   otherwise, return the longest common prefix of all files.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3720
        (self isDirectory and:[self exists]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3721
            |first longest|
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3722
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3723
            first := nil.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3724
            self directoryContentsDo:[:fileName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3725
                ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3726
                    matching add:fileName.    
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3727
                    first isNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3728
                        first := longest := fileName.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3729
                    ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3730
                        "/ more than one file
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3731
                        longest := longest commonPrefixWith:fileName ignoreCase:caseless.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3732
                        longest isEmpty ifTrue:[ ^ #() ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3733
                    ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3734
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3735
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3736
            longest notNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3737
                nameString := (self constructString:longest).
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3738
                 ^ matching
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3739
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3740
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3741
        ^ #()
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3742
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3743
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3744
    parentString := self class parentDirectoryName.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3745
    baseName := self baseName.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3746
    baseName ~= nm ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3747
        prefix := self directoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3748
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3749
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3750
    self isAbsolute ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3751
        dir := self directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3752
    ] ifFalse:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3753
        aDirectory isNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3754
            dir := self directory
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3755
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3756
            dir := (aDirectory construct:nm) directory
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3757
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3758
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3759
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3760
    caseless ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3761
        lcBaseName := baseName asLowercase
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3762
    ].
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3763
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3764
    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
  3765
        ^ #().
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3766
    ] do:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3767
        dir directoryContents do:[:fileName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3768
            ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3769
                ((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
  3770
                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
  3771
                    matching add:fileName
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3772
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3773
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3774
        ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3775
    ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3776
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3777
    (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
  3778
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3779
         find the longest common prefix
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3780
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3781
        matchLen := baseName size.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3782
        matchLen > matching first size ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3783
            try := baseName.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3784
            allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3785
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3786
            try := matching first copyTo:matchLen.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3787
            allMatching := true.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3788
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3789
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3790
        [allMatching] whileTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3791
            matching do:[:aName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3792
                ((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
  3793
                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
  3794
                    allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3795
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3796
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3797
            allMatching ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3798
                matchLen <  matching first size ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3799
                    matchLen := matchLen + 1.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3800
                    try := matching first copyTo:matchLen.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3801
                ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3802
                    allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3803
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3804
            ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3805
                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
  3806
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3807
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3808
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3809
         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
  3810
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3811
        nameString := nm := try
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3812
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3813
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3814
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3815
     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
  3816
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3817
    prefix notNil ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3818
        prefix = sepString ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3819
            "/ avoid introducing double slashes
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3820
            prefix := ''
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3821
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3822
        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
  3823
        nMatch == 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3824
            nameString := nm := matching first
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3825
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3826
            nMatch > 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3827
                nameString := nm := prefix , sepString , nm
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3828
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3829
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3830
    ] ifFalse:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3831
        nMatch == 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3832
            nameString := nm := matching first
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3833
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3834
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3835
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3836
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3837
     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
  3838
     (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
  3839
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3840
    ^ matching
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3841
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3842
    " trivial cases:
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3843
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3844
     '../' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3845
     '/' asFilename filenameCompletion      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3846
     '/usr/' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3847
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3848
     'mak' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3849
     'Make' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3850
     'Makef' asFilename filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3851
     '/u' asFilename filenameCompletion             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3852
     '../../libpr' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3853
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3854
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3855
    "Modified: / 22.9.1997 / 18:03:33 / stefan"
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  3856
    "Modified: / 30.4.1999 / 09:39:52 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  3857
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  3858
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3859
head 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3860
    "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
  3861
     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
  3862
     (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
  3863
      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
  3864
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3865
    ^ self directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3866
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3867
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3868
     Filename currentDirectory head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3869
     'Makefile' asFilename head    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3870
     '/foo/bar/baz.st' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3871
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3872
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3873
    "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
  3874
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3875
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3876
isParentDirectoryOf:aFilenameOrString
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3877
    "warning: may lead to automounting"
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3878
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3879
    |filenameArg otherName myName|
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3880
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3881
    filenameArg := aFilenameOrString asFilename directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3882
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3883
    otherName := filenameArg name.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3884
    myName := self name.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3885
    (otherName startsWith:myName ) ifTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3886
        ^ (otherName ~= myName)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3887
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3888
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3889
    otherName := filenameArg pathName.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3890
    myName := self pathName.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3891
    (otherName startsWith:myName ) ifTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3892
        ^ (otherName ~= myName)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3893
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3894
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3895
    filenameArg allParentDirectoriesDo:[:parent |
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3896
        parent pathName = myName ifTrue:[^ true].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3897
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3898
    ^ false.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3899
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3900
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3901
     '/etc' asFilename isParentDirectoryOf:'/etc/passwd' 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3902
     '/etc' asFilename isParentDirectoryOf:'/etc/'   
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3903
     '/etc' asFilename isParentDirectoryOf:'/etc'   
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3904
     '/home' asFilename isParentDirectoryOf:Filename currentDirectory 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3905
     '/' asFilename isParentDirectoryOf:'/phys/qnx'      
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3906
    "       
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3907
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3908
2987
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3909
localPathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3910
    "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
  3911
     but without any volume information.
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3912
     Only makes a difference on MSDOS & VMS systems."
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3913
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3914
    ^ self pathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3915
!
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3916
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3917
name
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3918
    "return the name of the file represented by the receiver as a string.
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3919
     This may or may not be a relative name (i.e. include ..'s).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3920
     See also: pathName"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3921
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3922
"/    self isAbsolute ifTrue:[^ self pathName].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3923
    ^ nameString
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3924
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3925
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3926
     '/foo/bar' asFilename name        
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3927
     '/foo/bar' asFilename pathName    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3928
     '.' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3929
     '.' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3930
     '../..' asFilename name             
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3931
     '../..' asFilename pathName 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3932
     'bitmaps' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3933
     'bitmaps' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3934
     '/tmp/../usr' asFilename name       
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3935
     '/tmp/../usr' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3936
     'source/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3937
     'source/..' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3938
     '/tmp/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3939
     '/tmp/..' asFilename pathName    
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3940
    "
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3941
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3942
    "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
  3943
!
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3944
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3945
pathName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3946
    "return the full pathname of the file represented by the receiver,
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3947
     as a string. This will not include ..'s. 
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3948
     If the path represented by the receiver does NOT represent a valid path,
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3949
     no compression will be done (for now; this may change).
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3950
     See also: name"
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3951
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3952
    |p|
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3953
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3954
"/    sep := self class separator.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3955
"/    (nameString startsWith:sep) ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3956
"/        parentName := self class parentDirectoryName.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3957
"/        (nameString findString:parentName) == 0 ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3958
"/            ^ nameString
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3959
"/        ]
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3960
"/    ].
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3961
    p := OperatingSystem pathNameOf:nameString.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3962
    ^ p
2
claus
parents: 1
diff changeset
  3963
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3964
    "
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3965
     '/foo/bar' asFilename pathName  
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3966
     '.' asFilename pathName         
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3967
     '../..' asFilename pathName     
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3968
     '../..' asFilename name           
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3969
     '/tmp/../usr' asFilename pathName   
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3970
     '/././usr' asFilename pathName     
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3971
    "
159
514c749165c3 *** empty log message ***
claus
parents: 132
diff changeset
  3972
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3973
    "Modified: 27.4.1996 / 18:19:52 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3974
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3975
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3976
physicalPathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3977
    "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
  3978
     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
  3979
     final target. Otherwise, its the receivers pathName itself.
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3980
     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
  3981
     nil is returned."
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3982
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3983
    |t target path|
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3984
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3985
    self isSymbolicLink ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3986
	self exists ifFalse:[^ nil].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3987
	^ self pathName
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3988
    ].
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3989
    t := self.
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3990
    [t isSymbolicLink] whileTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3991
	path := t linkInfo path.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3992
	path isNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3993
	    "/ cannot happen
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3994
	    ^ nil
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3995
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3996
	target := (self class named:t directoryName) construct:path.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3997
	target exists ifFalse:[^ nil].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3998
	t := target asFilename
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3999
    ].
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4000
    t exists ifFalse:[^ nil].
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4001
    ^ t pathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4002
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4003
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4004
     '/foo/bar' asFilename physicalPathName  
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4005
     '.' asFilename physicalPathName         
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4006
     '../..' asFilename physicalPathName     
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4007
     'include/abbrev.stc' asFilename physicalPathName           
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4008
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4009
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4010
    "Modified: 21.12.1996 / 15:29:50 / cg"
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4011
!
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4012
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4013
tail
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4014
    "the files name without directory prefix as a string. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4015
     An alias for baseName, for ST-80 compatiblity."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4016
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4017
    ^ self baseName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4018
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4019
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4020
     Filename currentDirectory tail 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4021
     'Makefile' asFilename tail    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4022
     '/foo/bar/baz.st' asFilename tail  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4023
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4024
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4025
    "Modified: 29.2.1996 / 20:19:50 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4026
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4027
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4028
volume
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4029
    "return the disc volume part of the name or an empty string.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4030
     This is only used with MSDOS and VMS filenames 
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4031
     - by default (and on unix), an empty string is returned"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4032
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4033
    ^ ''
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4034
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4035
    "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
  4036
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4037
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4038
!Filename methodsFor:'reading-directories'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4039
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4040
directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4041
    "return the contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4042
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4043
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4044
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4045
     So users of this method better test for existing directory before.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4046
     Notice: this returns the file-names as strings; see also
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4047
     #directoryContentsAsFilenames, which returns fileName objects."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4048
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4049
    |s contents|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4050
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4051
    s := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4052
    s isNil ifTrue:[^nil].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4053
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4054
    [ 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4055
        contents := s contents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4056
    ] ensure:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4057
        s close
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4058
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4059
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4060
    contents remove:'.' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4061
    contents remove:'..' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4062
    ^ contents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4063
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4064
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4065
     '.' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4066
     '/XXXdoesNotExist' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4067
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4068
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4069
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4070
    "Modified: / 3.8.1998 / 21:36:21 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4071
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4072
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4073
directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4074
    "return the contents of the directory as a collection of filenames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4075
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4076
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4077
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4078
     So users of this method better test for existing directory before.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4079
     Notice: this returns the file-names as fileName objects; see also
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4080
     #directoryContents, which returns strings."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4081
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4082
    |names|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4083
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4084
    names := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4085
    names isNil ifTrue:[^ nil].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4086
    ^ names asOrderedCollection collect:[:entry | self construct:entry].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4087
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4088
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4089
     '.' asFilename directoryContentsAsFilenames   
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4090
     '/XXXdoesNotExist' asFilename directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4091
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4092
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4093
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4094
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4095
directoryContentsDo:aBlock
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4096
    "evaluate aBlock for each file in the directory represented by the receiver.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4097
     The block is invoked with a string as argument.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4098
     The enumerations order is undefined - i.e. usually NOT sorted by
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4099
     filenames (but by creation time - on some systems).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4100
     This excludes entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4101
     NoOp for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4102
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4103
     So users of this method better test for existing directory before.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4104
     Notice: this enumerates strings; see also
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4105
     #directoryContentsDo:, which enumerates fileName objects."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4106
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4107
    |s fn|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4108
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4109
    s := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4110
    s isNil ifTrue:[^ nil].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4111
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4112
    [
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4113
        [s atEnd] whileFalse:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4114
            fn := s nextLine.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4115
            ((fn ~= '.') and:[fn ~= '..']) ifTrue:[        
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4116
                aBlock value:fn
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4117
            ]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4118
        ]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4119
    ] ensure:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4120
        s close
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4121
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4122
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4123
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4124
     '.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4125
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4126
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4127
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4128
    "Modified: / 23.12.1999 / 20:56:35 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4129
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4130
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4131
fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4132
    "return the full contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4133
     This is much like #directoryContents, but includes an entry for the
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4134
     parent directory, if there is one.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4135
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4136
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4137
     So users of this method better test for existing directory before."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4138
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4139
    |files|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4140
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4141
    files := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4142
    files isNil ifTrue:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4143
	"/ mhmh - that one does not exist
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4144
	^ files
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4145
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4146
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4147
    "/ add/remove parentDirectory if there is one/none
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4148
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4149
    files remove:'.' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4150
    self isRootDirectory ifTrue:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4151
	files remove:'..' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4152
    ] ifFalse:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4153
	(files includes:'..') ifFalse:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4154
	    files addFirst:'..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4155
	]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4156
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4157
    ^ files
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4158
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4159
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4160
     '.' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4161
     '/XXXdoesNotExist' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4162
     'd:\FET' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4163
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4164
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4165
    "Modified: / 21.9.1998 / 15:33:07 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4166
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4167
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4168
recursiveDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4169
    "return the contents of the directory and all subdirectories
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4170
     as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4171
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4172
     Subdirectory files are included with a relative pathname.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4173
     Warning: this may take a long time to execute."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4174
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4175
    |fileNames dirNames|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4176
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4177
    fileNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4178
    dirNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4179
    self directoryContents do:[:f |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4180
	(self construct:f) isDirectory ifTrue:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4181
	    dirNames add:f
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4182
	] ifFalse:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4183
	    fileNames add:f
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4184
	]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4185
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4186
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4187
    dirNames do:[:dN |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4188
	|dd subFiles|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4189
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4190
	dd := dN asFilename.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4191
	subFiles := (self construct:dN) recursiveDirectoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4192
	fileNames addAll:(subFiles collect:[:f | dd constructString:f])
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4193
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4194
    ^ fileNames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4195
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4196
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4197
     '.' asFilename recursiveDirectoryContents 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4198
     '../../clients' asFilename recursiveDirectoryContents 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4199
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4200
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4201
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4202
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4203
!Filename methodsFor:'reading-files'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4204
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4205
binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4206
    "return the binary contents of the file (as a byteArray);
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4207
     or nil, if the file is unreadable/non-existing."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4208
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4209
    ^ self readingFileDo:[:s | s isNil 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4210
                                ifTrue:[nil]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4211
                                ifFalse:[s binary. s contentsOfEntireFile]].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4212
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4213
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4214
     'Makefile' asFilename binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4215
     'foobar' asFilename binaryContentsOfEntireFile   
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4216
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4217
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4218
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4219
contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4220
    "return the contents of the file as a collection of lines;
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4221
     or nil, if the file is unreadable/non-existing.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4222
     See also #contentsOfEntireFile, which returns a string for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4223
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4224
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4225
    ^ self readingFileDo:[:s | s isNil 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4226
                                ifTrue:[nil]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4227
                                ifFalse:[s contents]].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4228
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4229
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4230
     'Makefile' asFilename contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4231
     'foobar' asFilename contents            
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4232
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4233
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4234
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4235
    "Created: / 11.7.1996 / 14:09:11 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4236
    "Modified: / 15.10.1998 / 11:41:45 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4237
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4238
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4239
contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4240
    "return the contents of the file as a string;
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4241
     or nil, if the file is unreadable/non-existing.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4242
     See also #contents, which returns the lines as stringCollection for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4243
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4244
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4245
    ^ self readingFileDo:[:s | s isNil 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4246
                                ifTrue:[nil]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4247
                                ifFalse:[s contentsOfEntireFile]].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4248
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4249
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4250
     'Makefile' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4251
     'foobar' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4252
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4253
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4254
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4255
    "Modified: / 15.10.1998 / 11:42:05 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4256
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4257
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4258
readingFileDo:aBlock
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4259
    "create a read-stream on the receiver file, evaluate aBlock, passing that stream as arg,
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4260
     and return the blocks value. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4261
     If the file cannot be opened, the block is evaluated with a nil argument.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4262
     Ensures that the stream is closed."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4263
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4264
    |stream result|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4265
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4266
    stream := self readStream.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4267
    [
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4268
        result := aBlock value:stream
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4269
    ] ensure:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4270
        stream notNil ifTrue:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4271
            stream close
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4272
        ]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4273
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4274
    ^ result
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4275
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4276
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4277
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4278
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4279
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4280
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4281
     rslt := 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4282
        '/etc/passwd' asFilename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4283
            readingFileDo:[:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4284
                s nextLine
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4285
            ]. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4286
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4287
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4288
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4289
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4290
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4291
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4292
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4293
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4294
     rslt :=
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4295
        '/etc/passwd' asFilename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4296
            readingFileDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4297
                [:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4298
                    |shells|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4299
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4300
                    shells := Bag new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4301
                    s linesDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4302
                        [:line |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4303
                            |parts|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4304
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4305
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4306
                            shells add:(parts seventh).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4307
                        ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4308
                    shells contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4309
                ].           
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4310
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4311
    "
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4312
!
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4313
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4314
readingLinesDo:aBlock
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4315
    "create a read-stream on the receiver file,
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4316
     evaluate aBlock for each line read from the stream.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4317
     If the file cannot be opened, an error is raised.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4318
     Ensures that the stream is closed."
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4319
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4320
    self readingFileDo:[:stream |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4321
        stream isNil ifTrue:[
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4322
            ^ OsInaccessibleError raiseRequestWith:self errorString:'cannot open file'
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4323
        ].
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4324
        stream linesDo:aBlock
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4325
    ].
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4326
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4327
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4328
    '/etc/passwd' asFilename 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4329
        readingLinesDo:[:eachLine |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4330
            Transcript showCR:eachLine.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4331
        ]. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4332
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4333
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4334
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4335
    '/etc/xxxxx' asFilename 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4336
        readingLinesDo:[:eachLine |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4337
            Transcript showCR:eachLine.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4338
        ]. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4339
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4340
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4341
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4342
!Filename methodsFor:'special accessing'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4343
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4344
nameWithSpecialExpansions:aString
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4345
    "return the nameString, expanding any OS specific
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4346
     macros. This should be redefined for OS's where such macros
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4347
     are common.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4348
     On unix, a ~/ prefix is expanded to the users home dir (as in csh)"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4349
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4350
    ^ aString
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4351
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4352
    "Modified: / 21.7.1998 / 10:43:20 / cg"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4353
    "Created: / 21.7.1998 / 10:45:58 / cg"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4354
!
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4355
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4356
osName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4357
    "special - return the OS's name for the receiver."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4358
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4359
    self isDirectory ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4360
	^ self osNameForDirectory
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4361
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4362
    ^ self osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4363
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4364
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4365
osNameForAccess
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4366
    "internal - return the OS's name for the receiver to
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4367
     access its fileInfo.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4368
     This may be redefined for systems, where a special suffix must be
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4369
     added in order to access directories (or others) as a file.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4370
     (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
  4371
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4372
    ^ nameString
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4373
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4374
    "Modified: / 21.7.1998 / 10:40:40 / cg"
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4375
!
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4376
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4377
osNameForDirectory
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4378
    "internal - return the OS's name for the receiver to
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4379
     access it as a directory."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4380
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4381
    ^ nameString
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4382
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4383
    "Modified: / 12.8.1998 / 14:44:32 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4384
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4385
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4386
osNameForDirectoryContents
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4387
    "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
  4388
     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
  4389
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4390
    ^ self osNameForDirectory
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4391
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4392
    "Created: / 3.8.1998 / 21:36:06 / cg"
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4393
    "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
  4394
!
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4395
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4396
osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4397
    "internal - return the OS's name for the receiver to
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4398
     access it as a file."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4399
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4400
    ^ nameString
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4401
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4402
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4403
!Filename methodsFor:'suffixes'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4404
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4405
hasSuffix:aSuffixString
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4406
    "return true if my suffix is the same as aString.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4407
     This cares for systems, where case is ignored in filenames"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4408
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4409
    |mySuffix|
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4410
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4411
    mySuffix := self suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4412
    self class isCaseSensitive ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  4413
	^ mySuffix = aSuffixString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4414
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4415
    ^ mySuffix asLowercase = aSuffixString asLowercase
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4416
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4417
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4418
     'abc.st' asFilename hasSuffix:'st'   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4419
     'abc.ST' asFilename hasSuffix:'st'   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4420
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4421
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4422
    "Modified: 7.9.1997 / 02:55:25 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4423
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4424
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4425
prefixAndSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4426
    "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
  4427
     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
  4428
     the prefix everything before, except for the period.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4429
     The directory name part is stripped off (i.e. the returned prefix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4430
     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
  4431
     (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
  4432
     For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4433
     See also: #withoutSuffix and #withSuffix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4434
     Notice: 
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4435
	there is currently no known system which uses other than
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4436
	the period character as suffixCharacter."
1049
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
    |nm idx|
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4439
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4440
    nm := self baseName.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4441
    idx := nm lastIndexOf:(self class suffixSeparator).
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4442
    idx == 0 ifTrue:[
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4443
	^ Array with:nm with:''
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4444
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4445
    ^ Array 
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4446
	with:(nm copyTo:idx-1)
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4447
	with:(nm copyFrom:idx+1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4448
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
     'abc.st' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4451
     'abc' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4452
     'a.b.c' asFilename prefixAndSuffix 
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4453
     '/foo/bar.c/baz.c' asFilename prefixAndSuffix 
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4454
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4455
     |parts| 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4456
     parts := 'Object.st' asFilename prefixAndSuffix.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4457
     ((parts at:1) , '.o') asFilename   
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4458
    "
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
    "Modified: 7.9.1995 / 11:15:42 / claus"
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4461
    "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
  4462
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4463
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4464
suffix
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4465
    "return my suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4466
     The suffix is the namepart after the final period character,
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4467
     or the empty string, if the name does not contain a period."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4468
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4469
    ^ self prefixAndSuffix at:2
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4470
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4471
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4472
     'abc.st' asFilename suffix   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4473
     'abc' asFilename suffix      
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4474
     'a.b.c' asFilename suffix    
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4475
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4476
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4477
    "Modified: 7.9.1995 / 11:09:03 / claus"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4478
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4479
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4480
withSuffix:aSuffix
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4481
    "return a new filename for the receivers name with a different suffix.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4482
     If the name already has a suffix, the new suffix replaces it;
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4483
     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
  4484
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4485
    aSuffix isNil ifTrue:[
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4486
        ^ self withoutSuffix
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4487
    ].
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4488
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4489
    ^ self class named:
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4490
        (self withoutSuffix name 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4491
         , self class suffixSeparator asString 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4492
         , aSuffix asString)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4493
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4494
    "
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4495
     'abc.st' asFilename withSuffix:nil         
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4496
     'abc.st' asFilename withSuffix:'o'         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4497
     'abc' asFilename withSuffix:'o'             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4498
     'a.b.c' asFilename withSuffix:'o'            
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4499
     '/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
  4500
     '/foo/bar/baz.c' asFilename withSuffix:'st'   
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4501
     '/foo/bar.c/baz.c' asFilename withSuffix:'st'   
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4502
     '/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
  4503
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4504
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4505
    "Modified: 7.9.1995 / 11:15:42 / claus"
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4506
    "Modified: 11.12.1996 / 16:01:02 / cg"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4507
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4508
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4509
withoutSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4510
    "return a new filename for the receivers name without the suffix.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4511
     If the name has no suffix, the receiver is returned."
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4512
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4513
    |nm idx idxFromEnd|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4514
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4515
    nm := self baseName.
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4516
    idx := nm lastIndexOf:(self class suffixSeparator).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4517
    (idx == 0) ifTrue:[^ self].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4518
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4519
    idxFromEnd := nm size - idx.
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4520
    idx := nameString size - idxFromEnd.
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4521
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4522
    ^ self class named:(nameString copyTo:(idx - 1))
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4523
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4524
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4525
     'abc.st' asFilename withoutSuffix         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4526
     '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
  4527
     '/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
  4528
     '/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
  4529
     './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
  4530
     './abc.d' asFilename withoutSuffix            
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4531
     'a.b.c' asFilename withoutSuffix           
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4532
     '/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
  4533
     '/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
  4534
     '/foo/bar.x/baz' asFilename withoutSuffix     
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4535
     '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix   
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4536
     '/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
  4537
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4538
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4539
    "Modified: 7.9.1995 / 11:15:42 / claus"
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4540
    "Modified: 3.7.1996 / 10:49:58 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4541
! !
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4542
5597
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4543
!Filename methodsFor:'testing'!
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4544
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4545
isFilename
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4546
    "return true, if the receiver is some kind of filename;
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4547
     false is returned here - the method is redefined from Object."
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4548
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4549
    ^true
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4550
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4551
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4552
! !
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4553
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4554
!Filename class methodsFor:'documentation'!
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  4555
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  4556
version
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
  4557
    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.232 2002-11-26 10:06:34 cg Exp $'
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  4558
! !
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4559
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4560
Filename initialize!