Filename.st
author Claus Gittinger <cg@exept.de>
Mon, 12 Nov 2001 19:22:34 +0100
changeset 6178 361b2efd99b1
parent 6139 1b86d43f8eb7
child 6223 e0ea936d07c0
permissions -rw-r--r--
class remove change
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:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
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:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
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
    |sep s|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   358
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   359
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   360
	^ ConcreteClass fromComponents:aCollectionOfDirectoryNames
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   361
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   362
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   363
    "/ fallBack - works on Unix & MSDOS
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   364
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   365
    sep := self separator asString.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   366
    s := ''.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   367
    aCollectionOfDirectoryNames keysAndValuesDo:[:index :component |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   368
	index == 1 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   369
	    (component ~= sep 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   370
	    or:[aCollectionOfDirectoryNames size == 1]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   371
		s := s , component
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   372
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   373
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   374
	    s := s , sep , component
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   375
	].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   376
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   377
    ^ self named:s
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   378
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   379
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   380
     Filename fromComponents:#('/' 'foo' 'bar' 'baz')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   381
     Filename fromComponents:#('foo' 'bar' 'baz')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   382
     Filename fromComponents:#('/')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   383
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   384
     Filename fromComponents:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   385
	 (Filename components:('.' asFilename pathName))
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   386
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   387
     Filename fromComponents:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   388
	 (Filename components:('.' asFilename name)) 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   389
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   390
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   391
    "Modified: 8.9.1997 / 00:23:16 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   392
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   393
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   394
fromUser
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   395
    "show a box to enter a filename. 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   396
     Return a filename instance or nil (if cancel was pressed)."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   397
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   398
    |name|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   399
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   400
    name := Dialog 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   401
	requestFileName:'filename:' 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   402
	default:nil
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   403
	fromDirectory:(FileSelectionBox lastFileSelectionDirectory).
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   404
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   405
    name size > 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   406
	^ self named:name
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   407
    ].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   408
    ^ nil
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   409
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   410
    "
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   411
     Filename fromUser 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   412
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   413
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   414
    "Modified: 19.4.1996 / 13:57:44 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   415
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   416
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   417
homeDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   418
    "return your homeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   419
     Some OperatingSystems do not support this - on those, the defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   420
     (which is the currentDirectory) is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   421
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   422
    |s|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   423
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   424
    s := OperatingSystem getHomeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   425
    s isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   426
	^ self defaultDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   427
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   428
    ^ self named:s
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   429
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   430
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   431
     Filename homeDirectory        
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
    "Modified: 8.9.1997 / 00:25:23 / cg"
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
named:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   438
    "return a filename for a directory named aString.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   439
     This is the same as 'aString asFilename'."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   440
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   441
    |cls|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   442
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   443
    cls := self.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   444
    cls == Filename ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   445
	cls := self concreteClass
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   446
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   447
    ^ (cls basicNew) setName:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   448
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   449
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   450
     Filename named:'/tmp/fooBar'
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
    "Modified: 7.9.1997 / 23:30:06 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   454
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   455
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   456
newTemporary
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   457
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   458
     The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   459
     unix process id, and nn is a unique number, incremented with every
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   460
     call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   461
     If any of the environment variables ST_TMPDIR or TMPDIR is set, 
4757
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   462
     its value defines the temp directory.
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   463
     Notice, that no file is created by this - only a unique name
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   464
     is generated."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   465
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   466
    ^ self newTemporaryIn:(self tempDirectory) pathName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   467
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   468
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   469
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   470
     Filename newTemporary     
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   471
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   472
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   473
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   474
    "Modified: 7.3.1996 / 14:51:33 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   475
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   476
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   477
newTemporaryIn:aDirectoryPrefix
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   478
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   479
     The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn',
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   480
     where xx is our unix process id, and nn is a unique number, incremented 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   481
     with every call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   482
     Notice: only a unique filename object is created and returned - no physical
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   483
     file is created by this method (i.e. you have to send #writeStream or
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   484
     whatever to it in order to really create something).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   485
     See also: #newTemporary which looks for a good temp directory."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   486
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   487
    |pid nameString fn|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   488
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   489
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   490
	^ ConcreteClass newTemporaryIn:aDirectoryPrefix
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   491
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   492
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   493
    "/ care for existing leftOver tempFiles
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   494
    "/ from a previous boot of the OS
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   495
    "/ (i.e. my pid could be the same as when executed
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   496
    "/  the last time before system reboot ...)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   497
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   498
    [fn isNil or:[fn exists]] whileTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   499
	"/ although the above allows things to be redefined in concrete classes,
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   500
	"/ the following should work on all systems ...
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   501
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   502
	NextTempFilenameIndex isNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   503
	    NextTempFilenameIndex := 1.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   504
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   505
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   506
	pid := OperatingSystem getProcessId printString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   507
	nameString := (self tempFileNameTemplate) bindWith:pid with:(NextTempFilenameIndex printString).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   508
	NextTempFilenameIndex := NextTempFilenameIndex + 1.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   509
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   510
	(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   511
	    fn := aDirectoryPrefix asFilename construct:nameString
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   512
	] ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   513
	    fn := self named:nameString
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   514
	]
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   515
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   516
    ^ fn
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   517
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   518
    "temp files in '/tmp':
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   519
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   520
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   521
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   522
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   523
    "temp files somewhere 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   524
     (not recommended - use above since it can be controlled via shell variables):
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   525
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   526
     UnixFilename newTemporaryIn:'/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   527
     UnixFilename newTemporaryIn:'/tmp'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   528
     UnixFilename newTemporaryIn:'/usr/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   529
     UnixFilename newTemporaryIn:'/'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   530
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   531
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   532
    "a local temp file:
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   533
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   534
     Filename newTemporaryIn:''         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   535
     Filename newTemporaryIn:nil         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   536
     Filename newTemporaryIn:'.'         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   537
     Filename newTemporaryIn:('source' asFilename) 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   538
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   539
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   540
    "Modified: / 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   541
    "Modified: / 11.8.1998 / 22:51:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   542
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   543
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   544
nullDevice
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   545
    "return the filename of the nullDevice (if available).
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   546
     returns nil, if the OperatingSystem does not support this."
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   547
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   548
    |s|
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   549
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   550
    s := OperatingSystem getNullDevice.
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   551
    s isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   552
	^ nil
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   553
    ].
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   554
    ^ self named:s
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   555
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   556
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   557
     Filename nullDevice        
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   558
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   559
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   560
    "Created: / 19.5.1999 / 12:24:26 / cg"
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   561
!
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   562
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   563
rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   564
    "return a filename for the root directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   565
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   566
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   567
	^ ConcreteClass rootDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   568
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   569
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   570
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   571
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   572
    ^ self named:(self separator asString)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   573
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   574
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   575
     Filename rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   576
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   577
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   578
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   579
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   580
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   581
rootDirectoryOnVolume:aVolumeName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   582
    "return a filename for the root directory on some volume"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   583
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   584
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   585
	^ ConcreteClass rootDirectoryOnVolume:aVolumeName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   586
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   587
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   588
    "/ fallBack - works on Unix (not on MSDOS or VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   589
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   590
    ^ self rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   591
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   592
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   593
     Filename rootDirectoryOnVolume:'/phys/idefix'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   594
     Filename rootDirectoryOnVolume:'d:'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   595
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   596
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   597
    "Modified: / 5.10.1998 / 12:45:39 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   598
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   599
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   600
tempDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   601
    "return the temp directory as a filename.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   602
     If any of the environment variables STX_TMPDIR, ST_TMPDIR,
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   603
     TMPDIR or TEMPDIR is set, its value defines the name, 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   604
     otherwise, '/tmp' is used. (at least on unix ...).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   605
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   606
     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
   607
	     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
   608
	     TMPDIR environment variable to have her temp files somewhere else.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   609
	     (especially on SUNOS, the root partition is ALWAYS too small ..."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   610
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   611
    |tempDir|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   612
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   613
    #('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   614
	tempDir isNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   615
	    tempDir := OperatingSystem getEnvironment:envVar.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   616
	].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   617
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   618
    tempDir isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   619
	tempDir := self defaultTempDirectoryName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   620
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   621
    ^ self named:tempDir
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   622
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   623
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   624
     Filename tempDirectory           
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   625
     Filename tempDirectory pathName   
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   626
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   627
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   628
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   629
    "Created: 7.3.1996 / 14:51:18 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   630
    "Modified: 8.9.1997 / 00:08:11 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   631
! !
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   632
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   633
!Filename class methodsFor:'defaults'!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   634
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   635
concreteClass
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   636
    "ST-80 compatibility:
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   637
     in ST-80, different subclasses of Filename are used for different
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   638
     OperatingSystems; concreteClass is supposed to return an appropriate class.
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   639
     Since in ST/X, there is (currently) only one Filename class, return it here."
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   640
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   641
    ^ ConcreteClass ? self
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   642
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   643
    "Created: 14.2.1997 / 16:36:13 / cg"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   644
    "Modified: 7.9.1997 / 23:29:20 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   645
!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   646
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   647
defaultClass
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   648
    "ST-80 compatibility:
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   649
     in ST-80, different subclasses of Filename are used for different
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   650
     OperatingSystems; defaultClass is supposed to return an appropriate class.
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   651
     Since in ST/X, there is (currently) only one Filename class, return it here."
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   652
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   653
    ^ ConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   654
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   655
    "Modified: 8.9.1997 / 00:36:01 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   656
! !
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   657
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   658
!Filename class methodsFor:'misc'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   659
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   660
canonicalize:aPathString
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   661
    "convert the argument, aPathString to a good format.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   662
     This should eliminate useless directory components (i.e. '././')
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   663
     and useless tree walks (i.e. '../foo/..')."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   664
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   665
    ^ aPathString
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   666
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   667
    "Created: / 13.9.1997 / 10:50:01 / cg"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   668
    "Modified: / 1.11.1997 / 12:44:57 / cg"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   669
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   670
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   671
filterSeps:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   672
    "ST80 compatibility:
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   673
     filter out (invalid) separators in aFilenameString.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   674
     We recommend using #makeLegalFilename"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   675
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   676
    ^ aFilenameString copyReplaceAll:(Character space) with:$_.
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   677
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   678
    "Created: / 1.11.1997 / 12:39:50 / cg"
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   679
    "Modified: / 18.7.1998 / 22:53:24 / cg"
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   680
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   681
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   682
suggest:aFilenameString 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   683
    "return a fileNamestring based on the argument, 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   684
     which is legal on the current platform."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   685
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   686
    ^ self canonicalize:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   687
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   688
    "Created: / 1.11.1997 / 12:42:39 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   689
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   690
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
   691
!Filename class methodsFor:'queries'!
2
claus
parents: 1
diff changeset
   692
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   693
components:aString
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   694
    "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
   695
     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
   696
     the final component.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   697
     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
   698
     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
   699
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   700
    |sep f vol rest components|
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   701
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   702
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   703
	^ ConcreteClass components:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   704
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   705
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   706
    "/ the following works on Unix & MSDOS (but not on openVMS)
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   707
    "/ However, MSDOS drive-letters and network drives are
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   708
    "/ not correctly handled here.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   709
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   710
    sep := self separator.
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   711
    f := aString asFilename.
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   712
    vol := f volume.
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   713
    vol size ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   714
	rest := f localPathName.
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   715
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   716
	rest := aString
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   717
    ].
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   718
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   719
    components := rest asCollectionOfSubstringsSeparatedBy:sep.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   720
    components first isEmpty ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   721
	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
   722
    ].
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   723
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   724
    "/ prepend volume to first component (the root directory)
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   725
    vol size ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   726
	components at:1 put:(vol , (components at:1)).
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   727
    ].
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   728
    components last isEmpty ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   729
	^ components copyWithoutLast:1
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   730
    ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   731
    ^ components
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   732
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   733
    "
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   734
     Filename components:'/foo/bar/baz'      
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   735
     Filename components:'/'     
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   736
     Filename components:'foo/bar/baz'  
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   737
     Filename components:'foo/bar'  
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   738
     Filename components:'foo'     
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   739
     Filename components:'/foo'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   740
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   741
     Filename components:'\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   742
     Filename components:'\foo'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   743
     Filename components:'\foo\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   744
     Filename components:'\foo\bar'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   745
     Filename components:'\foo\bar\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   746
     Filename components:'c:'        
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   747
     Filename components:'c:\'       
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   748
     Filename components:'c:\foo'      
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   749
     Filename components:'c:\foo\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   750
     Filename components:'c:\foo\bar'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   751
     Filename components:'c:\foo\bar\'  
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   752
     Filename components:'\\idefix'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   753
     Filename components:'\\idefix\home'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   754
     Filename components:'\\idefix\home\bar'    
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   755
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   756
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   757
    "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
   758
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   759
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   760
directorySuffix
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   761
    "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
   762
     The default is nil here, redefined for VMS"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   763
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   764
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   765
	^ ConcreteClass directorySuffix
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   766
    ].
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   767
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   768
    ^ nil
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   769
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   770
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   771
errorReporter
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   772
    "who knows the signals to report errors?"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   773
        
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   774
    ^ FileStream
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   775
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   776
    "Created: 2.7.1996 / 12:30:25 / stefan"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   777
!
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   778
440
claus
parents: 422
diff changeset
   779
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock
claus
parents: 422
diff changeset
   780
    "perform filename completion on aString in some directory;
claus
parents: 422
diff changeset
   781
     return the longest matching filename prefix as a string.
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   782
     The boolean directoriesOnly and filesOnly control respectively,
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   783
     if only directories or only regular files are to be considered for completion.
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   784
     If multiple files match, the exception block aBlock is evaluated with a 
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   785
     filename representing the directory (where the match was done) as argument.
440
claus
parents: 422
diff changeset
   786
     (this may be different from the inDirectory argument, if aString is absolute
claus
parents: 422
diff changeset
   787
      or starts with ../)"
claus
parents: 422
diff changeset
   788
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   789
    |s f matchSet nMatch name dir isAbsolute sep|
440
claus
parents: 422
diff changeset
   790
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   791
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   792
	^ ConcreteClass 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   793
	    filenameCompletionFor:aString 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   794
	    directory:inDirectory       
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   795
	    directoriesOnly:directoriesOnly 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   796
	    filesOnly:filesOnly 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   797
	    ifMultiple:aBlock
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   798
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   799
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   800
    aString size == 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   801
	aBlock value:(self named:'.').
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   802
	^ ''
440
claus
parents: 422
diff changeset
   803
    ].
claus
parents: 422
diff changeset
   804
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   805
    sep := self separator.
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   806
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   807
    "/ 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
   808
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   809
    f := self named:aString.
3854
a13d0d489365 care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   810
    isAbsolute := f isAbsolute.
440
claus
parents: 422
diff changeset
   811
claus
parents: 422
diff changeset
   812
    matchSet := f filenameCompletionIn:inDirectory.
claus
parents: 422
diff changeset
   813
    dir := f directory.
claus
parents: 422
diff changeset
   814
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   815
    matchSet := matchSet select:[:aFilename |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   816
	|f isDir|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   817
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   818
	isAbsolute ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   819
	    f := aFilename asFilename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   820
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   821
	    f := (dir construct:aFilename). 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   822
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   823
	isDir := f isDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   824
	directoriesOnly ifTrue:[    
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   825
	    isDir
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   826
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   827
	    isDir not
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   828
	]
440
claus
parents: 422
diff changeset
   829
    ].
claus
parents: 422
diff changeset
   830
claus
parents: 422
diff changeset
   831
    (nMatch := matchSet size) ~~ 1 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   832
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   833
	 more than one possible completion -
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   834
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   835
	aBlock value:f
440
claus
parents: 422
diff changeset
   836
    ].
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   837
440
claus
parents: 422
diff changeset
   838
    "
claus
parents: 422
diff changeset
   839
     even with more than one possible completion,
claus
parents: 422
diff changeset
   840
     f's name is now the common prefix
claus
parents: 422
diff changeset
   841
    "
claus
parents: 422
diff changeset
   842
    name := f asString.
4323
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   843
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   844
    nMatch <= 1 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   845
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   846
	 exactly one possible completion -
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   847
	"
3752
cbf9fa32eb28 fixed completion.
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
   848
"/        f := dir construct:matchSet first.
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   849
	false "directoriesOnly" ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   850
	    (f exists and:[f isDirectory]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   851
		(name endsWith:sep) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   852
		    name := name , sep asString
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   853
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   854
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   855
	]
440
claus
parents: 422
diff changeset
   856
    ].
claus
parents: 422
diff changeset
   857
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   858
    s := name.
440
claus
parents: 422
diff changeset
   859
claus
parents: 422
diff changeset
   860
    "/ special: if there was no change, and the string represented
claus
parents: 422
diff changeset
   861
    "/ 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
   862
    ((nMatch == 1) or:[s = aString]) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   863
	(s endsWith:sep) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   864
	    (self named:s) isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   865
		^ s , sep asString
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   866
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   867
	].
440
claus
parents: 422
diff changeset
   868
    ].
claus
parents: 422
diff changeset
   869
claus
parents: 422
diff changeset
   870
    ^ s
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   871
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   872
    "Modified: / 30.4.1999 / 09:40:13 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   873
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   874
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   875
filesMatching:aPattern
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   876
    "return a collection of strings, representing the names
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   877
     of files matching aPattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   878
     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
   879
     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
   880
     The returned strings are the expanded names, in the same form
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
   881
     as given in pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
   882
     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
   883
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   884
    |basePattern dir d files|
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   885
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   886
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   887
	^ ConcreteClass filesMatching:aPattern
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   888
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   889
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   890
    "/ the following works on Unix & MSDOS (but not on openVMS)
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   891
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   892
    dir := aPattern asFilename directoryName.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   893
    basePattern := aPattern asFilename baseName.
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   894
    d := dir asFilename.
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
   895
    files := dir asFilename filesMatchingWithoutDotDirs:basePattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   896
    dir = '.' ifTrue:[^ files].
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   897
    ^ files collect:[:base | d constructString:base].
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   898
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   899
    "
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   900
     Filename filesMatching:'*'   
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   901
     Filename filesMatching:'/*'
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
   902
     Filename filesMatching:'/usr/local/*'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   903
    "
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   904
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   905
    "Modified: 8.9.1997 / 00:32:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   906
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   907
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   908
isBadCharacter:aCharacter
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   909
    "return true, if aCharacter is unallowed in a filename."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   910
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   911
    |ascii|
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   912
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   913
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   914
	^ ConcreteClass isBadCharacter:aCharacter
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   915
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   916
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   917
    ascii := aCharacter asciiValue.
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   918
    ascii < 32 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   919
	^ true  "/ a control character
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   920
    ].
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   921
    ascii == 16rFF ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   922
	^ true  "/ delete character
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   923
    ].
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   924
    ^ false
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   925
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   926
    "Modified: 8.9.1997 / 00:32:59 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   927
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   928
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   929
isCaseSensitive
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   930
    "return true, if filenames are case sensitive.
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   931
     We ask the OS about this, to be independent here."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   932
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   933
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   934
	^ ConcreteClass isCaseSensitive
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   935
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   936
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   937
    ^ OperatingSystem caseSensitiveFilenames
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   938
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   939
    "Modified: 8.9.1997 / 00:33:32 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   940
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
   941
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   942
localNameStringFrom:aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   943
    "ST-80 compatibility.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   944
     what does this do ? (used in FileNavigator-goody).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   945
     GUESS: 
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   946
	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
   947
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   948
    |sep|
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   949
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   950
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   951
	^ ConcreteClass localNameStringFrom:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   952
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   953
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   954
    sep := self separator asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   955
    (aString startsWith:sep) ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   956
	^ aString copyFrom:sep size + 1
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   957
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   958
    ^ aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   959
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   960
    "Modified: 7.9.1995 / 10:44:56 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   961
    "Modified: 8.9.1997 / 00:33:51 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   962
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
   963
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   964
maxComponentLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   965
    "return the maximum number of characters a filename component may
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   966
     be in size. This depends on the OperatingSystem."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   967
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   968
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   969
	^ ConcreteClass maxComponentLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   970
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   971
    ^ OperatingSystem maxFileNameLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   972
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   973
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   974
maxLength
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   975
    "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
   976
     This depends on the OperatingSystem."
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   977
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   978
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   979
	^ ConcreteClass maxLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   980
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
   981
    ^ OperatingSystem maxPathLength
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   982
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   983
    "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
   984
    "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
   985
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   986
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   987
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   988
    "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
   989
     The default is nil here"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   990
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   991
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   992
	^ ConcreteClass nullFilename
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   993
    ].
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   994
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   995
    ^ nil
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   996
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   997
    "Created: / 12.1.1998 / 12:15:30 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   998
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
   999
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1000
parentDirectoryName 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1001
    "return the name used for the parent directory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1002
     This is '..' for unix and dos-like systems. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1003
     (there may be more in the future."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1004
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1005
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1006
	^ ConcreteClass parentDirectoryName
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1007
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1008
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1009
    ^ OperatingSystem parentDirectoryName
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1010
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1011
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1012
     Filename parentDirectoryName  
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
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1015
    "Modified: 8.9.1997 / 00:34:39 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1016
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1017
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1018
separator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1019
    "return the file/directory separator.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1020
     This is to be redefined in concrete classes;
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1021
     the following default usually leads to a flat view of
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1022
     the fileSystem (huh - BS2000 ?)"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1023
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1024
     (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1025
	^ ConcreteClass separator
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1026
     ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1027
     ^ $_
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1028
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1029
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1030
      Filename separator  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1031
     "
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1032
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1033
    "Modified: 8.9.1997 / 00:20:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1034
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1035
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1036
suffixSeparator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1037
    "return the filename suffix separator.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1038
     Usually, this is $. for unix-like and msdos systems 
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1039
     (there is currently no known system, where this differs)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1040
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1041
     ^ $.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1042
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1043
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1044
      Filename suffixSeparator  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1045
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1046
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1047
    "Modified: 7.9.1995 / 11:10:43 / claus"
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1048
    "Modified: 30.4.1996 / 12:14:25 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1049
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1050
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1051
tempFileNameTemplate
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1052
    "return a template for temporary files.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1053
     This is expanded with the current processID and a sequenceNumber
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1054
     to generate a unique filename."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1055
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1056
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1057
	^ ConcreteClass tempFileNameTemplate
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1058
    ].
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
    ^ 'stxtmp_%1_%2'
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1061
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1062
    "Created: 8.9.1997 / 00:01:46 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1063
    "Modified: 8.9.1997 / 00:35:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1064
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1065
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1066
volumes
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1067
    "ST-80 compatibility.
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1068
     GUESS: does it return the available drives on MSDOS systems ?
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1069
     Q: what does this do on Unix systems ? (used in FileNavigator-goody)."
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1070
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1071
    (self ~~ ConcreteClass) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1072
	^ ConcreteClass volumes
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1073
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1074
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1075
    ^ OperatingSystem getDriveList
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1076
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1077
    "Modified: 7.9.1995 / 10:45:25 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1078
    "Modified: 8.9.1997 / 00:35:19 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1079
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1080
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1081
!Filename methodsFor:'Compatibility - VW5.4'!
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1082
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1083
asLogicalFileSpecification
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1084
    ^ self
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1085
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1086
    "Created: / 30.10.2001 / 17:31:10 / cg"
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1087
! !
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1088
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1089
!Filename methodsFor:'comparing'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1090
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1091
= aFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1092
    "return true, if the argument represents the same filename"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1093
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1094
    |str|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1095
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1096
    self species == aFilename species ifTrue:[
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1097
	str := aFilename asString.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1098
	self class isCaseSensitive ifTrue:[
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1099
	    ^ nameString = str
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1100
	].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1101
	^ nameString sameAs:str
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1102
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1103
    ^ false
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1104
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1105
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1106
contentsIsPrefixOf:aFilename
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1107
    "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
  1108
     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
  1109
     This compares the files actual contents; not the filenames."
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1110
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1111
    |f2 s1 s2 buffer1 buffer2 rslt n|
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1112
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1113
    f2 := aFilename asFilename.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1114
    self fileSize > f2 fileSize ifTrue:[^ false].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1115
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1116
    buffer1 := ByteArray new:8192.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1117
    buffer2 := ByteArray new:8192.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1118
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1119
    s1 := self readStream.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1120
    s1 isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1121
	^ self error:('cannot open %1 for reading' bindWith:nameString)
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1122
    ].
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1123
    s2 := f2 readStream.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1124
    s2 isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1125
	^ self error:('cannot open %1 for reading' bindWith:aFilename asFilename name)
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1126
    ].
3869
6d7dca488a41 read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1127
    s1 binary.
6d7dca488a41 read binary, in #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  1128
    s2 binary.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1129
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1130
    [s1 atEnd] whileFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1131
	n := s1 nextBytes:8192 into:buffer1 startingAt:1.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1132
	n == 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1133
	    "/ receiver shorter.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1134
	    s1 close. s2 close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1135
	    ^ true
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1136
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1137
	(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1138
	    "/ aFilename shorter
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1139
	    s1 close. s2 close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1140
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1141
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1142
	buffer1 ~= buffer2 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1143
	    s1 close. s2 close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1144
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1145
	]
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1146
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1147
    "/ receiver shorter or same size.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1148
    s1 close. s2 close.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1149
    ^ true
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1150
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1151
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1152
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1153
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1154
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1155
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1156
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1157
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1158
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1159
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1160
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1161
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1162
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1163
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1164
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1165
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1166
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1167
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1168
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1169
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1170
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1171
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1172
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1173
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1174
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1175
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1176
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1177
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1178
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1179
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1180
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1181
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1182
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1183
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1184
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1185
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1186
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1187
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1188
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1189
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1190
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1191
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1192
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1193
!
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1194
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1195
contentsStartsWithContentsOf:aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1196
    "return true if the contents of the file represented by aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1197
     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
  1198
     This compares the files actual contents; not the filenames."
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1199
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1200
    ^ aFilename asFilename contentsIsPrefixOf:self
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1201
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1202
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1203
     |s|
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1204
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1205
     s := 'testFile1' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1206
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1207
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1208
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1209
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1210
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1211
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1212
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1213
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1214
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1215
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1216
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1217
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1218
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1219
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1220
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1221
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1222
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1223
     s nextPutAll:'44444'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1224
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1225
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1226
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1227
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1228
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1229
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1230
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1231
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1232
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1233
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1234
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1235
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1236
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1237
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1238
     s nextPutAll:'33334'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1239
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1240
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1241
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1242
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1243
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1244
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1245
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1246
hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1247
    "return an integer useful as a hash-key"
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1248
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1249
    ^ nameString hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1250
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1251
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1252
sameContentsAs:aFilename
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1253
    "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
  1254
     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
  1255
     This compares the files actual contents; not the filenames."
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1256
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1257
    |f2|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1258
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1259
    f2 := aFilename asFilename.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1260
    f2 fileSize = self fileSize ifFalse:[^ false].
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1261
    ^ self contentsIsPrefixOf:f2.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1262
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1263
    "
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1264
     'Make.proto' asFilename sameContentsAs:'Makefile'  
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1265
    "
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1266
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1267
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1268
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1269
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1270
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1271
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1272
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1273
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1274
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1275
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1276
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1277
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1278
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1279
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1280
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1281
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1282
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifFalse:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1283
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1284
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1285
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1286
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1287
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1288
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1289
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1290
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1291
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1292
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1293
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1294
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1295
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1296
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1297
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1298
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1299
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1300
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1301
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1302
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1303
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1304
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1305
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1306
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1307
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1308
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1309
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1310
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1311
!Filename methodsFor:'converting'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1312
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1313
asAbsoluteFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1314
    "return the receiver converted to a filename with
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1315
     an absolute pathname."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1316
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  1317
    ^ self class named:self pathName
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1318
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1319
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1320
asFilename
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1321
    "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
  1322
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1323
    "Thats pretty easy here :-)"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1324
    ^ self
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1325
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1326
    "Modified: 12.11.1996 / 12:40:03 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1327
!
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
asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1330
    "return the receiver converted to a string"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1331
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1332
    ^ nameString
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
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1335
components
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1336
    "return the receivers filename components - that is the name of each directory
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1337
     along the pathName (that DOES include the root directory)"
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1338
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1339
    ^ self class components:self name
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1340
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1341
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1342
     '.' asFilename asAbsoluteFilename components 
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1343
     'Makefile' asFilename asAbsoluteFilename components     
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1344
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1345
!
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1346
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1347
makeLegalFilename 
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1348
    "convert the receivers name to be a legal filename.
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1349
     This removes/replaces invalid characters and/or compresses
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1350
     the name as required by the OS.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1351
     The implementation may change in the future to be more
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1352
     OS specific."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1353
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1354
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1355
     actually, in Unix spaces are allowed - but it makes life
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1356
     so hard; therefore, replace them by underscores ...
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1357
    "
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1358
    (nameString includes:Character space) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1359
	nameString := nameString copyReplaceAll:(Character space) with:$_.
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1360
    ].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1361
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1362
     need more - especially on SYS5.3 type systems, 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1363
     we may want to contract the fileName to 14 characters.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1364
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1365
    ^ self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1366
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1367
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1368
     'hello world' asFilename makeLegalFilename 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1369
    "
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1370
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1371
    "Modified: / 20.7.1998 / 13:16:51 / cg"
2707
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1372
!
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1373
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1374
withEncoding:encodingSymbol
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1375
    "dummy for now - for ST80 compatibility"
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1376
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1377
    ^ self
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1378
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1379
    "Created: 20.6.1997 / 17:01:28 / cg"
2
claus
parents: 1
diff changeset
  1380
! !
claus
parents: 1
diff changeset
  1381
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1382
!Filename methodsFor:'enumerating-contents'!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1383
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1384
allDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1385
    "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
  1386
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1387
     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
  1388
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1389
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1390
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1391
     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
  1392
     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
  1393
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1394
    self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1395
	|eachFileOrDirectory|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1396
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1397
	eachFileOrDirectory := self construct:eachFileOrDirectoryName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1398
	eachFileOrDirectory isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1399
	    aBlock value:eachFileOrDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1400
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1401
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1402
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1403
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1404
     '.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1405
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1406
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1407
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1408
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1409
directoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1410
    "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
  1411
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1412
     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
  1413
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1414
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1415
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1416
     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
  1417
     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
  1418
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1419
    self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1420
	eachFileOrDirectory isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1421
	    aBlock value:eachFileOrDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1422
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1423
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1424
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1425
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1426
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1427
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1428
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1429
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1430
directoryContentsAsFilenamesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1431
    "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
  1432
     The block is invoked with a filename-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1433
     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
  1434
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1435
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1436
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1437
     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
  1438
     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
  1439
     Notice: this enumerates fileName objects; see also
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1440
     #directoryContentsDo:, which enumerates strings."
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1441
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1442
    self directoryContentsAsFilenames do:aBlock.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1443
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1444
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1445
     '.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1446
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1447
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1448
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1449
    "Modified: / 23.12.1999 / 20:56:35 / cg"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1450
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1451
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1452
recursiveDirectoryContentsDo:aBlock 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1453
    "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
  1454
     The block is invoked with a string-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1455
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1456
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1457
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1458
     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
  1459
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1460
    self recursiveDirectoryContentsDo:aBlock directoryPrefix:''
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1461
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1462
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1463
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1464
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1465
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1466
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1467
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1468
    "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
  1469
     The block is invoked with a string-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1470
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1471
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1472
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1473
     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
  1474
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1475
    |fileNames dirNames p|
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1476
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1477
    fileNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1478
    dirNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1479
    self directoryContentsDo:[:f | |t|
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1480
	t := self construct:f.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1481
	t isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1482
	    t isSymbolicLink ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1483
		dirNames add:f
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1484
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1485
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1486
	    fileNames add:f
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1487
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1488
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1489
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1490
    aPrefix size > 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1491
	p := aPrefix , self separator asString
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1492
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1493
	p := ''
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1494
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1495
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1496
    fileNames do:[:aFile | aBlock value:(p , aFile)].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1497
    dirNames do:[:dN |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1498
	aBlock value:(p , dN).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1499
	(self construct:dN)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1500
	    recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN)
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1501
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1502
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1503
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1504
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1505
     '/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1506
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1507
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1508
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1509
withAllDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1510
    "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
  1511
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1512
     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
  1513
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1514
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1515
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1516
     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
  1517
     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
  1518
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1519
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1520
	aBlock value:self.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1521
	self allDirectoriesDo:aBlock
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1522
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1523
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1524
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1525
     '.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1526
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1527
! !
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1528
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1529
!Filename methodsFor:'error handling'!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1530
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1531
accessDeniedError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1532
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1533
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1534
    "report an error that access to some file was denied"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1535
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1536
    |errNo errString|
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1537
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1538
    errNo := OperatingSystem lastErrorNumber.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1539
    errString := OperatingSystem lastErrorString.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1540
    errString size == 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1541
	errString := ''.
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1542
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1543
	errString := ' (' , errString , ')'
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1544
    ].
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1545
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1546
    ^ OperatingSystem accessDeniedErrorSignal
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1547
	raiseRequestWith:filename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1548
	errorString:('access denied: ' , filename asString , errString)
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1549
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1550
    "Modified: / 26.9.1999 / 16:11:44 / cg"
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
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1553
fileCreationError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1554
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1555
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1556
    "report an error that some file could not be created"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1557
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1558
    ^ OperatingSystem accessDeniedErrorSignal
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1559
	raiseRequestWith:filename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1560
	errorString:('cannot create/write file: ' , filename asString)
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1561
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1562
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1563
fileNotFoundError:filename 
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1564
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1565
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1566
    "report an error that some file was not found"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1567
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1568
    ^ OperatingSystem fileNotFoundErrorSignal
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1569
	raiseRequestWith:filename
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1570
	errorString:('file not found: ' , filename asString)
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1571
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1572
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1573
removeError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1574
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1575
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1576
    "report an error that some file could not be removed"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1577
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1578
    ^ OperatingSystem accessDeniedErrorSignal
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1579
	raiseRequestWith:filename
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1580
	errorString:('cannot remove: ' , filename asString)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1581
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1582
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1583
reportError:string with:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1584
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1585
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1586
    "report an error"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1587
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1588
    ^ OperatingSystem errorSignal
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1589
	raiseRequestWith:filename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1590
	errorString:string
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1591
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1592
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1593
!Filename methodsFor:'file access'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1594
3015
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1595
appendStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1596
    "return a stream for appending to the file represented by the receiver.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1597
     If the file does not already exist, it is created.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1598
     Same as #appendingWriteStream for ST-80 compatibility."
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1599
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1600
    ^ self appendingWriteStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1601
!
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1602
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1603
appendingWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1604
    "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
  1605
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1606
     if it does exist, writes are appended at the end."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1607
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1608
    ^ FileStream appendingOldFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1609
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1610
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1611
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1612
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1613
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1614
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1615
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1616
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1617
     s := '/tmp/foo' asFilename appendingWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1618
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1619
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1620
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1621
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1622
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1623
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1624
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1625
newReadWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1626
    "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
  1627
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1628
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1629
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1630
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1631
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1632
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1633
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1634
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1635
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1636
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1637
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1638
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1639
     s := '/tmp/foo' asFilename newReadWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1640
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1641
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1642
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1643
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1644
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1645
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1646
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1647
readStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1648
    "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
  1649
     If the file does not already exist, nil is returned."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1650
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1651
    ^ FileStream readonlyFileNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1652
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1653
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1654
     '/tmp/foo' asFilename readStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1655
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1656
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1657
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1658
readWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1659
    "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
  1660
     If the file does not already exist, nil is returned.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1661
     If the file does exist, it is NOT truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1662
5208
7cdbf4e22374 oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents: 5200
diff changeset
  1663
    self exists ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1664
	^ FileStream oldFileNamed:(self osNameForAccess)
5208
7cdbf4e22374 oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents: 5200
diff changeset
  1665
    ].
7cdbf4e22374 oops - readWriteStream only worked for old files.
Claus Gittinger <cg@exept.de>
parents: 5200
diff changeset
  1666
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1667
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1668
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1669
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1670
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1671
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1672
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1673
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1674
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1675
     s := '/tmp/foo' asFilename readWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1676
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1677
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1678
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1679
     '/tmp/foo' asFilename contents      
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1680
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1681
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1682
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1683
writeStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1684
    "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
  1685
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1686
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1687
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1688
    ^ FileStream newFileForWritingNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1689
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1690
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1691
     '/tmp/foo' asFilename writeStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1692
    "
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1693
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1694
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1695
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1696
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1697
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1698
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1699
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1700
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1701
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1702
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1703
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1704
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1705
     '/tmp/foo' asFilename contents  
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1706
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1707
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1708
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1709
!Filename methodsFor:'file operations'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1710
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1711
addAccessRights:aCollection
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1712
    "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
  1713
     by the receiver. The argument must be a collection of symbols,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1714
     such as #readUser, #writeGroup etc."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1715
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1716
    |access osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1717
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1718
    osName := self osNameForFile.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1719
    access := OperatingSystem accessModeOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1720
    aCollection do:[:accessSymbol |
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1721
	access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1722
    ].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1723
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1724
	^ self accessDeniedError:self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1725
    ]
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1726
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1727
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1728
     'foo' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1729
     'foo' asFilename addAccessRights:#(readUser readGroup readOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1730
     'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1731
     'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1732
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1733
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1734
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1735
basicMakeDirectory
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1736
    "create a directory with the receivers name.
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1737
     Return true if successful, false if not."
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1738
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1739
    ^ OperatingSystem createDirectory:(self osNameForDirectory)
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1740
!
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1741
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1742
copyTo:newName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1743
    "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
  1744
     Raises an exception, if an error occurs."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1745
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1746
    |inStream outStream buffer bufferSize count newFile|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1747
4324
9b4b8ace862d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
  1748
    OperatingSystem isMSDOSlike ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1749
	"/ mhmh - NT hangs, when copying bigger blocks to a network drive - why ?
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1750
	bufferSize := 1 * 1024.
4324
9b4b8ace862d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
  1751
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1752
	bufferSize := 8 * 1024.
4324
9b4b8ace862d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
  1753
    ].
9b4b8ace862d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4323
diff changeset
  1754
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1755
    buffer := ByteArray new:bufferSize.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1756
    inStream := self readStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1757
    inStream isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1758
	^ self fileNotFoundError:self 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1759
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1760
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1761
    outStream := (newFile := newName asFilename) writeStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1762
    outStream isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1763
	inStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1764
	^ self fileCreationError:newFile
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1765
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1766
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1767
    [inStream atEnd] whileFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1768
	count := inStream nextBytes:bufferSize into:buffer.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1769
	(outStream nextPutBytes:count from:buffer) ~= count ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1770
	    inStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1771
	    outStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1772
	    ^ self fileCreationError:newFile
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1773
	]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1774
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1775
    outStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1776
    inStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1777
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1778
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1779
     'Makefile' asFilename copyTo:'Makefile.foo'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1780
     'smalltalk' asFilename copyTo:'/dev/null'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1781
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1782
5134
48758d82be48 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5132
diff changeset
  1783
    "Modified: / 23.12.1999 / 21:52:36 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1784
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1785
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1786
delete
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1787
    "remove the file - same as remove, for ST-80 compatibility"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1788
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1789
    self remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1790
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1791
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1792
makeDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1793
    "create a directory with the receivers name.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1794
     Raises an exception if not successful"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1795
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1796
    (self basicMakeDirectory) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1797
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1798
	"/ could have existed before ...
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1799
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1800
	(self exists and:[self isDirectory]) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1801
	    self fileCreationError:self.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1802
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1803
	]
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1804
    ].
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  1805
    ^ true
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1806
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1807
    "Modified: / 5.5.1999 / 13:36:33 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1808
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1809
844
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1810
makeExecutable
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1811
    "make the file executable - you must have permission to do so.
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1812
     For directories, execution means: 'allow changing into it'"
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1813
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1814
    ^ self addAccessRights:#(executeUser)
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1815
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1816
    "Created: 9.1.1996 / 15:32:47 / cg"
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1817
!
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1818
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1819
makeExecutableForAll
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1820
    "make the file executable for all - you must have permission to do so.
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1821
     For directories, execution means: 'allow changing into it'"
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1822
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1823
    ^ self addAccessRights:#(executeUser executeGroup executeOthers)
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1824
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1825
    "Created: 9.1.1996 / 15:32:28 / cg"
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1826
!
8833550c4e01 added makeExecutable methods
Claus Gittinger <cg@exept.de>
parents: 672
diff changeset
  1827
4901
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1828
makeExecutableForGroup
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1829
    "make the file executable for the group - you must have permission to do so.
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1830
     For directories, execution means: 'allow changing into it'"
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1831
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1832
    ^ self addAccessRights:#(executeGroup)
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1833
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1834
    "Created: 9.1.1996 / 15:32:28 / cg"
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1835
!
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1836
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1837
makeReadable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1838
    "make the file readable for  the owner - you must have permission to do so."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1839
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1840
    ^ self addAccessRights:#(readUser)
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1841
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1842
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1843
makeReadableForAll
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1844
    "make the file readable for all - you must have permission to do so."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1845
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1846
    ^ self addAccessRights:#(readUser readGroup readOthers)
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1847
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1848
4901
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1849
makeReadableForGroup
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1850
    "make the file readable for the group - you must have permission to do so."
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1851
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1852
    ^ self addAccessRights:#(readGroup)
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1853
!
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1854
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1855
makeUnwritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1856
    "make the file unwritable for all - you must have permission to do so."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1857
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1858
    ^ self removeAccessRights:#(writeUser writeGroup writeOthers)
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
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1861
makeWritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1862
    "make the file writableable for all - you must have permission to do so."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1863
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1864
    ^ self addAccessRights:#(writeUser)
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1865
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1866
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1867
makeWritableForAll
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1868
    "make the file writable for all - you must have permission to do so."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1869
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1870
    ^ self addAccessRights:#(writeUser writeGroup writeOthers)
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1871
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1872
4901
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1873
makeWritableForGroup
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1874
    "make the file writable for the group - you must have permission to do so."
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1875
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1876
    ^ self addAccessRights:#(writeGroup)
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1877
!
955ae4d4d9a8 checkin from browser
ca
parents: 4897
diff changeset
  1878
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1879
moveTo:newName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1880
    "copy the file represented by the receiver, then delete it.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1881
     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
  1882
     Raise an exception if not successful.
3d801043be3f dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 5577
diff changeset
  1883
     (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
  1884
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1885
    OperatingSystem errorSignal handle:[:ex |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1886
	self copyTo:newName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1887
	self remove
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1888
    ] do:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1889
	self renameTo:newName.
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1890
    ]
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1891
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1892
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1893
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1894
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1895
     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
  1896
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1897
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1898
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1899
     f renameTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1900
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1901
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1902
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1903
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1904
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1905
     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
  1906
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1907
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1908
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1909
     f moveTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  1910
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1911
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1912
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1913
recursiveCopyTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1914
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1915
     Otherwise, copy the directory and recursively
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1916
     and recursively all of its subfiles/subdirectories.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1917
     Raises an exception if not successful."
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1918
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  1919
    |ok d|
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1920
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1921
    self isDirectory ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1922
	d := destination asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1923
	(d exists and:[d isDirectory]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1924
	    d := d construct:self baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1925
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1926
	^ self copyTo:d
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1927
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1928
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1929
    "/ typically, an 'cp -r' is faster;
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1930
    "/ 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
  1931
    "/ fallBack doing a manual directory walk.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1932
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1933
    ok := OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1934
	    recursiveCopyDirectory:(self osNameForDirectory)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1935
	    to:(destination asFilename osNameForDirectory).
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1936
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1937
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1938
	self recursiveCopyWithoutOSCommandTo:destination
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1939
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1940
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1941
    "Created: / 5.5.1999 / 13:35:01 / cg"
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  1942
    "Modified: / 31.5.1999 / 13:11:34 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1943
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1944
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1945
recursiveCopyWithoutOSCommandTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1946
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1947
     Otherwise, copy the directory and all of its subfiles/subdirectories.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1948
     This one walks down the directory hierarchy, not using any OS
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1949
     command to do the copy.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1950
     Raises an exception if not successful."
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1951
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  1952
    |destinationFilename d|
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  1953
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  1954
    d := destination asFilename.
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  1955
"/    (d exists and:[d isDirectory]) ifTrue:[
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  1956
"/        d := d construct:self baseName.
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  1957
"/    ].
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1958
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1959
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1960
	destinationFilename := d asFilename construct:self baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1961
	destinationFilename makeDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1962
	self directoryContents do:[:aFilenameString |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1963
	    |src dst|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1964
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1965
	    src := self construct:aFilenameString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1966
	    src isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1967
		src recursiveCopyWithoutOSCommandTo:destinationFilename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1968
	    ] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1969
		src copyTo:(destinationFilename construct:aFilenameString)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1970
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1971
	]
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1972
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1973
	self copyTo:d
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1974
    ]
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1975
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1976
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1977
     '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1978
     'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1979
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1980
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  1981
    "Modified: / 31.5.1999 / 18:12:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1982
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1983
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1984
recursiveMakeDirectory
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1985
    "create a directory with the receivers name and all required intermediate
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1986
     directories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1987
     Raises an exception if not successful."
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1988
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1989
    (OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1990
	^ self fileCreationError:self
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1991
    ]
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1992
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1993
    "Created: / 27.11.1995 / 23:36:40 / cg"
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  1994
    "Modified: / 5.5.1999 / 13:38:42 / cg"
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1995
!
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  1996
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1997
recursiveRemove
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  1998
    "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
  1999
     Otherwise, remove the directory and all of its subfiles/subdirectories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2000
     Raise an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2001
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2002
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2003
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2004
    "/ typically, an 'rm -rf' is faster and removes better;
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2005
    "/ 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
  2006
    "/ fallBack doing a manual directory walk.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2007
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2008
    ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory).
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2009
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2010
	self recursiveRemoveWithoutOSCommand
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2011
    ].
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2012
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2013
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2014
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2015
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2016
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2017
	Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2018
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2019
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2020
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2021
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2022
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2023
     ('foo' asFilename recursiveRemove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2024
	Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2025
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2026
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2027
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2028
    "Created: / 14.11.1995 / 11:19:29 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2029
    "Modified: / 5.5.1999 / 13:43:35 / cg"
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2030
!
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2031
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2032
recursiveRemoveWithoutOSCommand
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2033
    "if I represent a regular file, remove it.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2034
     Otherwise, remove the directory and all of its subfiles/subdirectories.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2035
     Raise an error if not successful.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2036
     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
  2037
     command to do the remove."
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2038
4939
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  2039
    |files|
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  2040
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2041
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2042
	(files := self directoryContents) size > 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2043
	    files do:[:aFilenameString |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2044
		|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2045
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2046
		f := self construct:aFilenameString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2047
		f isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2048
		    f recursiveRemoveWithoutOSCommand
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2049
		] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2050
		    f remove
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2051
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2052
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2053
	]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2054
    ].
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2055
    self remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2056
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2057
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2058
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2059
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  2060
     'foo' asFilename remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2061
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2062
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2063
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2064
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  2065
     'foo' asFilename recursiveRemove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2066
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2067
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2068
    "Created: / 25.2.1998 / 19:50:40 / cg"
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2069
    "Modified: / 25.2.1998 / 19:52:08 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2070
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2071
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2072
remove
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  2073
    "remove the file/directory.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2074
     Raises an exception if not successful.
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  2075
     Use #recursiveRemove in order to (recursively) remove non empty directories."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2076
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2077
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2078
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2079
    self exists ifFalse:[ ^ self].
3113
43e75ed892cf Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents: 3077
diff changeset
  2080
    (self isSymbolicLink not and:[self isDirectory]) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2081
	ok := OperatingSystem removeDirectory:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2082
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2083
	ok := OperatingSystem removeFile:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2084
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2085
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2086
	self removeError:self
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2087
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2088
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2089
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2090
     (FileStream newFileNamed:'foo') close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2091
     'foo' asFilename remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2092
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2093
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2094
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2095
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2096
     'foo/bar' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2097
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2098
	Transcript showCR:'could not remove foo'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2099
     ]
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2100
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2101
3113
43e75ed892cf Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents: 3077
diff changeset
  2102
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2103
    "Modified: / 5.5.1999 / 13:41:12 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2104
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2105
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2106
removeAccessRights:aCollection
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2107
    "remove the access rights as specified in aCollection for the file represented
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2108
     by the receiver. The argument must be a collection of symbols,
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 659
diff changeset
  2109
     such as #readUser, #writeGroup etc.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2110
     Raises an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2111
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2112
    |access osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2113
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2114
    osName := self osNameForFile.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2115
    access := OperatingSystem accessModeOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2116
    aCollection do:[:accessSymbol |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2117
	access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2118
    ].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2119
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2120
	^ self accessDeniedError:self
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2121
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2122
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2123
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2124
     'foo' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2125
     'foo' asFilename removeAccessRights:#(readUser readGroup readOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2126
     'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2127
     'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2128
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2129
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2130
    "Modified: / 5.5.1999 / 13:41:21 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2131
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2132
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2133
removeDirectory
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2134
    "remove the directory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2135
     Raises an exception if not successful (or if its not a directory).
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2136
     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
  2137
     Use #recursiveRemove in order to (recursively) remove non empty directories."
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2138
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2139
    |ok|
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2140
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2141
    ok := OperatingSystem removeDirectory:(self osNameForFile).
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2142
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2143
	self exists ifFalse:[ ^ self].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2144
	self removeError:self
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2145
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2146
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2147
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2148
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2149
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2150
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2151
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2152
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2153
     'foo' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2154
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2155
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2156
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2157
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2158
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2159
     'foo/bar' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2160
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2161
	Transcript showCR:'could not remove foo'
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2162
     ]
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2163
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2164
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2165
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2166
    "Modified: / 5.5.1999 / 13:41:12 / cg"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2167
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2168
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2169
removeFile
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2170
    "remove the file.
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2171
     Raises an exception if not successful (or if its not a file).
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2172
     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
  2173
     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
  2174
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2175
    |ok|
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2176
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2177
    ok := OperatingSystem removeFile:(self osNameForFile).
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2178
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2179
	self exists ifFalse:[ ^ self].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2180
	self removeError:self
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2181
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2182
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2183
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2184
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2185
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2186
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2187
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2188
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2189
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2190
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2191
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2192
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2193
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2194
renameOrCopyTo:newName
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2195
    "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
  2196
     Raises an exception if not successful.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2197
     This does basically the same as #renameTo:, with one exception:
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2198
     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
  2199
     fails, and #renameTo: raises an exception;
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2200
     in contrast, this method falls back to copying the file."
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2201
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2202
    |newFilename|
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2203
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2204
    newFilename := newName asFilename.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2205
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2206
    (OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2207
	renameFile:(self osNameForFile) 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2208
	to:(newFilename osNameForFile)
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2209
    ) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2210
	self exists ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2211
	    ^ self fileNotFoundError:self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2212
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2213
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2214
	OperatingSystem isUNIXlike ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2215
	    OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2216
		"/ try to copy - and remove the original
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2217
		"/ this helps with cross-device renames.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2218
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2219
	      self copyTo:newName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2220
	      ^ self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2221
	  ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2222
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2223
	^ self accessDeniedError:newName asFilename.
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2224
    ].
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2225
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2226
    "
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2227
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2228
    "
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2229
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2230
    "Modified: / 5.5.1999 / 13:41:27 / cg"
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2231
!
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2232
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2233
renameTo:newName
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 659
diff changeset
  2234
    "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
  2235
     Raises an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2236
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2237
    (OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2238
	renameFile:(self osNameForFile) 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2239
	to:(newName asFilename osNameForFile)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2240
    ) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2241
	self exists ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2242
	    ^ self fileNotFoundError:self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2243
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2244
	^ self accessDeniedError:newName asFilename.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2245
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2246
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2247
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2248
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
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
    "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
  2252
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2253
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2254
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2255
    "change the files size.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2256
     This may not be supported on all operating systems
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2257
     (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
  2258
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2259
    (OperatingSystem truncateFile:(self osNameForFile) to:newSize) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2260
	^ 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
  2261
    ]
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2262
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2263
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2264
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2265
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2266
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2267
     s next:1000 put:$1.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2268
     s close.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2269
     ('test' asFilename fileSize) printNL.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2270
     'test' asFilename truncateTo:100.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2271
     ('test' asFilename fileSize) printNL.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2272
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2273
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2274
    "Modified: / 5.5.1999 / 13:41:59 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2275
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2276
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2277
!Filename methodsFor:'file queries'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2278
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2279
accessTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2280
    "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
  2281
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2282
    | i |
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2283
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2284
    (i := self info) isNil ifTrue:[^ nil].
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2285
    ^ i accessed
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2286
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2287
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2288
     Filename currentDirectory accessTime 
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2289
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2290
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2291
    "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
  2292
    "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
  2293
    "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
  2294
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2295
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2296
dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2297
    "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
  2298
     that responds to the at: message with arguments 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2299
     #modified, #accessed or #statusChanged."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2300
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2301
    |info dates osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2302
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2303
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2304
    info := OperatingSystem infoOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2305
    info isNil ifTrue:[
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2306
	info := OperatingSystem linkInfoOf:osName.
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2307
	info isNil ifTrue:[
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2308
	    ^ nil
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2309
	]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2310
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2311
    dates := IdentityDictionary new.
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2312
    dates at:#modified put:(info modified).
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2313
    dates at:#accessed put:(info accessed).
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2314
    dates at:#statusChanged put:(info statusChanged).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2315
    ^ dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2316
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2317
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2318
     Filename currentDirectory dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2319
     '../regression' asFilename dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2320
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2321
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2322
    "Modified: 1.11.1996 / 20:19:24 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2323
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2324
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2325
fileSize
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2326
    "return the size of the file in bytes"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2327
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2328
    |i|
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2329
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2330
    (i := self info) isNil ifTrue:[^ nil].
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2331
    ^ i size
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2332
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2333
    "Modified: / 17.8.1998 / 10:23:46 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2334
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2335
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2336
fileType
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2337
    "this returns a string describing the type of contents of
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2338
     the file. This is done using the unix 'file' command,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2339
     (which usually is configurable by /etc/magic).
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2340
     On non-unix systems, this may simply return 'file', 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2341
     not knowning about the contents.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2342
     Warning:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2343
	 Since the returned string differs among systems (and language settings),
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2344
	 it is only useful for user-information; 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2345
	 NOT as a tag to be used by a program."
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2346
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2347
    |type buffer s n suffix idx baseNm|
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2348
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2349
    "/ since we cannot depend on a 'file' command being available,
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2350
    "/ do the most obvious ones here. 
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2351
    "/ (also useful since the 'file' command takes some time, and the code
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2352
    "/  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
  2353
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2354
    self isSymbolicLink ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2355
	^ 'symbolic link to ' , (self linkInfo path)
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2356
    ].
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  2357
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2358
	self isReadable ifFalse:[^ 'directory, unreadable'].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2359
	self isExecutable ifFalse:[^ 'directory, locked'].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2360
	^ 'directory'
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  2361
    ].
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2362
    (type := self type) == #characterSpecial ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2363
	^ 'character device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2364
    ].
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2365
    type == #blockSpecial ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2366
	^ 'block device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2367
    ].
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2368
    type == #socket ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2369
	^ 'socket'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2370
    ].
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2371
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  2372
    self isReadable ifFalse:[^ 'unreadable'].
1612
730781a80e2a inline detect empty and HTML documents
Claus Gittinger <cg@exept.de>
parents: 1602
diff changeset
  2373
    self fileSize == 0 ifTrue:[^ 'empty'].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  2374
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2375
    suffix := self suffix asLowercase.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2376
    baseNm := self withoutSuffix baseName asLowercase.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2377
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2378
    ((#('st' 'rc' 'chg' 'htm' 'html' 'ps') includes:suffix)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2379
    or:[#('makefile') includes:baseNm]) ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2380
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2381
	buffer := String new:2024.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2382
	s := self readStream.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2383
	s notNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2384
	    n := s nextBytes:buffer size into:buffer.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2385
	    s close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2386
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2387
	    (suffix = 'st') ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2388
		(buffer findString:'subclass:') ~~ 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2389
		    ^ 'smalltalk source'
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
		(buffer findString:'methodsFor:') ~~ 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2392
		    ^ 'smalltalk source'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2393
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2394
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2395
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2396
	    (buffer findString:'methodsFor:') ~~ 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2397
		^ 'smalltalk changes / method source'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2398
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2399
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2400
	    (suffix = 'rc') ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2401
		(buffer findString:'ST/X startup') ~~ 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2402
		    ^ 'smalltalk startup script'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2403
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2404
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2405
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2406
	    (suffix = 'htm' or:[suffix = 'html']) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2407
		(idx := buffer findString:'<H') ~~ 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2408
		    ((buffer continuesWith:'<HEAD' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2409
		    or:[(buffer continuesWith:'<HTML' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2410
		    or:[(buffer continuesWith:'<H1' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2411
		    or:[(buffer continuesWith:'<H2' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2412
		    or:[(buffer continuesWith:'<H3' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2413
		    or:[(buffer continuesWith:'<H4' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2414
		    or:[(buffer continuesWith:'<H5' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2415
		    or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]])
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2416
		    ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2417
			^ 'HTML document text'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2418
		    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2419
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2420
	    ].
1614
4e1a64b19247 inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents: 1612
diff changeset
  2421
        
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2422
	    (suffix = 'ps') ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2423
		(buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2424
		    ^ 'PostScript document'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2425
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2426
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2427
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2428
	    (baseNm = 'makefile') ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2429
		(buffer startsWith:'#') ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2430
		    ^ 'make rules'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2431
		]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2432
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2433
	]
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  2434
    ].
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2435
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2436
    ^ 'file'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2437
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2438
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2439
     'Makefile' asFilename fileType 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2440
     '.' asFilename fileType     
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2441
     '/dev/null' asFilename fileType 
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2442
     '/tmp/.X11-unix/X0' asFilename fileType 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2443
     'smalltalk.rc' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2444
     'bitmaps/SBrowser.xbm' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2445
    "
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  2446
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2447
    "Modified: / 21.7.1998 / 11:25:56 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2448
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2449
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2450
id
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2451
    "return the files/directories file-id (inode number)"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2452
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2453
    ^ OperatingSystem idOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2454
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2455
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2456
     Filename currentDirectory id 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2457
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2458
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2459
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2460
    "Created: 5.8.1997 / 19:26:01 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2461
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2462
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2463
info
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2464
    "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
  2465
     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
  2466
     the returned object) is:
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2467
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2468
	 type  - a symbol giving the files fileType
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2469
	 mode  - numeric access mode 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2470
	 uid   - owners user id
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2471
	 gid   - owners group id
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2472
	 size  - files size
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2473
	 id    - files number (i.e. inode number)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2474
	 accessed      - last access time (as osTime-stamp)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2475
	 modified      - last modification time (as osTime-stamp)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2476
	 statusChanged - last staus change (as osTime-stamp)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2477
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2478
     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
  2479
     all of the information.
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2480
     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
  2481
	modified
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2482
	size
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2483
	type
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2484
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2485
     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
  2486
     to either handle nil values,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2487
     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
  2488
     (i.e. instead of:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2489
	someFilename type == #directory
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2490
      use
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2491
	someFilename isDirectory
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2492
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2493
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2494
    ^ OperatingSystem infoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2495
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2496
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2497
     Filename currentDirectory info
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2498
     '/dev/null' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2499
     '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
  2500
     '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
  2501
     '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
  2502
     '../../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
  2503
     '.' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2504
     '..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2505
     '..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2506
     '..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2507
     '..\..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2508
     'c:\' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2509
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2510
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2511
    "Modified: / 17.8.1998 / 10:24:10 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2512
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2513
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2514
linkInfo
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2515
    "return the files info if its a symbolic link; nil otherwise.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2516
     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
  2517
     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
  2518
     receiver represents a symbolic link, the links information 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2519
     is returned 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2520
     (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
  2521
      which is accessed via the symbolic link).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2522
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2523
     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
  2524
	 path -> the target files pathname
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2525
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2526
     See the comment in #info for more details."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2527
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2528
    ^ OperatingSystem linkInfoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2529
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2530
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2531
     Filename currentDirectory linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2532
     '/dev/null' asFilename linkInfo    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2533
     'Make.proto' asFilename linkInfo   
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  2534
     'Make.proto' asFilename linkInfo path  
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2535
     'source/Point.st' asFilename linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2536
     '../../libbasic/Point.st' asFilename linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2537
    "
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  2538
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  2539
    "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
  2540
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2541
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2542
modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2543
    "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
  2544
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2545
    |i|
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2546
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2547
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2548
    ^ i modified
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2549
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2550
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2551
     Filename currentDirectory modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2552
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2553
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2554
    "Created: / 9.7.1996 / 10:18:59 / cg"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2555
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  2556
    "Modified: / 14.8.1998 / 17:42:50 / cg"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2557
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2558
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2559
type
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2560
    "return the symbolic type of the file"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2561
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2562
    ^ OperatingSystem typeOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2563
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2564
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2565
     Filename currentDirectory type 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2566
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2567
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2568
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  2569
    "Created: 5.8.1997 / 19:31:26 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2570
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2571
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2572
!Filename methodsFor:'file utilities'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2573
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2574
edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2575
    "start an editView on the file represented by the receiver"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2576
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2577
    EditTextView openOn:self asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2578
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2579
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2580
     'smalltalk.rc' asFilename edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2581
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2582
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2583
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2584
fileIn
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2585
    "load smalltalk code from the file"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2586
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2587
    |s rslt|
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2588
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2589
    s := self readStream.
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2590
    [
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2591
	rslt := s fileIn.
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2592
    ] valueNowOrOnUnwindDo:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2593
	s close.
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2594
    ].
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  2595
    ^ rslt.
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2596
! !
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2597
2
claus
parents: 1
diff changeset
  2598
!Filename methodsFor:'instance creation'!
claus
parents: 1
diff changeset
  2599
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2600
construct:subname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2601
    "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
  2602
     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
  2603
     (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
  2604
     The argument may not specify an absolute path name.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2605
     Please do not use this to create filenames with suffixes,
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2606
     since some systems require special naming conventions.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2607
     See also: #withSuffix: (which is different, but often needed)."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2608
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  2609
    ^ self class named:(self constructString:subname)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2610
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2611
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2612
     '/tmp' asFilename construct:'foo'    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2613
     '/' asFilename construct:'foo'         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2614
     '/usr/tmp' asFilename construct:'foo'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2615
     '/foo/bar' asFilename construct:'baz' 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2616
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2617
     Bad example; works on UNIX, but may not on others:
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2618
       'foo/bar.baz' construct:'.suff'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2619
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2620
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2621
    "Modified: 29.2.1996 / 20:55:06 / cg"
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2622
!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2623
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2624
constructDirectory:subname
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2625
    "same as #construct: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2626
     (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
  2627
     
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2628
    ^ self class named:(self constructDirectoryString:subname)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2629
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2630
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2631
constructDirectoryString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2632
    "same as #constructString: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2633
     (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
  2634
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2635
    ^ self constructString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2636
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2637
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2638
constructString:subName
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2639
    "taking the receiver as a directory name, construct a new
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2640
     filename-string for an entry within this directory 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2641
     (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
  2642
     The argument may not specify an absolute path name.
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2643
     The code below works for UNIX & MSDOS; 
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2644
     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
  2645
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2646
    |sepString sub|
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2647
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2648
    sub := subName asString.
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2649
    sepString := self class separator asString.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2650
    nameString = sepString ifTrue:[
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2651
	"I am the root"
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2652
	^ sepString  , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2653
    ].
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2654
    (nameString endsWith:sepString) ifTrue:[
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2655
	^ nameString , sub
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2656
    ].
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  2657
    ^ nameString , sepString , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2658
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2659
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2660
     '/tmp' asFilename constructString:'foo'   
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2661
     '/' asFilename constructString:'foo'         
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2662
     '/usr/tmp' asFilename constructString:'foo'
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2663
     '/foo/bar' asFilename constructString:'baz' 
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2664
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  2665
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2666
    "Modified: / 7.9.1995 / 10:15:22 / claus"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2667
    "Created: / 9.9.1997 / 08:57:08 / cg"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2668
    "Modified: / 20.1.1998 / 15:58:23 / md"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  2669
    "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
  2670
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2671
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2672
filenameFor:fileName
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2673
    "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
  2674
     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
  2675
     (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
  2676
     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
  2677
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2678
    |f|
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2679
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2680
    f := fileName asFilename.
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2681
    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
  2682
    ^ (self construct:fileName)
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2683
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2684
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2685
     '/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
  2686
     '/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
  2687
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2688
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2689
    "Created: 18.9.1997 / 14:34:14 / stefan"
2
claus
parents: 1
diff changeset
  2690
! !
claus
parents: 1
diff changeset
  2691
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2692
!Filename methodsFor:'misc'!
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2693
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2694
, aString
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2695
    "this allows filenames to understand how names are concatenated.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  2696
     Returns a string consisting of the receivers name, concatenated
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2697
     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
  2698
     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
  2699
     See also: #withSuffix: which is new and better."
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2700
5866
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  2701
    <resource:#obsolete>
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  2702
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2703
    self obsoleteMethodWarning:'use #construct:'.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  2704
    ^ (nameString , aString asString)
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2705
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2706
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2707
     'Makefile' asFilename , '.bak'        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2708
     ('Makefile' asFilename , '.bak') asFilename  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2709
     'Makefile' asFilename withSuffix:'bak' 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2710
     'Makefile' asFilename construct:'.bak'     
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2711
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  2712
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2713
    "Modified: 7.9.1997 / 23:45:36 / cg"
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2714
! !
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  2715
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2716
!Filename methodsFor:'printing & storing'!
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  2717
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2718
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  2719
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  2720
     The format is suitable for a human - not meant to be read back."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  2721
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2722
    aStream nextPutAll:(self class name).
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2723
    aStream nextPutAll:'('''.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2724
    nameString printOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2725
    aStream nextPutAll:''')'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2726
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2727
    "Modified: 7.9.1997 / 23:46:20 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2728
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2729
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2730
storeOn:aStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2731
    "append a printed representation of the receiver to aStream,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2732
     which allows reconstructing it via readFrom:"
328
claus
parents: 326
diff changeset
  2733
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2734
    aStream nextPut:$(.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2735
    nameString storeOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2736
    aStream nextPutAll:' asFilename)'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2737
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2738
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 195
diff changeset
  2739
!Filename methodsFor:'private accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2740
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2741
setName:aString
38
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  2742
    "set the filename"
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  2743
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  2744
    nameString := self nameWithSpecialExpansions:aString.
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  2745
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  2746
    "Modified: / 21.7.1998 / 10:44:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2747
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  2748
2
claus
parents: 1
diff changeset
  2749
!Filename methodsFor:'queries'!
claus
parents: 1
diff changeset
  2750
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2751
canBeWritten
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2752
    "same as isWritable - for ST-80 compatibility"
328
claus
parents: 326
diff changeset
  2753
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2754
    ^ self isWritable
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2755
328
claus
parents: 326
diff changeset
  2756
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2757
     '/foo/bar' asFilename canBeWritten 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2758
     '/tmp' asFilename canBeWritten   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2759
     'Makefile' asFilename canBeWritten   
328
claus
parents: 326
diff changeset
  2760
    "
claus
parents: 326
diff changeset
  2761
!
claus
parents: 326
diff changeset
  2762
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2763
exists
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2764
    "return true, if such a file exists."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2765
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2766
    ^ OperatingSystem isValidPath:(self osNameForAccess)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  2767
85
claus
parents: 77
diff changeset
  2768
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2769
     '/foo/bar' asFilename exists 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2770
     '/tmp' asFilename exists  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  2771
     'Makefile' asFilename exists   
85
claus
parents: 77
diff changeset
  2772
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2773
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  2774
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2775
filenamesMatching:aPattern
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2776
    "VW compatibility"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2777
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2778
    ^ (self filesMatching:aPattern) asOrderedCollection
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2779
	    collect:[:eachName | self construct:eachName]
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2780
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2781
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2782
     '/etc' asFilename filenamesMatching:'a*;c*' 
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2783
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2784
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2785
    "Created: / 15.4.1997 / 15:40:02 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2786
    "Modified: / 3.8.1998 / 21:22:15 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2787
!
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  2788
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2789
filesMatching:aPattern
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2790
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2791
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2792
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2793
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2794
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2795
    |matchers notCaseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2796
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2797
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2798
    notCaseSensitive := self class isCaseSensitive not.
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2799
    ^ self directoryContents
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2800
	select:[:name | 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2801
		(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2802
	       ]
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2803
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2804
    "
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2805
     '/etc' asFilename filesMatching:'a*;c*' 
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2806
    "
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2807
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2808
    "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
  2809
    "Modified: / 3.8.1998 / 21:22:15 / cg"
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2810
!
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2811
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2812
filesMatchingWithoutDotDirs:aPattern
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2813
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2814
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2815
     Exclude '.' and '..' from the returned list.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2816
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2817
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2818
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2819
    |matchers notCaseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2820
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2821
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2822
    notCaseSensitive := self class isCaseSensitive not.
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2823
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2824
    ^ self directoryContents 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2825
	select:[:name | 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2826
		name ~= '.'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2827
		and:[name ~= '..'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2828
		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
  2829
      ]
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2830
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2831
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2832
     Filename currentDirectory filesMatching:'M*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2833
     '/etc' asFilename filesMatching:'[a-z]*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2834
     '../../libbasic' asFilename filesMatching:'[A-D]*.st'  
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2835
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  2836
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  2837
    "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
  2838
    "Modified: / 3.8.1998 / 21:22:30 / cg"
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2839
!
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  2840
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2841
isAbsolute
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2842
    "return true, if the receiver represents an absolute pathname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2843
     (in contrast to one relative to the current directory)."
356
claus
parents: 328
diff changeset
  2844
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2845
    (nameString startsWith:self class separator) ifTrue:[^ true].
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2846
    ^ self isVolumeAbsolute
328
claus
parents: 326
diff changeset
  2847
claus
parents: 326
diff changeset
  2848
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2849
     '/foo/bar' asFilename isAbsolute   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2850
     '..' asFilename isAbsolute         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2851
     '..' asAbsoluteFilename isAbsolute         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2852
     'source/SBrowser.st' asFilename isAbsolute  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2853
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2854
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2855
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2856
isDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2857
    "return true, if the receiver represents an existing,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2858
     readable directories pathname."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2859
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2860
    ^ OperatingSystem isDirectory:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2861
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2862
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2863
     '/foo/bar' asFilename isDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2864
     '/tmp' asFilename isDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2865
     'Makefile' asFilename isDirectory   
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  2866
     'c:\' asFilename isDirectory   
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  2867
     'd:\' asFilename isDirectory   
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2868
    "
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  2869
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  2870
    "Modified: / 21.9.1998 / 15:53:10 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2871
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2872
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2873
isExecutable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2874
    "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
  2875
     For directories, true is returned if the directory can be entered.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2876
     See isExecutableProgram for a related check."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2877
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2878
    ^ OperatingSystem isExecutable:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2879
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2880
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2881
     '/foo/bar' asFilename isExecutable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2882
     '/tmp' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2883
     'Makefile' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2884
     '/bin/ls' asFilename isExecutable   
356
claus
parents: 328
diff changeset
  2885
    "
claus
parents: 328
diff changeset
  2886
!
claus
parents: 328
diff changeset
  2887
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2888
isExecutableProgram
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2889
    "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
  2890
     (i.e. for directories, false is returned.)"
356
claus
parents: 328
diff changeset
  2891
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2892
    |osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2893
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2894
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2895
    ^ (OperatingSystem isExecutable:osName)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2896
      and:[(OperatingSystem isDirectory:osName) not]
356
claus
parents: 328
diff changeset
  2897
claus
parents: 328
diff changeset
  2898
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2899
     '/tmp' asFilename isExecutable         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2900
     '/bin/ls' asFilename isExecutable       
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2901
     '/tmp' asFilename isExecutableProgram   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2902
     '/bin/ls' asFilename isExecutableProgram    
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
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2906
isExplicitRelative
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2907
    "return true, if this name is an explicit relative name
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2908
     (i.e. starts with './' or '../', to avoid path-prepending)"
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2909
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2910
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2911
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2912
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2913
isHidden
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2914
    "return true, if the receiver represents a hidden file.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2915
     The definitions of hidden files depends on the OS used;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2916
     on UNIX, a name starting with a period is considered hidden;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2917
     on MSDOS, the files hidden attribute is used.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2918
     VMS has no concept of hidden files."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2919
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2920
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2921
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2922
2944
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2923
isImplicit
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2924
    "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
  2925
     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
  2926
     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
  2927
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2928
    ^ false
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2929
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2930
    "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
  2931
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  2932
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2933
isReadable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2934
    "return true, if such a file exists and is readable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2935
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2936
    ^ OperatingSystem isReadable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2937
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2938
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2939
     '/foo/bar' asFilename isReadable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2940
     '/tmp' asFilename isReadable      
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2941
     'Makefile' asFilename isReadable   
328
claus
parents: 326
diff changeset
  2942
    "
claus
parents: 326
diff changeset
  2943
!
claus
parents: 326
diff changeset
  2944
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2945
isRelative
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2946
    "return true, if this name is interpreted relative to some
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2947
     directory (opposite of absolute)"
328
claus
parents: 326
diff changeset
  2948
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2949
    ^ self isAbsolute not
2175
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2950
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2951
    "
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2952
     './foo/bar' asFilename isRelative
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2953
     '../../foo/bar' asFilename isRelative
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2954
     '/foo/bar' asFilename isRelative     
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2955
     'bar' asFilename isRelative          
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2956
    "
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2957
a3fe5ef27022 commentary
Claus Gittinger <cg@exept.de>
parents: 2168
diff changeset
  2958
    "Modified: 16.1.1997 / 01:19:14 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2959
!
328
claus
parents: 326
diff changeset
  2960
3045
fb2d17c7a360 fixed fullDirectoryContents (mounted volumes)
ca
parents: 3015
diff changeset
  2961
isRootDirectory
3046
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  2962
    "return true, if I represent the root directory 
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  2963
     (i.e. I have no parentDir)"
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  2964
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2965
    "/ mhmh - should we use:
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2966
    "/
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2967
    "/ parentDir := self construct:'..'.
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2968
    "/ (parentDir exists
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2969
    "/ and:[parentDir isDirectory
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2970
    "/ and:[parentDir id ~= self id]]) ifTrue:[
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2971
    "/    ^ false
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2972
    "/ ].
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2973
    "/ ^ true
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2974
    "/
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2975
3046
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  2976
    ^ self pathName = Filename rootDirectory pathName
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  2977
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  2978
    "Modified: 23.10.1997 / 00:38:35 / cg"
3045
fb2d17c7a360 fixed fullDirectoryContents (mounted volumes)
ca
parents: 3015
diff changeset
  2979
!
fb2d17c7a360 fixed fullDirectoryContents (mounted volumes)
ca
parents: 3015
diff changeset
  2980
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2981
isSymbolicLink
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2982
    "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
  2983
     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
  2984
     not will always return false."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2985
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2986
    ^ OperatingSystem isSymbolicLink:(self osNameForFile)
328
claus
parents: 326
diff changeset
  2987
claus
parents: 326
diff changeset
  2988
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2989
     'Make.proto' asFilename isSymbolicLink  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2990
     'Makefile' asFilename isSymbolicLink   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2991
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2992
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2993
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2994
isVolumeAbsolute
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2995
    "return true, if the receiver represents an absolute pathname
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2996
     on some disk volume (MSDOS only)"
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2997
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  2998
    ^ false
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  2999
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3000
    "Modified: 7.9.1997 / 23:54:33 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3001
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3002
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3003
isWritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3004
    "return true, if such a file exists and is writable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3005
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3006
    ^ OperatingSystem isWritable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3007
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3008
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3009
     '/foo/bar' asFilename isWritable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3010
     '/tmp' asFilename isWritable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3011
     'Makefile' asFilename isWritable   
328
claus
parents: 326
diff changeset
  3012
    "
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3013
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3014
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3015
separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3016
    "return the directory-separator character"
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3017
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3018
    ^ self class separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3019
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3020
    "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
  3021
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3022
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3023
!Filename methodsFor:'queries-contents'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3024
3865
fae8d6f1942e renamed #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  3025
binaryContentsOfEntireFile
3864
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3026
    "return the binary contents of the file as a byteArray;
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3027
     or nil, if the file is unreadable/non-existing."
3864
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3028
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3029
    |s contents|
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3030
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3031
    s := self readStream.
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3032
    s isNil ifTrue:[^ nil].
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3033
    s binary.
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3034
    [
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3035
	contents := s contentsOfEntireFile
3864
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3036
    ] valueNowOrOnUnwindDo:[s close].
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3037
    ^ contents
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3038
3865
fae8d6f1942e renamed #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3864
diff changeset
  3039
    "Created: / 3.10.1998 / 17:56:39 / cg"
3864
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3040
!
7579a0090a6a added #binaryContents
Claus Gittinger <cg@exept.de>
parents: 3854
diff changeset
  3041
1540
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3042
contents
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3043
    "return the contents of the file as a collection of lines;
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3044
     or nil, if the file is unreadable/non-existing.
3876
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3045
     See also #contentsOfEntireFile, which returns a string for textFiles."
1540
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3046
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3047
    |s contents|
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3048
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3049
    s := self readStream.
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3050
    s isNil ifTrue:[^ nil].
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3051
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3052
    [
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3053
	contents := s contents
1540
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3054
    ] valueNowOrOnUnwindDo:[s close].
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3055
    ^ contents
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3056
5226
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3057
    "
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3058
     'Makefile' asFilename contents
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3059
    "
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3060
3876
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3061
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3062
    "Created: / 11.7.1996 / 14:09:11 / cg"
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3063
    "Modified: / 15.10.1998 / 11:41:45 / cg"
1540
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3064
!
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3065
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3066
contentsOfEntireFile
1540
2f442d8dad53 added #contents
Claus Gittinger <cg@exept.de>
parents: 1535
diff changeset
  3067
    "return the contents of the file as a string;
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3068
     or nil, if the file is unreadable/non-existing.
3876
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3069
     See also #contents, which returns the lines as stringCollection for textFiles."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3070
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3071
    |s contents|
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3072
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3073
    s := self readStream.
1535
9feed3032434 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1532
diff changeset
  3074
    s isNil ifTrue:[^ nil].
9feed3032434 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1532
diff changeset
  3075
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3076
    [
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3077
	contents := s contentsOfEntireFile
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3078
    ] valueNowOrOnUnwindDo:[s close].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3079
    ^ contents
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  3080
5226
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3081
    "
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3082
     'Makefile' asFilename contentsOfEntireFile
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3083
    "
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3084
3876
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3085
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
a680b41a014c comment
Claus Gittinger <cg@exept.de>
parents: 3871
diff changeset
  3086
    "Modified: / 15.10.1998 / 11:42:05 / cg"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3087
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3088
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3089
directoryContents
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3090
    "return the contents of the directory as a collection of strings.
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3091
     This excludes any entries for '.' or '..'.
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3092
     Returns nil for non-existing directories; however, this behavior
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3093
     may be changed in the near future, to raise an exception instead.
5226
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3094
     So users of this method better test for existing directory before.
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3095
     Notice: this returns the file-names as strings; see also
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3096
     #directoryContentsAsFilenames, which returns fileName objects."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3097
2946
c61e7226a7eb #directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents: 2944
diff changeset
  3098
    |s contents|
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3099
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3100
    s := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
3713
881d419652f3 care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents: 3677
diff changeset
  3101
    s isNil ifTrue:[^nil].
881d419652f3 care for non-existing directory - before removing '.' and '..'
Claus Gittinger <cg@exept.de>
parents: 3677
diff changeset
  3102
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3103
    [ 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3104
	contents := s contents.
5934
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3105
    ] valueNowOrOnUnwindDo:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3106
	s close
5934
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3107
    ].
2946
c61e7226a7eb #directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents: 2944
diff changeset
  3108
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3109
    contents remove:'.' ifAbsent:nil.
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3110
    contents remove:'..' ifAbsent:nil.
2946
c61e7226a7eb #directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents: 2944
diff changeset
  3111
    ^ contents.
c61e7226a7eb #directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents: 2944
diff changeset
  3112
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3113
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3114
     '.' asFilename directoryContents
2946
c61e7226a7eb #directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents: 2944
diff changeset
  3115
     '/XXXdoesNotExist' asFilename directoryContents
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3116
    "
2946
c61e7226a7eb #directoryContents no longer uses FileDirectory.
Stefan Vogel <sv@exept.de>
parents: 2944
diff changeset
  3117
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3118
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3119
    "Modified: / 3.8.1998 / 21:36:21 / cg"
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3120
!
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3121
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3122
directoryContentsAsFilenames
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3123
    "return the contents of the directory as a collection of filenames.
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3124
     This excludes any entries for '.' or '..'.
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3125
     Returns nil for non-existing directories; however, this behavior
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3126
     may be changed in the near future, to raise an exception instead.
5226
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3127
     So users of this method better test for existing directory before.
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3128
     Notice: this returns the file-names as fileName objects; see also
49955e61788f comments
Claus Gittinger <cg@exept.de>
parents: 5208
diff changeset
  3129
     #directoryContents, which returns strings."
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3130
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3131
    |names|
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3132
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3133
    names := self directoryContents.
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3134
    names isNil ifTrue:[^ nil].
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3135
    ^ names asOrderedCollection collect:[:entry | self construct:entry].
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3136
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3137
    "
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3138
     '.' asFilename directoryContentsAsFilenames   
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3139
     '/XXXdoesNotExist' asFilename directoryContentsAsFilenames
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3140
    "
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3141
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3142
!
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3143
5934
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3144
directoryContentsDo:aBlock
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3145
    "evaluate aBlock for each file in the directory represented by the receiver.
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3146
     The block is invoked with a string as argument.
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3147
     The enumerations order is undefined - i.e. usually NOT sorted by
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3148
     filenames (but by creation time - on some systems).
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3149
     This excludes entries for '.' or '..'.
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3150
     NoOp for non-existing directories; however, this behavior
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3151
     may be changed in the near future, to raise an exception instead.
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3152
     So users of this method better test for existing directory before.
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3153
     Notice: this enumerates strings; see also
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3154
     #directoryContentsDo:, which enumerates fileName objects."
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3155
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3156
    |s fn|
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3157
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3158
    s := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3159
    s isNil ifTrue:[^ nil].
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3160
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3161
    [
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3162
	[s atEnd] whileFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3163
	    fn := s nextLine.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3164
	    ((fn ~= '.') and:[fn ~= '..']) ifTrue:[        
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3165
		aBlock value:fn
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3166
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3167
	]
5934
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3168
    ] valueNowOrOnUnwindDo:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3169
	s close
5934
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3170
    ].
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3171
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3172
    "
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3173
     '.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3174
    "
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3175
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3176
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3177
    "Modified: / 23.12.1999 / 20:56:35 / cg"
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3178
!
150803769afd checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5928
diff changeset
  3179
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3180
fullDirectoryContents
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3181
    "return the full contents of the directory as a collection of strings.
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3182
     This is much like #directoryContents, but includes an entry for the
4897
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3183
     parent directory, if there is one.
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3184
     Returns nil for non-existing directories; however, this behavior
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3185
     may be changed in the near future, to raise an exception instead.
b7f31ef6f69a comments;
Claus Gittinger <cg@exept.de>
parents: 4820
diff changeset
  3186
     So users of this method better test for existing directory before."
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3187
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3188
    |files|
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3189
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3190
    files := self directoryContents.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3191
    files isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3192
	"/ mhmh - that one does not exist
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3193
	^ files
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3194
    ].
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3195
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3196
    "/ add/remove parentDirectory if there is one/none
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3197
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3198
    files remove:'.' ifAbsent:nil.
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3199
    self isRootDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3200
	files remove:'..' ifAbsent:nil.
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3201
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3202
	(files includes:'..') ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3203
	    files addFirst:'..'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3204
	]
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3205
    ].
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3206
    ^ files
3046
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3207
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3208
    "
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3209
     '.' asFilename fullDirectoryContents
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3210
     '/XXXdoesNotExist' asFilename fullDirectoryContents
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3211
     'd:\FET' asFilename fullDirectoryContents
3046
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3212
    "
f7c8ad3b7dbf *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3045
diff changeset
  3213
3843
bd729bf4ae3a comments only
Claus Gittinger <cg@exept.de>
parents: 3774
diff changeset
  3214
    "Modified: / 21.9.1998 / 15:33:07 / cg"
3867
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3215
!
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3216
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3217
mimeTypeOfContents
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3218
    "this tries to guess the mime type of contents of
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3219
     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
  3220
     or the contents is unknown.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3221
     This is done using some heuristics, and may need some improvement"
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3222
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3223
    |type buffer s n suffix idx idx2 baseNm|
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3224
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3225
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3226
	^ 'nil'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3227
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3228
    (type := self type) == #characterSpecial ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3229
	^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3230
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3231
    type == #blockSpecial ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3232
	^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3233
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3234
    type == #socket ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3235
	^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3236
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3237
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3238
    self isReadable ifFalse:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3239
    self fileSize == 0 ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3240
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3241
    suffix := self suffix asLowercase.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3242
    baseNm := self withoutSuffix baseName asLowercase.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3243
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3244
    "/ read some data from the file ...
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3245
    buffer := String new:2024.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3246
    s := self readStream.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3247
    s isNil ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3248
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3249
    n := s nextBytes:buffer size into:buffer.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3250
    s close.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3251
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3252
    (idx := buffer findString:'MIMEType:') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3253
	idx := idx + 'MIMEType:' size.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3254
	idx := buffer indexOfNonSeparatorStartingAt:idx.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3255
	idx2 := buffer indexOfSeparatorStartingAt:idx.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3256
	idx2 > idx ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3257
	    ^ buffer copyFrom:idx to:idx2-1
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3258
	].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3259
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3260
5303
fd21c677d273 support for sif-fileIn
Claus Gittinger <cg@exept.de>
parents: 5226
diff changeset
  3261
    (buffer findString:'interchangeVersion:') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3262
	^ 'application/x-smalltalk-source-sif'
5303
fd21c677d273 support for sif-fileIn
Claus Gittinger <cg@exept.de>
parents: 5226
diff changeset
  3263
    ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3264
    (buffer findString:'subclass:') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3265
	^ 'application/x-smalltalk-source'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3266
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3267
    (buffer findString:'methodsFor:') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3268
	^ 'application/x-smalltalk-source'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3269
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3270
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3271
    (buffer findString:'<BODY:') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3272
	^ 'text/html'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3273
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3274
    (idx := buffer findString:'<H') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3275
	((buffer continuesWith:'<HEAD' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3276
	or:[(buffer continuesWith:'<HTML' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3277
	or:[(buffer continuesWith:'<H1' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3278
	or:[(buffer continuesWith:'<H2' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3279
	or:[(buffer continuesWith:'<H3' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3280
	or:[(buffer continuesWith:'<H4' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3281
	or:[(buffer continuesWith:'<H5' startingAt:idx)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3282
	or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]])
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3283
	ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3284
	    ^ 'text/html'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3285
	]
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3286
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3287
        
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3288
    (buffer findString:'%!!PS-Adobe') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3289
	^ 'application/postscript'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3290
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3291
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3292
    (buffer findString:'#!! /bin/sh') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3293
	^ 'application/x-sh'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3294
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3295
    (buffer findString:'#!!/bin/sh') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3296
	^ 'application/x-sh'
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3297
    ].
5599
d8300207f839 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  3298
"/    (buffer findString:'#!! /bin/bash') ~~ 0 ifTrue:[
d8300207f839 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  3299
"/        ^ 'application/x-bash'
d8300207f839 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  3300
"/    ].
d8300207f839 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  3301
"/    (buffer findString:'#!!/bin/bash') ~~ 0 ifTrue:[
d8300207f839 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  3302
"/        ^ 'application/x-bash'
d8300207f839 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5598
diff changeset
  3303
"/    ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3304
5598
7aba0b944724 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5597
diff changeset
  3305
    (buffer findString:'<?xml version=') ~~ 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3306
	^ 'text/xml'
5598
7aba0b944724 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5597
diff changeset
  3307
    ].
7aba0b944724 xml - mimeType detection
Claus Gittinger <cg@exept.de>
parents: 5597
diff changeset
  3308
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3309
    ^ nil
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3310
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3311
    "
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3312
     'Makefile' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3313
     '.' asFilename mimeTypeOfContents     
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3314
     '/dev/null' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3315
     '/tmp/.X11-unix/X0' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3316
     'smalltalk.rc' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3317
     'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3318
     '../../rules/stmkmf' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3319
    "
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3320
5012
3134cc1bd02b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5011
diff changeset
  3321
    "Modified: / 19.11.1999 / 15:58:29 / cg"
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3322
!
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3323
3867
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3324
recursiveDirectoryContents
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3325
    "return the contents of the directory and all subdirectories
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3326
     as a collection of strings.
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3327
     This excludes any entries for '.' or '..'.
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3328
     Subdirectory files are included with a relative pathname.
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3329
     Warning: this may take a long time to execute."
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3330
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  3331
    |fileNames dirNames|
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  3332
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  3333
    fileNames := OrderedCollection new.
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  3334
    dirNames := OrderedCollection new.
3867
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3335
    self directoryContents do:[:f |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3336
	(self construct:f) isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3337
	    dirNames add:f
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3338
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3339
	    fileNames add:f
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3340
	]
3867
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3341
    ].
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3342
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  3343
    dirNames do:[:dN |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3344
	|dd subFiles|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3345
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3346
	dd := dN asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3347
	subFiles := (self construct:dN) recursiveDirectoryContents.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3348
	fileNames addAll:(subFiles collect:[:f | dd constructString:f])
3867
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3349
    ].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  3350
    ^ fileNames.
3867
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3351
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3352
    "
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3353
     '.' asFilename recursiveDirectoryContents 
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3354
     '../../clients' asFilename recursiveDirectoryContents 
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3355
    "
91b0773fe260 added #recursiveDirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3865
diff changeset
  3356
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3357
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3358
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3359
!Filename methodsFor:'queries-path & name'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3360
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3361
baseName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3362
    "return my baseName as a string.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3363
     - thats the file/directory name without leading parent-dirs.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3364
     (i.e. '/usr/lib/st/file' asFilename baseName -> 'file'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3365
       and '/usr/lib'         asFilename baseName -> lib).
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3366
     This method does not check if the path is valid
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3367
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3368
     See also: #pathName, #directoryName and #directoryPathName.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3369
     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
  3370
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3371
    |len index sep endIdx|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3372
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3373
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3374
    len := nameString size.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3375
    ((len == 1) and:[(nameString at:1) == sep]) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3376
	^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3377
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3378
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3379
    endIdx := len.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3380
    len > 1 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3381
	(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3382
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3383
    index := nameString lastIndexOf:sep startingAt:len-1.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3384
    index == 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3385
	^ nameString copyTo:endIdx
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3386
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3387
    ^ 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
  3388
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3389
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3390
     '/foo/bar' asFilename baseName  
4903
1487c740eaba comment
Claus Gittinger <cg@exept.de>
parents: 4901
diff changeset
  3391
     '/foo/bar.cc' asFilename baseName  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3392
     '.' asFilename baseName          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3393
     '..' asFilename baseName         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3394
     '../..' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3395
     '../../libbasic' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3396
     '../../libpr' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3397
     '../../libbasic/Object.st' asFilename baseName        
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3398
     '/' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3399
     '\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3400
     'c:\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3401
     '\\idefix' asFilename baseName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3402
    "
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3403
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3404
    "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
  3405
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3406
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3407
directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3408
    "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
  3409
     - 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
  3410
       the receiver is contained in.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3411
     (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
  3412
      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
  3413
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  3414
    ^ self class named:(self directoryName)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3415
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3416
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3417
     '/foo/bar' asFilename directory      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3418
     '/foo/bar' asFilename directoryName  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3419
     '/foo/bar' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3420
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3421
     '.' asFilename directory        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3422
     '..' asFilename directory       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3423
     '../..' asFilename directory     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3424
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3425
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3426
    "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
  3427
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3428
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3429
directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3430
    "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
  3431
     - 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
  3432
       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
  3433
     This method does not check if the path is valid.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3434
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3435
     (i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3436
       and '/usr/lib' asFilename directoryName         -> /usr').
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3437
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3438
     (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
  3439
      a string instead of a Filename instance).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3440
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3441
     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
  3442
     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
  3443
3954
20cc39f4e75c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  3444
    |index sep sepString p rest|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3445
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3446
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3447
    sepString := sep asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3448
    (nameString = sepString) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3449
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3450
	"/ the trivial '/' case
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3451
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3452
	^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3453
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3454
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3455
    "/
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3456
    "/ strip off multiple trailing slashes
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3457
    "/
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3458
    p := nameString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3459
    [p endsWith:sepString] whileTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3460
	(p = sepString) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3461
	    ^ p
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3462
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3463
	p := p copyWithoutLast:1
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3464
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3465
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3466
    "/ strip off trailing components
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3467
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3468
    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
  3469
    index == 0 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3470
	"/ no separator found
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3471
	p = '.' ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3472
	    ^ '..'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3473
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3474
	p = '..' ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3475
	    ^ '../..'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3476
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3477
	^ '.'
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3478
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3479
    rest := p copyFrom:(index+1).
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3480
    rest = '.' ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3481
	^ p , '.'
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3482
    ].
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3483
    rest = '..' ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3484
	^ p , '/..'
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3485
    ].
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3486
    index == 1 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3487
	^ '/'
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3488
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3489
    ^ p copyTo:(index - 1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3490
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3491
    "
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3492
     '/home' asFilename directoryName          
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3493
     '/foo/bar/' asFilename directoryName    
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3494
     '/foo/bar/' asFilename directory      
1049
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
     '/foo/bar' asFilename directoryName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3497
     'bitmaps' asFilename directoryName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3498
     'bitmaps' asFilename directoryPathName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3499
     '.' asFilename directoryName        
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3500
     '.' asFilename directoryPathName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3501
     '..' asFilename directoryName       
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3502
     '..' asFilename directoryPathName       
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3503
     '../..' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3504
     '../..' asFilename directoryPathName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3505
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3506
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3507
    "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
  3508
    "Modified: / 21.10.1998 / 22:52:25 / cg"
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3509
    "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
  3510
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3511
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3512
directoryPathName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3513
    "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
  3514
     - 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
  3515
       the receiver is contained in.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3516
     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
  3517
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  3518
    ^ (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
  3519
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3520
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3521
     '/foo/bar/' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3522
     '/foo/bar' asFilename directoryPathName    
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
     '.' asFilename directoryPathName      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3525
     '.' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3526
     '.' asFilename directory          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3527
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3528
     '..' asFilename directoryPathName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3529
     '..' asFilename directoryName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3530
     '..' asFilename directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3531
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3532
     '../..' asFilename directoryPathName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3533
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3534
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3535
    "Modified: 7.9.1995 / 10:42:13 / claus"
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3536
    "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
  3537
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3538
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3539
filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3540
    "try to complete the receiver filename.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3541
     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
  3542
       it returns a collection of matching filename objects,
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3543
       and leaves changes the receivers filename-string to the longest common
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3544
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3545
     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
  3546
     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
  3547
     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
  3548
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3549
    ^ self filenameCompletionIn:nil
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
     'mak' asFilename filenameCompletion  
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3553
     'Make' asFilename filenameCompletion  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3554
     'Makef' asFilename filenameCompletion;yourself  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3555
     '/u' asFilename filenameCompletion             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3556
     '../../libpr' asFilename inspect filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3557
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3558
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3559
    "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
  3560
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3561
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3562
filenameCompletionIn:aDirectory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3563
    "try to complete the receiver filename.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3564
     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
  3565
       it returns a collection of matching filename objects,
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3566
       and leaves changes the receivers filename-string to the longest common
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3567
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3568
     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
  3569
     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
  3570
     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
  3571
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3572
    |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
  3573
     sepString parentString prefix nMatch nm caseless lcBaseName|
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3574
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3575
    nm := self nameWithSpecialExpansions:nameString.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3576
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3577
    sepString := self class separator asString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3578
    (nm endsWith:sepString) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3579
	^ #()
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3580
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3581
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3582
    parentString := self class parentDirectoryName.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3583
    baseName := self baseName.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3584
    baseName ~= nm ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3585
	prefix := self directoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3586
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3587
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3588
    self isAbsolute ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3589
	dir := self directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3590
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3591
	aDirectory isNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3592
	    dir := self directory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3593
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3594
	    dir := (aDirectory construct:nm) directory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3595
	]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3596
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3597
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3598
    caseless := self class isCaseSensitive not.
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3599
    caseless ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3600
	lcBaseName := baseName asLowercase
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3601
    ].
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3602
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3603
    matching := OrderedCollection new.
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3604
    dir class errorReporter openErrorSignal handle:[:ex|
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3605
	^ #().
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3606
    ] do:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3607
	dir directoryContents do:[:fileName |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3608
	    ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3609
		((caseless and:[fileName asLowercase startsWith:lcBaseName])
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3610
		or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3611
		    matching add:fileName
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3612
		]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3613
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3614
	].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3615
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3616
    (nMatch := matching size) > 1 ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3617
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3618
	 find the longest common prefix
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3619
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3620
	matchLen := baseName size.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3621
	matchLen > matching first size ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3622
	    try := baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3623
	    allMatching := false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3624
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3625
	    try := matching first copyTo:matchLen.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3626
	    allMatching := true.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3627
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3628
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3629
	[allMatching] whileTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3630
	    matching do:[:aName |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3631
		((caseless and:[aName asLowercase startsWith:try asLowercase])
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3632
		or:[caseless not and:[aName startsWith:try]]) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3633
		    allMatching := false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3634
		]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3635
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3636
	    allMatching ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3637
		matchLen <  matching first size ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3638
		    matchLen := matchLen + 1.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3639
		    try := matching first copyTo:matchLen.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3640
		] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3641
		    allMatching := false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3642
		]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3643
	    ] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3644
		try := matching first copyTo:matchLen - 1.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3645
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3646
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3647
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3648
	 and set my name to the last full match
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3649
	"
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3650
	nameString := nm := try
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
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3654
     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
  3655
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3656
    prefix notNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3657
	prefix = sepString ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3658
	    "/ avoid introducing double slashes
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3659
	    prefix := ''
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3660
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3661
	matching := matching collect:[:n | prefix , sepString , n].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3662
	nMatch == 1 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3663
	    nameString := nm := matching first
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3664
	] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3665
	    nMatch > 1 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3666
		nameString := nm := prefix , sepString , nm
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3667
	    ]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3668
	]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3669
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3670
	nMatch == 1 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3671
	    nameString := nm := matching first
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3672
	]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3673
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3674
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3675
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3676
     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
  3677
     (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
  3678
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3679
    ^ matching
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3680
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3681
    " trivial cases:
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3682
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3683
     '../' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3684
     '/' asFilename filenameCompletion      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3685
     '/usr/' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3686
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3687
     'mak' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3688
     'Make' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3689
     'Makef' asFilename filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3690
     '/u' asFilename filenameCompletion             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3691
     '../../libpr' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3692
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3693
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3694
    "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
  3695
    "Modified: / 30.4.1999 / 09:39:52 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  3696
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  3697
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3698
head 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3699
    "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
  3700
     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
  3701
     (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
  3702
      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
  3703
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3704
    ^ self directoryName
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
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3707
     Filename currentDirectory head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3708
     'Makefile' asFilename head    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3709
     '/foo/bar/baz.st' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3710
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3711
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3712
    "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
  3713
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3714
2987
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3715
localPathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3716
    "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
  3717
     but without any volume information.
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3718
     Only makes a difference on MSDOS & VMS systems."
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3719
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3720
    ^ self pathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3721
!
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  3722
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3723
name
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3724
    "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
  3725
     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
  3726
     See also: pathName"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3727
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3728
    self isAbsolute ifTrue:[^ self pathName].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3729
    ^ nameString
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3730
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3731
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3732
     '/foo/bar' asFilename name        
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3733
     '/foo/bar' asFilename pathName    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3734
     '.' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3735
     '.' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3736
     '../..' asFilename name             
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3737
     '../..' asFilename pathName 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3738
     'bitmaps' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3739
     'bitmaps' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3740
     '/tmp/../usr' asFilename name       
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3741
     '/tmp/../usr' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3742
     'source/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3743
     'source/..' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3744
     '/tmp/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3745
     '/tmp/..' asFilename pathName    
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3746
    "
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3747
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  3748
    "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
  3749
!
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3750
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3751
pathName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3752
    "return the full pathname of the file represented by the receiver,
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3753
     as a string. This will not include ..'s. 
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3754
     If the path represented by the receiver does NOT represent a valid path,
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3755
     no compression will be done (for now; this may change).
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3756
     See also: name"
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3757
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3758
    |p|
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  3759
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3760
"/    sep := self class separator.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3761
"/    (nameString startsWith:sep) ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3762
"/        parentName := self class parentDirectoryName.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3763
"/        (nameString findString:parentName) == 0 ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3764
"/            ^ nameString
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3765
"/        ]
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3766
"/    ].
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3767
    p := OperatingSystem pathNameOf:nameString.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3768
    ^ p
2
claus
parents: 1
diff changeset
  3769
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3770
    "
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3771
     '/foo/bar' asFilename pathName  
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3772
     '.' asFilename pathName         
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3773
     '../..' asFilename pathName     
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3774
     '../..' asFilename name           
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3775
     '/tmp/../usr' asFilename pathName   
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3776
     '/././usr' asFilename pathName     
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3777
    "
159
514c749165c3 *** empty log message ***
claus
parents: 132
diff changeset
  3778
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  3779
    "Modified: 27.4.1996 / 18:19:52 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3780
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3781
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3782
physicalPathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3783
    "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
  3784
     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
  3785
     final target. Otherwise, its the receivers pathName itself.
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3786
     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
  3787
     nil is returned."
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3788
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3789
    |t target path|
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3790
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3791
    self isSymbolicLink ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3792
	self exists ifFalse:[^ nil].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3793
	^ self pathName
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3794
    ].
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3795
    t := self.
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3796
    [t isSymbolicLink] whileTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3797
	path := t linkInfo path.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3798
	path isNil ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3799
	    "/ cannot happen
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3800
	    ^ nil
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3801
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3802
	target := (self class named:t directoryName) construct:path.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3803
	target exists ifFalse:[^ nil].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3804
	t := target asFilename
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3805
    ].
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3806
    t exists ifFalse:[^ nil].
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3807
    ^ t pathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3808
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3809
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3810
     '/foo/bar' asFilename physicalPathName  
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3811
     '.' asFilename physicalPathName         
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3812
     '../..' asFilename physicalPathName     
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3813
     'include/abbrev.stc' asFilename physicalPathName           
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3814
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3815
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3816
    "Modified: 21.12.1996 / 15:29:50 / cg"
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3817
!
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  3818
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3819
tail
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3820
    "the files name without directory prefix as a string. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3821
     An alias for baseName, for ST-80 compatiblity."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3822
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3823
    ^ self baseName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3824
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3825
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3826
     Filename currentDirectory tail 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3827
     'Makefile' asFilename tail    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3828
     '/foo/bar/baz.st' asFilename tail  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3829
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3830
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3831
    "Modified: 29.2.1996 / 20:19:50 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3832
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3833
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3834
volume
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3835
    "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
  3836
     This is only used with MSDOS and VMS filenames 
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3837
     - by default (and on unix), an empty string is returned"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3838
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3839
    ^ ''
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3840
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3841
    "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
  3842
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3843
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3844
!Filename methodsFor:'special accessing'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3845
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3846
nameWithSpecialExpansions:aString
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3847
    "return the nameString, expanding any OS specific
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3848
     macros. This should be redefined for OS's where such macros
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3849
     are common.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3850
     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
  3851
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3852
    ^ aString
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3853
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3854
    "Modified: / 21.7.1998 / 10:43:20 / cg"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3855
    "Created: / 21.7.1998 / 10:45:58 / cg"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3856
!
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3857
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3858
osName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3859
    "special - return the OS's name for the receiver."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3860
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3861
    self isDirectory ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3862
	^ self osNameForDirectory
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3863
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3864
    ^ self osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3865
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3866
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3867
osNameForAccess
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3868
    "internal - return the OS's name for the receiver to
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3869
     access its fileInfo.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3870
     This may be redefined for systems, where a special suffix must be
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3871
     added in order to access directories (or others) as a file.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3872
     (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
  3873
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3874
    ^ nameString
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3875
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3876
    "Modified: / 21.7.1998 / 10:40:40 / cg"
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3877
!
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3878
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3879
osNameForDirectory
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  3880
    "internal - return the OS's name for the receiver to
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3881
     access it as a directory."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3882
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3883
    ^ nameString
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  3884
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  3885
    "Modified: / 12.8.1998 / 14:44:32 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3886
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3887
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3888
osNameForDirectoryContents
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  3889
    "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
  3890
     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
  3891
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3892
    ^ self osNameForDirectory
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3893
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3894
    "Created: / 3.8.1998 / 21:36:06 / cg"
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  3895
    "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
  3896
!
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  3897
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3898
osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3899
    "internal - return the OS's name for the receiver to
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3900
     access it as a file."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3901
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3902
    ^ nameString
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3903
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3904
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3905
!Filename methodsFor:'suffixes'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3906
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3907
hasSuffix:aSuffixString
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3908
    "return true if my suffix is the same as aString.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3909
     This cares for systems, where case is ignored in filenames"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3910
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3911
    |mySuffix|
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3912
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3913
    mySuffix := self suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3914
    self class isCaseSensitive ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3915
	^ mySuffix = aSuffixString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3916
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3917
    ^ mySuffix asLowercase = aSuffixString asLowercase
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3918
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3919
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3920
     'abc.st' asFilename hasSuffix:'st'   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3921
     'abc.ST' asFilename hasSuffix:'st'   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3922
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3923
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3924
    "Modified: 7.9.1997 / 02:55:25 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3925
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3926
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3927
prefixAndSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3928
    "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
  3929
     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
  3930
     the prefix everything before, except for the period.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3931
     The directory name part is stripped off (i.e. the returned prefix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3932
     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
  3933
     (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
  3934
     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
  3935
     See also: #withoutSuffix and #withSuffix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3936
     Notice: 
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3937
	there is currently no known system which uses other than
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3938
	the period character as suffixCharacter."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3939
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3940
    |nm idx|
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3941
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3942
    nm := self baseName.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3943
    idx := nm lastIndexOf:(self class suffixSeparator).
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3944
    idx == 0 ifTrue:[
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3945
	^ Array with:nm with:''
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3946
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3947
    ^ Array 
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3948
	with:(nm copyTo:idx-1)
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3949
	with:(nm copyFrom:idx+1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3950
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3951
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3952
     'abc.st' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3953
     'abc' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3954
     'a.b.c' asFilename prefixAndSuffix 
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3955
     '/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
  3956
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3957
     |parts| 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3958
     parts := 'Object.st' asFilename prefixAndSuffix.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3959
     ((parts at:1) , '.o') asFilename   
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3960
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3961
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3962
    "Modified: 7.9.1995 / 11:15:42 / claus"
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3963
    "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
  3964
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3965
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3966
suffix
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3967
    "return my suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3968
     The suffix is the namepart after the final period character,
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3969
     or the empty string, if the name does not contain a period."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3970
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3971
    ^ self prefixAndSuffix at:2
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3972
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3973
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3974
     'abc.st' asFilename suffix   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3975
     'abc' asFilename suffix      
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3976
     'a.b.c' asFilename suffix    
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3977
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3978
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3979
    "Modified: 7.9.1995 / 11:09:03 / claus"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3980
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3981
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3982
withSuffix:aSuffix
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3983
    "return a new filename for the receivers name with a different suffix.
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  3984
     If the name already has a suffix, the new suffix replacaes it;
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  3985
     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
  3986
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3987
    ^ self class named:
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3988
	(self withoutSuffix name 
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3989
	 , self class suffixSeparator asString 
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  3990
	 , aSuffix asString)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3991
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3992
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3993
     'abc.st' asFilename withSuffix:'o'         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3994
     'abc' asFilename withSuffix:'o'             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3995
     'a.b.c' asFilename withSuffix:'o'            
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3996
     '/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
  3997
     '/foo/bar/baz.c' asFilename withSuffix:'st'   
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3998
     '/foo/bar.c/baz.c' asFilename withSuffix:'st'   
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  3999
     '/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
  4000
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4001
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4002
    "Modified: 7.9.1995 / 11:15:42 / claus"
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4003
    "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
  4004
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4005
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4006
withoutSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4007
    "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
  4008
     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
  4009
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4010
    |nm idx idxFromEnd|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4011
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4012
    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
  4013
    idx := nm lastIndexOf:(self class suffixSeparator).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4014
    (idx == 0) ifTrue:[^ self].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4015
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  4016
    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
  4017
    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
  4018
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4019
    ^ 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
  4020
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4021
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4022
     'abc.st' asFilename withoutSuffix         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4023
     '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
  4024
     '/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
  4025
     '/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
  4026
     './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
  4027
     './abc.d' asFilename withoutSuffix            
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4028
     'a.b.c' asFilename withoutSuffix           
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4029
     '/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
  4030
     '/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
  4031
     '/foo/bar.x/baz' asFilename withoutSuffix     
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4032
     '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix   
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4033
     '/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
  4034
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4035
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4036
    "Modified: 7.9.1995 / 11:15:42 / claus"
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  4037
    "Modified: 3.7.1996 / 10:49:58 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4038
! !
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4039
5597
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4040
!Filename methodsFor:'testing'!
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4041
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4042
isFilename
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4043
    "return true, if the receiver is some kind of filename;
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4044
     false is returned here - the method is redefined from Object."
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4045
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4046
    ^true
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4047
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4048
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4049
! !
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  4050
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4051
!Filename class methodsFor:'documentation'!
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  4052
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  4053
version
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  4054
    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.202 2001-11-05 09:51:43 cg Exp $'
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  4055
! !
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4056
Filename initialize!