Filename.st
author Stefan Vogel <sv@exept.de>
Wed, 23 Feb 2005 12:54:19 +0100
changeset 8754 1efa34b61e9b
parent 8741 d3f70a668435
child 8769 d85a61c092ee
permissions -rw-r--r--
Simpler delegation. ConcreteClass may not be nil or Filename after initialization.
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
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    49
        '/fee/foo/foe' asFilename exists     
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    50
        '/not_existing' asFilename isDirectory 
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
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
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    57
        'Makefile' asFilename readStream
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    58
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    59
        'newFile' asFilename writeStream
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    60
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
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
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    70
    Since Filenames have different semantics under different operating systems,
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    71
    class methods are delegated to concrete implementations in various subclasses like
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    72
    UnixFilename, PCFilename, ...
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    73
    The delegation is implemented in a way, so that some methods of
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    74
    specific OS Filenames might be used, even if ST/X is currently running 
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    75
    on a different OS (as long as the method does not depend on the OperatingSystem class).
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    76
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1225
diff changeset
    77
    [author:]
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    78
        Claus Gittinger
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    79
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1225
diff changeset
    80
    [see also:]
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    81
        String
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    82
        FileStream DirectoryStream PipeStream Socket
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    83
        OperatingSystem
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    84
        Date Time
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    85
"
360
claus
parents: 359
diff changeset
    86
!
claus
parents: 359
diff changeset
    87
claus
parents: 359
diff changeset
    88
examples
claus
parents: 359
diff changeset
    89
"
claus
parents: 359
diff changeset
    90
    does a file/directory exist ?:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    91
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    92
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    93
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    94
	f := 'foobar' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    95
	^ f exists  
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
    96
									[exEnd]
360
claus
parents: 359
diff changeset
    97
claus
parents: 359
diff changeset
    98
claus
parents: 359
diff changeset
    99
    is it a directory ?:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   100
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   101
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   102
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   103
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   104
	^ f isDirectory.   
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   105
									[exEnd]
360
claus
parents: 359
diff changeset
   106
claus
parents: 359
diff changeset
   107
        
claus
parents: 359
diff changeset
   108
    get the working directory:
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
	^ Filename defaultDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   111
									[exEnd]
360
claus
parents: 359
diff changeset
   112
claus
parents: 359
diff changeset
   113
claus
parents: 359
diff changeset
   114
    get a files full pathname 
claus
parents: 359
diff changeset
   115
    (caring for relative names or symbolic links):
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   116
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   117
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   118
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   119
	f := '..' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   120
	^ f pathName  
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   121
									[exEnd]
360
claus
parents: 359
diff changeset
   122
claus
parents: 359
diff changeset
   123
claus
parents: 359
diff changeset
   124
    get a directories directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   125
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   126
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   127
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   128
	f := Filename defaultDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   129
	^ f directory 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   130
									[exEnd]
360
claus
parents: 359
diff changeset
   131
claus
parents: 359
diff changeset
   132
claus
parents: 359
diff changeset
   133
    get a files directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   134
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   135
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   136
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   137
	f := './smalltalk' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   138
	^ f directory 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   139
									[exEnd]
360
claus
parents: 359
diff changeset
   140
claus
parents: 359
diff changeset
   141
claus
parents: 359
diff changeset
   142
    getting access & modification times:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   143
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   144
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   145
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   146
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   147
	^ f dates
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   148
									[exEnd]
360
claus
parents: 359
diff changeset
   149
claus
parents: 359
diff changeset
   150
    access time only:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   151
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   152
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   153
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   154
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   155
	^ f dates at:#accessed  
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   156
									[exEnd]
360
claus
parents: 359
diff changeset
   157
        
claus
parents: 359
diff changeset
   158
claus
parents: 359
diff changeset
   159
    getting all information on a file/directory:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   160
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   161
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   162
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   163
	f := '/tmp' asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   164
	^ f info
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   165
									[exEnd]
360
claus
parents: 359
diff changeset
   166
claus
parents: 359
diff changeset
   167
claus
parents: 359
diff changeset
   168
    getting a temporary file (unique name):
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   169
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   170
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   171
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   172
	f := Filename newTemporary.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   173
	^ f    
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   174
									[exEnd]
360
claus
parents: 359
diff changeset
   175
claus
parents: 359
diff changeset
   176
    creating, writing, reading and removing a temporary file:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   177
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   178
	|f writeStream readStream|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   179
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   180
	f := Filename newTemporary.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   181
	writeStream := f writeStream.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   182
	writeStream nextPutAll:'hello world'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   183
	writeStream cr.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   184
	writeStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   185
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   186
	'contents (as seen by unix''s cat command:' printNL.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   187
	OperatingSystem executeCommand:('cat ' , f pathName).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   188
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   189
	readStream := f readStream.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   190
	Transcript showCR:'contents as seen by smalltalk:'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   191
	Transcript showCR:(readStream upToEnd).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   192
	readStream close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   193
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   194
	f delete.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   195
									[exEnd]
360
claus
parents: 359
diff changeset
   196
        
claus
parents: 359
diff changeset
   197
claus
parents: 359
diff changeset
   198
    getting a directories contents:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   199
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   200
	|f files|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   201
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   202
	f := Filename currentDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   203
	files := f directoryContents.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   204
	Transcript showCR:'the files are:'.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   205
	Transcript showCR:(files printString).
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   206
									[exEnd]
360
claus
parents: 359
diff changeset
   207
claus
parents: 359
diff changeset
   208
claus
parents: 359
diff changeset
   209
    editing a file:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   210
									[exBegin]
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   211
	|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   212
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   213
	f := Filename newTemporary.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   214
	(f writeStream) nextPutAll:'hello world'; close.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   215
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   216
	f edit
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   217
									[exEnd]
360
claus
parents: 359
diff changeset
   218
"
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   219
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   220
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   221
!Filename class methodsFor:'initialization'!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   222
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   223
initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   224
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   225
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   226
    ConcreteClass isNil ifTrue:[
7702
aa9eedcf00d2 only init once.
Claus Gittinger <cg@exept.de>
parents: 7697
diff changeset
   227
        self initializeConcreteClass
aa9eedcf00d2 only init once.
Claus Gittinger <cg@exept.de>
parents: 7697
diff changeset
   228
    ].
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   229
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
     self initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   232
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   233
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   234
    "Created: 7.9.1997 / 23:32:55 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   235
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   236
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   237
initializeConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   238
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   239
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   240
    OperatingSystem isUNIXlike ifTrue:[
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   241
        ConcreteClass := UnixFilename
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   242
    ] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   243
        ConcreteClass := PCFilename
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   244
    ] ifFalse:[OperatingSystem isVMSlike ifTrue:[
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   245
        ConcreteClass := OpenVMSFilename
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   246
    ] ifFalse:[
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   247
        self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'.
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   248
    ]]].
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   249
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   250
    ConcreteClass isNil ifTrue:[
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   251
        self error:'Filename: Missing concrete Filename class'.
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   252
    ].
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   253
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   254
    "
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   255
     self initializeConcreteClass
2906
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
    "Modified: 7.9.1997 / 23:32:37 / cg"
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
reinitialize
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   262
    "initialize for the OS we are running on (after a restart)"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   263
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   264
    self initializeConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   265
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   266
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   267
     self reinitialize
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   268
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   269
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   270
    "Created: 7.9.1997 / 23:33:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   271
! !
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   272
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   273
!Filename class methodsFor:'instance creation'!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   274
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   275
currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   276
    "return a filename for the current directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   277
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   278
    self == Filename ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   279
        ^ ConcreteClass currentDirectory
3959
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
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   283
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   284
    ^ self named:'.'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   285
    "/ ^ self named:('.' asFilename pathName)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   286
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   287
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   288
     Filename currentDirectory 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   289
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   290
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   291
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   292
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   293
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   294
currentDirectoryName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   295
    "return a filename for the current directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   296
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   297
    self == Filename ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   298
        ^ ConcreteClass currentDirectoryName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   299
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   300
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   301
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
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
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   305
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   306
     Filename currentDirectoryName    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   307
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   308
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   309
    "Modified: / 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   310
    "Created: / 21.10.1998 / 17:49:57 / cg"
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
defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   314
    "ST80 compatibility: same as currentDirectory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   315
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   316
    ^ self currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   317
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   318
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   319
     Filename defaultDirectory 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   320
    "
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
defaultDirectoryName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   324
    "ST80 compatibility: return the defaultDirectories name (as a string)"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   325
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   326
    ^ self defaultDirectory name
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   327
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   328
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   329
     Filename defaultDirectoryName 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   330
    "
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
findDefaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   334
    "same as #defaultDirectory for ST80 compatibility"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   335
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   336
    ^ self defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   337
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   338
    "Created: 20.6.1997 / 17:00:29 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   339
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   340
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   341
fromComponents:aCollectionOfDirectoryNames
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   342
    "create & return a new filename from components given in
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   343
     aCollectionOfDirectoryNames. If the first component is the name of the
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   344
     root directory (i.e. '/') an absolute path-filename is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   345
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   346
    self == Filename ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   347
        ^ ConcreteClass fromComponents:aCollectionOfDirectoryNames
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   348
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   349
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   350
    ^ self named:(self nameFromComponents:aCollectionOfDirectoryNames)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   351
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   352
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   353
     Filename fromComponents:#('/' 'foo' 'bar' 'baz')  
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   354
     PCFilename fromComponents:#('/' 'foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   355
     UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   356
     OpenVMSFilename fromComponents:#('foo' 'bar' 'baz')
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   357
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   358
     Filename fromComponents:#('foo' 'bar' 'baz')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   359
     Filename fromComponents:#('/')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   360
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   361
     Filename fromComponents:
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   362
         (Filename components:('.' asFilename pathName))
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   363
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   364
     Filename fromComponents:
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   365
         (Filename components:('.' asFilename name)) 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   366
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   367
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   368
    "Modified: 8.9.1997 / 00:23:16 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   369
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   370
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   371
fromUser
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   372
    "show a box to enter a filename. 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   373
     Return a filename instance or nil (if cancel was pressed)."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   374
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   375
    |name|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   376
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   377
    name := Dialog 
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   378
        requestFileName:'filename:' 
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   379
        default:nil
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   380
        fromDirectory:(FileSelectionBox lastFileSelectionDirectory).
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   381
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   382
    name notEmptyOrNil ifTrue:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   383
        ^ self named:name
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   384
    ].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   385
    ^ nil
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   386
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   387
    "
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   388
     Filename fromUser 
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: 19.4.1996 / 13:57:44 / 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
homeDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   395
    "return your homeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   396
     Some OperatingSystems do not support this - on those, the defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   397
     (which is the currentDirectory) is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   398
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   399
    |s|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   400
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   401
    s := OperatingSystem getHomeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   402
    s isNil ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
   403
	^ self defaultDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   404
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   405
    ^ self named:s
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   406
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   407
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   408
     Filename homeDirectory        
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   409
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   410
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   411
    "Modified: 8.9.1997 / 00:25:23 / cg"
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
named:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   415
    "return a filename for a directory named aString.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   416
     This is the same as 'aString asFilename'."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   417
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   418
    self == Filename ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   419
        ^ ConcreteClass named:aString
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   420
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   421
    ^ self basicNew setName:aString
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   422
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   423
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   424
     Filename named:'/tmp/fooBar'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   425
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   426
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   427
    "Modified: 7.9.1997 / 23:30:06 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   428
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   429
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   430
newTemporary
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   431
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   432
     The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   433
     unix process id, and nn is a unique number, incremented with every
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   434
     call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   435
     If any of the environment variables ST_TMPDIR or TMPDIR is set, 
4757
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   436
     its value defines the temp directory.
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   437
     Notice, that no file is created by this - only a unique name
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   438
     is generated."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   439
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   440
    ^ self newTemporaryIn:self tempDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   441
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   442
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   443
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   444
     Filename newTemporary     
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   445
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   446
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   447
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   448
    "Modified: 7.3.1996 / 14:51:33 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   449
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   450
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   451
newTemporaryIn:aDirectoryPrefix
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   452
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   453
     The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn',
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   454
     where xx is our unix process id, and nn is a unique number, incremented 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   455
     with every call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   456
     Notice: only a unique filename object is created and returned - no physical
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   457
     file is created by this method (i.e. you have to send #writeStream or
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   458
     whatever to it in order to really create something).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   459
     See also: #newTemporary which looks for a good temp directory."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   460
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   461
    ^ self newTemporaryIn:aDirectoryPrefix nameTemplate:self tempFileNameTemplate
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   462
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   463
    "temp files in '/tmp':
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   464
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   465
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   466
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   467
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   468
    "temp files somewhere 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   469
     (not recommended - use above since it can be controlled via shell variables):
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   470
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   471
     UnixFilename newTemporaryIn:'/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   472
     UnixFilename newTemporaryIn:'/tmp'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   473
     UnixFilename newTemporaryIn:'/usr/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   474
     UnixFilename newTemporaryIn:'/'  
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
    "a local temp file:
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   478
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   479
     Filename newTemporaryIn:''         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   480
     Filename newTemporaryIn:nil         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   481
     Filename newTemporaryIn:'.'         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   482
     Filename newTemporaryIn:('source' asFilename) 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   483
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   484
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   485
    "Modified: / 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   486
    "Modified: / 11.8.1998 / 22:51:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   487
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   488
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   489
newTemporaryIn:aDirectoryPrefix nameTemplate:template
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   490
    "return a new unique filename - use this for temporary files.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   491
     The filenames returned are in aDirectoryPrefix and named after the given template,
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   492
     in which %1 and %2 are expanded to the unix process id, and a unique number, incremented 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   493
     with every call to this method respectively.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   494
     Notice: only a unique filename object is created and returned - no physical
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   495
     file is created by this method (i.e. you have to send #writeStream or
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   496
     whatever to it in order to really create something).
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   497
     See also: #newTemporary which looks for a good temp directory."
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   498
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   499
    |nameString newTempFilename|
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   500
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   501
    self == Filename ifTrue:[
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   502
        ^ ConcreteClass newTemporaryIn:aDirectoryPrefix nameTemplate:template
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   503
    ].
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   504
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   505
    "although the above allows things to be redefined in concrete classes,
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   506
     the following should work on all systems ..."
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   507
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   508
    NextTempFilenameIndex isNil ifTrue:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   509
        NextTempFilenameIndex := 1.
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   510
    ].
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   511
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   512
    [
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   513
        nameString := template bindWith:OperatingSystem getProcessId with:NextTempFilenameIndex.
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   514
        NextTempFilenameIndex := NextTempFilenameIndex + 1.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   515
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   516
        (aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   517
            newTempFilename := aDirectoryPrefix asFilename construct:nameString
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   518
        ] ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   519
            newTempFilename := self named:nameString
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   520
        ]
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   521
    ] doWhile:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   522
        "care for existing leftOver tempFiles
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   523
         from a previous boot of the OS
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   524
         i.e. my pid could be the same as when executed
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   525
         the last time before system reboot ...)"
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   526
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   527
        newTempFilename exists
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   528
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   529
    ^ newTempFilename
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   530
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   531
    "temp files in '/tmp':
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   532
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   533
     Filename newTemporary    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   534
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   535
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   536
    "temp files somewhere 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   537
     (not recommended - use above since it can be controlled via shell variables):
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   538
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   539
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   540
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'  
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   541
     UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2'    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   542
     UnixFilename newTemporaryIn:'/'        nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   543
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   544
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   545
    "a local temp file:
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   546
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   547
     Filename newTemporaryIn:''             nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   548
     Filename newTemporaryIn:nil            nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   549
     Filename newTemporaryIn:'.'            nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   550
     Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   551
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   552
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   553
    "Modified: / 7.9.1995 / 10:48:31 / claus"
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   554
    "Modified: / 11.8.1998 / 22:51:43 / cg"
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   555
!
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   556
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   557
nullDevice
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   558
    "return the filename of the nullDevice (if available).
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   559
     returns nil, if the OperatingSystem does not support this."
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   560
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   561
    |s|
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   562
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   563
    s := self nullFilename.
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   564
    s isNil ifTrue:[
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   565
        ^ nil
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   566
    ].
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   567
    ^ self named:s
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   568
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   569
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   570
     Filename nullDevice
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   571
     UnixFilename nullDevice
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   572
     PCFilename nullDevice
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   573
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   574
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   575
    "Created: / 19.5.1999 / 12:24:26 / cg"
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   576
!
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   577
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   578
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   579
    "create & return a new filename from components given in
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   580
     aCollectionOfDirectoryNames on a host named remoteHostString. 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   581
     An absolute network-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   582
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   583
    self == Filename ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   584
        ^ ConcreteClass remoteHost:remoteHostString 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   585
                        rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   586
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   587
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   588
    self error:'remote hosts are not supported by OS'.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   589
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   590
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   591
rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   592
    "create & return a new filename from components given in
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   593
     aCollectionOfDirectoryNames. 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   594
     An absolute path-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   595
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   596
    |sep s|
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   597
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   598
    self == Filename ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   599
        ^ ConcreteClass rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   600
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   601
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   602
    "/ fallBack - works on Unix & MSDOS
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   603
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   604
    sep := self separatorString.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   605
    s := WriteStream on:''.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   606
    aCollectionOfDirectoryNames do:[:component |
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   607
        component ~= sep ifTrue:[
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   608
            s nextPutAll:sep; nextPutAll:component
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   609
        ]
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   610
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   611
    s := s contents.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   612
    s size == 0 ifTrue:[s := sep].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   613
    ^ self named:s
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   614
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   615
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   616
     Filename rootComponents:#('/' 'foo' 'bar' 'baz')
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   617
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   618
     Filename rootComponents:#('foo' 'bar' 'baz')  
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   619
     PCFilename rootComponents:#('foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   620
     UnixFilename rootComponents:#('foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   621
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   622
     Filename rootComponents:#('/')  
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   623
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   624
     Filename rootComponents:
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   625
         (Filename components:('.' asFilename pathName))
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   626
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   627
     Filename rootComponents:
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   628
         (Filename components:('.' asFilename name)) 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   629
    "
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   630
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   631
    "Modified: 8.9.1997 / 00:23:16 / cg"
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   632
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   633
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   634
rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   635
    "return a filename for the root directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   636
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   637
    self == Filename ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   638
        ^ ConcreteClass rootDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   639
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   640
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   641
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   642
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   643
    ^ self named:(self separatorString)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   644
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   645
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   646
     Filename rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   647
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   648
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   649
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   650
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   651
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   652
rootDirectoryOnVolume:aVolumeName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   653
    "return a filename for the root directory on some volume"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   654
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   655
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   656
        ^ ConcreteClass rootDirectoryOnVolume:aVolumeName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   657
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   658
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   659
    "/ fallBack - works on Unix (not on MSDOS or VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   660
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   661
    ^ self rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   662
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   663
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   664
     Filename rootDirectoryOnVolume:'/phys/idefix'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   665
     Filename rootDirectoryOnVolume:'d:'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   666
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   667
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   668
    "Modified: / 5.10.1998 / 12:45:39 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   669
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   670
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   671
tempDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   672
    "return the temp directory as a filename.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   673
     If any of the environment variables STX_TMPDIR, ST_TMPDIR,
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   674
     TMPDIR or TEMPDIR is set, its value defines the name, 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   675
     otherwise, '/tmp' is used. (at least on unix ...).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   676
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   677
     Notice: do not hardcode '/tmp' into your programs - things may be
7064
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
   678
             different on other OS's. Also, the user may want to set the
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
   679
             TMPDIR environment variable to have her temp files somewhere else.
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
   680
             (especially on SUNOS, the root partition is ALWAYS too small ..."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   681
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   682
    |tempDir|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   683
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   684
    #('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar |
7064
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
   685
        tempDir isNil ifTrue:[
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
   686
            tempDir := OperatingSystem getEnvironment:envVar.
8660
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   687
            tempDir notNil ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   688
                tempDir := self named:tempDir.
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   689
                tempDir exists ifFalse:[
8660
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   690
                    tempDir := nil.
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   691
                ].
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   692
            ].
7064
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
   693
        ].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   694
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   695
    tempDir isNil ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   696
        tempDir := self named:self defaultTempDirectoryName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   697
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   698
    ^ tempDir
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   699
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   700
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   701
     Filename tempDirectory           
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   702
     Filename tempDirectory pathName   
8660
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   703
     Filename tempDirectory exists    
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   704
     Filename tempDirectory isWritable   
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   705
     (Filename tempDirectory construct:'foo') makeDirectory   
8660
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   706
     (Filename tempDirectory construct:'foo') remove   
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   707
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   708
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   709
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   710
    "Created: 7.3.1996 / 14:51:18 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   711
    "Modified: 8.9.1997 / 00:08:11 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   712
! !
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   713
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   714
!Filename class methodsFor:'defaults'!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   715
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   716
concreteClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   717
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   718
     OperatingSystems; concreteClass is supposed to return an appropriate class."
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   719
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   720
    ^ ConcreteClass ? self
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   721
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   722
    "Created: 14.2.1997 / 16:36:13 / cg"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   723
    "Modified: 7.9.1997 / 23:29:20 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   724
!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   725
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   726
defaultClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   727
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   728
     OperatingSystems; defaultClass is supposed to return an appropriate class"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   729
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   730
    ^ ConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   731
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   732
    "Modified: 8.9.1997 / 00:36:01 / cg"
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   733
!
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   734
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   735
defaultTempDirectoryName
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   736
    "return the default temp directory as a filename.
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   737
     This is used, if no special preferences were defined in
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   738
     any of the TEMP-environment variables (see tempDirectory)."
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   739
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   740
    self == Filename ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   741
        ^ ConcreteClass defaultTempDirectoryName
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   742
    ].
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   743
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   744
    ^ '/tmp'
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   745
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   746
    "
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   747
     Filename defaultTempDirectoryName           
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   748
    "
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   749
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   750
    "Modified: 7.9.1995 / 10:48:31 / claus"
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   751
    "Created: 7.3.1996 / 14:51:18 / cg"
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   752
    "Modified: 8.9.1997 / 00:24:53 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   753
! !
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   754
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   755
!Filename class methodsFor:'misc'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   756
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   757
canonicalize:aPathString
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   758
    "convert the argument, aPathString to a good format.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   759
     This should eliminate useless directory components (i.e. '././')
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   760
     and useless tree walks (i.e. '../foo/..')."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   761
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   762
    |comps newComps parentName currentName rootName|
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   763
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   764
    parentName := self parentDirectoryName.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   765
    currentName := self currentDirectoryName.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   766
    rootName := self rootDirectory name.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   767
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   768
    comps := self components:aPathString.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   769
    newComps := OrderedCollection new.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   770
    comps do:[:eachComponent |
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   771
        eachComponent = currentName ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   772
            eachComponent = parentName ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   773
               (newComps isEmpty 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   774
               or:[ newComps = (Array with:rootName) 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   775
               or:[newComps last = parentName]]) ifTrue:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   776
                   newComps add:eachComponent
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   777
               ] ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   778
                   newComps removeLast
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   779
               ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   780
            ] ifFalse:[
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   781
                newComps add:eachComponent
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   782
            ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   783
        ]
7666
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   784
    ]. 
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   785
    "/ add current Directory if empty
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   786
    newComps isEmpty ifTrue:[
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   787
        newComps add:currentName.
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   788
    ].
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   789
    ^ self nameFromComponents:newComps
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   790
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   791
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   792
     Filename canonicalize:'/etc/../etc'      
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   793
     Filename canonicalize:'/home/cg/../'     
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   794
     Filename canonicalize:'/home/cg/../././'  
7666
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   795
     Filename canonicalize:'./home/cg/../././'     
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   796
     Filename canonicalize:'/home/././cg/../././'   
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   797
     Filename canonicalize:'/home/././cg/././'    
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   798
     Filename canonicalize:'/home/cg/../../..'    
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   799
     Filename canonicalize:'cg/../../..'    
7666
4cfcb1c3d0cc cononilize current directory '.' no empty filename anymore
penk
parents: 7596
diff changeset
   800
     Filename canonicalize:'./'      
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
   801
     Filename canonicalize:'/home/.'   
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   802
    "
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   803
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   804
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   805
filterSeps:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   806
    "ST80 compatibility:
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   807
     filter out (invalid) separators in aFilenameString.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   808
     We recommend using #makeLegalFilename"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   809
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   810
    ^ aFilenameString copyReplaceAll:(Character space) with:$_.
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   811
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   812
    "Created: / 1.11.1997 / 12:39:50 / cg"
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   813
    "Modified: / 18.7.1998 / 22:53:24 / cg"
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   814
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   815
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   816
suggest:aFilenameString 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   817
    "return a fileNamestring based on the argument, 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   818
     which is legal on the current platform."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   819
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   820
    ^ self canonicalize:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   821
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   822
    "Created: / 1.11.1997 / 12:42:39 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   823
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   824
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
   825
!Filename class methodsFor:'queries'!
2
claus
parents: 1
diff changeset
   826
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   827
components:aString
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   828
    "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
   829
     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
   830
     the final component.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   831
     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
   832
     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
   833
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   834
    |sep f vol rest components|
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   835
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   836
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   837
        ^ ConcreteClass components:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   838
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   839
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   840
    "/ the following works on Unix & MSDOS (but not on openVMS)
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   841
    "/ However, MSDOS drive-letters and network drives are
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   842
    "/ not correctly handled here.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   843
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   844
    sep := self separator.
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   845
    f := aString asFilename.
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   846
    vol := f volume.
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   847
    vol size ~~ 0 ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   848
        rest := f localPathName.
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   849
    ] ifFalse:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   850
        rest := aString
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   851
    ].
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   853
    components := rest asCollectionOfSubstringsSeparatedBy:sep.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   854
    components first isEmpty ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   855
        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
   856
    ].
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   857
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   858
    "/ prepend volume to first component (the root directory)
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   859
    vol size ~~ 0 ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   860
        components at:1 put:(vol , (components at:1)).
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   861
    ].
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   862
    components last isEmpty ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   863
        ^ components copyWithoutLast:1
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   864
    ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   865
    ^ components
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   866
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   867
    "
3373
d950241b9e80 bugFix:
ca
parents: 3302
diff changeset
   868
     Filename components:'/foo/bar/baz'      
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   869
     Filename components:'/'     
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   870
     Filename components:'foo/bar/baz'  
2503
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   871
     Filename components:'foo/bar'  
279c9f6a99c9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2175
diff changeset
   872
     Filename components:'foo'     
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   873
     Filename components:'/foo'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   874
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   875
     Filename components:'\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   876
     Filename components:'\foo'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   877
     Filename components:'\foo\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   878
     Filename components:'\foo\bar'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   879
     Filename components:'\foo\bar\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   880
     Filename components:'c:'        
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   881
     Filename components:'c:\'       
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   882
     Filename components:'c:\foo'      
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   883
     Filename components:'c:\foo\'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   884
     Filename components:'c:\foo\bar'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   885
     Filename components:'c:\foo\bar\'  
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   886
     Filename components:'\\idefix'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   887
     Filename components:'\\idefix\home'     
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   888
     Filename components:'\\idefix\home\bar'    
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   889
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   890
3852
0ebc19d9f28b volume handling.
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   891
    "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
   892
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
   893
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   894
directorySuffix
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   895
    "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
   896
     The default is nil here, redefined for VMS"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   897
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   898
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   899
        ^ ConcreteClass directorySuffix
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   900
    ].
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   901
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   902
    ^ nil
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   903
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
   904
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   905
errorReporter
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   906
    "who knows the signals to report errors?"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   907
        
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   908
    ^ FileStream
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   909
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   910
    "Created: 2.7.1996 / 12:30:25 / stefan"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   911
!
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
   912
440
claus
parents: 422
diff changeset
   913
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock
claus
parents: 422
diff changeset
   914
    "perform filename completion on aString in some directory;
claus
parents: 422
diff changeset
   915
     return the longest matching filename prefix as a string.
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   916
     The boolean directoriesOnly and filesOnly control respectively,
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   917
     if only directories or only regular files are to be considered for completion.
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   918
     If multiple files match, the exception block aBlock is evaluated with a 
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
   919
     filename representing the directory (where the match was done) as argument.
440
claus
parents: 422
diff changeset
   920
     (this may be different from the inDirectory argument, if aString is absolute
claus
parents: 422
diff changeset
   921
      or starts with ../)"
claus
parents: 422
diff changeset
   922
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   923
    self == Filename ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   924
        ^ ConcreteClass 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   925
            filenameCompletionFor:aString 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   926
            directory:inDirectory       
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   927
            directoriesOnly:directoriesOnly 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   928
            filesOnly:filesOnly 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   929
            ifMultiple:aBlock
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   930
    ].
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   931
    ^ self filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock forMultipleDo:nil
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   932
!
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   933
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   934
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock forMultipleDo:aMultipleBlock
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   935
    "perform filename completion on aString in some directory;
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   936
     return the longest matching filename prefix as a string.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   937
     The boolean directoriesOnly and filesOnly control respectively,
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   938
     if only directories or only regular files are to be considered for completion.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   939
     If multiple files match, the exception block aBlock is evaluated with a 
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   940
     filename representing the directory (where the match was done) as argument and the aMultipleBlock
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   941
     is evaluated with both the directory (where the match was done) and the matchSet
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   942
     (list of matched filenames)  as arguments.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   943
     (this may be different from the inDirectory argument, if aString is absolute
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   944
      or starts with ../)"
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   945
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   946
    |s f matchSet nMatch name dir isAbsolute sep|
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   947
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   948
    aString size == 0 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   949
        aBlock value:(self named:'.').
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   950
        ^ ''
440
claus
parents: 422
diff changeset
   951
    ].
claus
parents: 422
diff changeset
   952
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   953
    sep := self separator.
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   954
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   955
    "/ 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
   956
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
   957
    f := self named:aString.
3854
a13d0d489365 care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
   958
    isAbsolute := f isAbsolute.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   959
    matchSet := f filenameCompletionIn:inDirectory.  "/ BAD DESIGN: has side effect on f
440
claus
parents: 422
diff changeset
   960
    dir := f directory.
claus
parents: 422
diff changeset
   961
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   962
    matchSet := matchSet select:[:aFilename |
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   963
        |f isDir|
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   964
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   965
        isAbsolute ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   966
            f := aFilename asFilename
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   967
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   968
            f := (dir construct:aFilename). 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   969
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   970
        isDir := f isDirectory.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   971
        directoriesOnly ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   972
            isDir
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   973
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   974
            filesOnly ifTrue:[    
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   975
                isDir not
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   976
            ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   977
                true
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   978
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   979
        ]
440
claus
parents: 422
diff changeset
   980
    ].
claus
parents: 422
diff changeset
   981
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
   982
    f := f asCanonicalizedFilename.
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   983
        (nMatch := matchSet size) ~~ 1 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   984
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   985
         more than one possible completion -
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   986
        "
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   987
        aMultipleBlock notNil ifTrue:[
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   988
            aMultipleBlock value:f value:matchSet.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
   989
        ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
   990
        aBlock value:f
440
claus
parents: 422
diff changeset
   991
    ].
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
   992
440
claus
parents: 422
diff changeset
   993
    "
claus
parents: 422
diff changeset
   994
     even with more than one possible completion,
claus
parents: 422
diff changeset
   995
     f's name is now the common prefix
claus
parents: 422
diff changeset
   996
    "
claus
parents: 422
diff changeset
   997
    name := f asString.
4323
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   998
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
   999
    nMatch <= 1 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1000
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1001
         exactly one possible completion -
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1002
        "
3752
cbf9fa32eb28 fixed completion.
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
  1003
"/        f := dir construct:matchSet first.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1004
        false "directoriesOnly" ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1005
            (f exists and:[f isDirectory]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1006
                (name endsWith:sep) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1007
                    name := name , sep asString
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1008
                ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1009
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1010
        ]
440
claus
parents: 422
diff changeset
  1011
    ].
claus
parents: 422
diff changeset
  1012
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1013
    s := name.
440
claus
parents: 422
diff changeset
  1014
claus
parents: 422
diff changeset
  1015
    "/ special: if there was no change, and the string represented
claus
parents: 422
diff changeset
  1016
    "/ 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
  1017
    ((nMatch == 1) or:[s = aString]) ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1018
        (s endsWith:sep) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1019
            (self named:s) isDirectory ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1020
                ^ s , sep asString
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1021
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1022
        ].
440
claus
parents: 422
diff changeset
  1023
    ].
claus
parents: 422
diff changeset
  1024
claus
parents: 422
diff changeset
  1025
    ^ s
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1026
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1027
    "Modified: / 30.4.1999 / 09:40:13 / cg"
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
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1030
filesMatching:aPattern
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1031
    "return a collection of strings, representing the names
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1032
     of files matching aPattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1033
     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
  1034
     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
  1035
     The returned strings are the expanded names, in the same form
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1036
     as given in pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1037
     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
  1038
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1039
    |basePattern dir d files|
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1040
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1041
    self == Filename ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  1042
        ^ ConcreteClass filesMatching:aPattern
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1043
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1044
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1045
    "/ the following works on Unix & MSDOS (but not on openVMS)
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1046
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1047
    dir := aPattern asFilename directoryName.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1048
    basePattern := aPattern asFilename baseName.
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1049
    d := dir asFilename.
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  1050
    files := dir asFilename filesMatchingWithoutDotDirs:basePattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1051
    dir = '.' ifTrue:[^ files].
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1052
    ^ files collect:[:base | d constructString:base].
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1053
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1054
    "
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1055
     Filename filesMatching:'*'   
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1056
     Filename filesMatching:'/*'
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1057
     Filename filesMatching:'/usr/local/*'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1058
    "
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1059
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1060
    "Modified: 8.9.1997 / 00:32:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1061
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1062
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1063
isBadCharacter:aCharacter
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1064
    "return true, if aCharacter is unallowed in a filename."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1065
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1066
    self == Filename  ifTrue:[
8095
bfbd1309a4a6 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8036
diff changeset
  1067
        ^ ConcreteClass isBadCharacter:aCharacter
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1068
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1069
8095
bfbd1309a4a6 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8036
diff changeset
  1070
    ^ aCharacter isControlCharacter
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1071
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1072
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1073
isCaseSensitive
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1074
    "return true, if filenames are case sensitive.
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1075
     We ask the OS about this, to be independent here."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1076
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1077
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1078
        ^ ConcreteClass isCaseSensitive
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1079
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1080
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1081
    ^ OperatingSystem caseSensitiveFilenames
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1082
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1083
    "Modified: 8.9.1997 / 00:33:32 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1084
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1085
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1086
localNameStringFrom:aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1087
    "ST-80 compatibility.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1088
     what does this do ? (used in FileNavigator-goody).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1089
     GUESS: 
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1090
        does it strip off any volume characters and make a path relative ?"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1091
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1092
    |sep|
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1093
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1094
    self == Filename ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1095
        ^ ConcreteClass localNameStringFrom:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1096
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1097
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1098
    sep := self separatorString.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1099
    (aString startsWith:sep) ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1100
        ^ aString copyFrom:sep size + 1
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1101
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1102
    ^ aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1103
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1104
    "Modified: 7.9.1995 / 10:44:56 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1105
    "Modified: 8.9.1997 / 00:33:51 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1106
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1107
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1108
maxComponentLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1109
    "return the maximum number of characters a filename component may
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1110
     be in size. This depends on the OperatingSystem."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1111
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1112
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1113
        ^ ConcreteClass maxComponentLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1114
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1115
    ^ OperatingSystem maxFileNameLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1116
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1117
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1118
maxLength
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1119
    "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
  1120
     This depends on the OperatingSystem."
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1121
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1122
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1123
        ^ ConcreteClass maxLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1124
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1125
    ^ OperatingSystem maxPathLength
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1126
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1127
    "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
  1128
    "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
  1129
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1130
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1131
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1132
    "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
  1133
     The default is nil here"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1134
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1135
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1136
        ^ ConcreteClass nullFilename
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1137
    ].
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1138
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1139
    ^ OperatingSystem getNullDevice
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1140
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1141
    "Created: / 12.1.1998 / 12:15:30 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1142
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1143
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1144
parentDirectoryName 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1145
    "return the name used for the parent directory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1146
     This is '..' for unix and dos-like systems. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1147
     (there may be more in the future."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1148
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1149
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1150
        ^ ConcreteClass parentDirectoryName
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1151
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1152
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1153
    ^ OperatingSystem parentDirectoryName
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1154
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1155
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1156
     Filename parentDirectoryName  
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1157
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1158
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1159
    "Modified: 8.9.1997 / 00:34:39 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1160
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1161
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1162
separator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1163
    "return the file/directory separator.
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1164
     This is to be redefined in concrete classes;
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1165
     the following default usually leads to a flat view of
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1166
     the fileSystem (huh - BS2000 ?)"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1167
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1168
    self == Filename ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1169
       ^ ConcreteClass separator
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1170
    ].
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1171
    ^ $_
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1172
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1173
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1174
     Filename separator
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1175
     PCFilename separator
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1176
    "
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1177
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1178
    "Modified: 8.9.1997 / 00:20:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1179
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1180
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1181
separatorString
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1182
    "return the file/directory separator as a string."
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1183
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1184
    ^ self separator asString
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1185
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1186
    "
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1187
     Filename separatorString  
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1188
    "
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1189
!
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1190
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1191
suffixSeparator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1192
    "return the filename suffix separator.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1193
     Usually, this is $. for unix-like and msdos systems 
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1194
     (there is currently no known system, where this differs)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1195
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1196
     ^ $.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1197
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1198
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1199
      Filename suffixSeparator  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1200
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1201
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1202
    "Modified: 7.9.1995 / 11:10:43 / claus"
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1203
    "Modified: 30.4.1996 / 12:14:25 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1204
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1205
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1206
tempFileNameTemplate
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1207
    "return a template for temporary files.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1208
     This is expanded with the current processID and a sequenceNumber
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1209
     to generate a unique filename."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1210
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1211
    self == Filename ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1212
        ^ ConcreteClass tempFileNameTemplate
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1213
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1214
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1215
    ^ 'stxtmp_%1_%2'
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1216
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1217
    "Created: 8.9.1997 / 00:01:46 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1218
    "Modified: 8.9.1997 / 00:35:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1219
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1220
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1221
volumes
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1222
    "ST-80 compatibility.
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1223
     GUESS: does it return the available drives on MSDOS systems ?
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1224
     Q: what does this do on Unix systems ? (used in FileNavigator-goody)."
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1225
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1226
    self == Filename ifTrue:[
8679
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1227
        ^ ConcreteClass volumes
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1228
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1229
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1230
    ^ OperatingSystem getDriveList
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1231
8679
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1232
    "
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1233
     Filename volumes
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1234
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1235
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1236
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1237
!Filename class methodsFor:'utilities'!
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1238
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1239
nameFromComponents:aCollectionOfDirectoryNames
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1240
    "return a filenameString from components given in aCollectionOfDirectoryNames. 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1241
     If the first component is the name of the root directory (i.e. '/'),
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1242
     an absolute path-string is returned."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1243
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1244
    |sep s|
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1245
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1246
    self == Filename ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1247
        ^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1248
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1249
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1250
    "/ fallBack - works on Unix & MSDOS
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1251
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1252
    sep := self separatorString.
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1253
    s := ''.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1254
    aCollectionOfDirectoryNames keysAndValuesDo:[:index :component |
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1255
        index == 1 ifTrue:[
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1256
            s := component.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1257
        ] ifFalse:[
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1258
            (index == 2 and:[ (s endsWith:sep) ]) ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1259
                s := s , component
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1260
            ] ifFalse:[
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1261
                s := s , sep , component
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1262
            ]
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1263
        ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1264
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1265
    ^ s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1266
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1267
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1268
     Filename nameFromComponents:#('/' 'foo' 'bar' 'baz')  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1269
     Filename nameFromComponents:#('foo' 'bar' 'baz')  
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1270
     Filename nameFromComponents:#('/') 
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1271
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1272
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1273
     comps := Filename components:'/foo/bar/baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1274
     Filename nameFromComponents:comps        
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1275
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1276
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1277
     comps := Filename components:'\foo\bar\baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1278
     Filename nameFromComponents:comps          
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1279
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1280
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1281
     comps := Filename components:'c:\foo\bar\baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1282
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1283
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1284
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1285
     comps := Filename components:'foo\bar\baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1286
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1287
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1288
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1289
     comps := Filename components:'foo'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1290
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1291
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1292
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1293
     comps := Filename components:'\'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1294
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1295
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1296
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1297
     comps := Filename components:'c:\'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1298
     Filename nameFromComponents:comps            
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1299
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1300
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1301
    "Modified: 8.9.1997 / 00:23:16 / cg"
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1302
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1303
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1304
readingFile:aPathName do:aBlock
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1305
    "create a read-stream on a file, evaluate aBlock, passing that stream,
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1306
     and return the blocks value.
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1307
     Ensures that the stream is closed."
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1308
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1309
    ^ aPathName asFilename readingFileDo:aBlock.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1310
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1311
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1312
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1313
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1314
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1315
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1316
     rslt := 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1317
        Filename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1318
            readingFile:'/etc/passwd'
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1319
            do:[:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1320
                s nextLine
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1321
            ]. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1322
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1323
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1324
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1325
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1326
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1327
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1328
     |rslt|
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1329
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1330
     rslt :=
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1331
        Filename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1332
            readingFile:'/etc/passwd' 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1333
            do:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1334
                [:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1335
                    |shells|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1336
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1337
                    shells := Bag new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1338
                    s linesDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1339
                        [:line |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1340
                            |parts|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1341
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1342
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1343
                            shells add:(parts seventh).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1344
                        ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1345
                    shells contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1346
                ].           
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1347
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1348
    "
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1349
! !
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1350
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1351
!Filename methodsFor:'Compatibility-VW5.4'!
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1352
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1353
asLogicalFileSpecification
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1354
    ^ self
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1355
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1356
    "Created: / 30.10.2001 / 17:31:10 / cg"
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1357
!
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1358
7596
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1359
definitelyExists
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1360
    "for now - a kludge"
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1361
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1362
    ^ self exists
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1363
!
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1364
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1365
extension
6454
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1366
    "return the receiver's extension;
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1367
     that is the characters from and including
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1368
     the last period or nil, if there is none."
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1369
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1370
    |string idx|
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1371
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1372
    string := self asString.
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1373
    idx := string lastIndexOf:$..
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1374
    idx > 1 ifTrue:[
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1375
        ^ string copyFrom:idx
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1376
    ].
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1377
    ^ nil
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1378
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1379
    "
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1380
     'foo.html' asFilename extension   
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1381
     'foo.bar' asFilename extension       
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1382
     'foo.bar.baz' asFilename extension   
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1383
     'foo.' asFilename extension          
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1384
     'foo' asFilename extension           
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1385
     '.login' asFilename extension           
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1386
    "
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1387
! !
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1388
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1389
!Filename methodsFor:'comparing'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1390
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1391
= aFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1392
    "return true, if the argument represents the same filename"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1393
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1394
    |str|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1395
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1396
    self species == aFilename species ifTrue:[
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1397
	str := aFilename asString.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1398
	self class isCaseSensitive ifTrue:[
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1399
	    ^ nameString = str
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1400
	].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1401
	^ nameString sameAs:str
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1402
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1403
    ^ false
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1404
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1405
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1406
contentsIsPrefixOf:aFilename
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1407
    "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
  1408
     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
  1409
     This compares the files actual contents; not the filenames."
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1410
6908
27f9f8eceb56 Remove unused method variables
Stefan Vogel <sv@exept.de>
parents: 6893
diff changeset
  1411
    |f2 s1 s2 buffer1 buffer2 n|
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1412
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1413
    f2 := aFilename asFilename.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1414
    self fileSize > f2 fileSize ifTrue:[^ false].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1415
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1416
    [
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1417
        s1 := self readStream.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1418
        s2 := f2 readStream.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1419
        s1 binary.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1420
        s2 binary.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1421
7776
e67e1ad8f5b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7702
diff changeset
  1422
        buffer1 := ByteArray new:8192.
e67e1ad8f5b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7702
diff changeset
  1423
        buffer2 := ByteArray new:8192.
e67e1ad8f5b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7702
diff changeset
  1424
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1425
        [s1 atEnd] whileFalse:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1426
            n := s1 nextBytes:8192 into:buffer1 startingAt:1.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1427
            n == 0 ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1428
                "/ receiver shorter.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1429
                ^ true
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1430
            ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1431
            (s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1432
                "/ aFilename shorter
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1433
                ^ false
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1434
            ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1435
            buffer1 ~= buffer2 ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1436
                ^ false
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1437
            ]
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1438
        ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1439
        "/ receiver shorter or same size.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1440
    ] ensure:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1441
        s1 notNil ifTrue:[s1 close]. 
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1442
        s2 notNil ifTrue:[s2 close]. 
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1443
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1444
    ^ true
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1445
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1446
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1447
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1448
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1449
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1450
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1451
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1452
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1453
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1454
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1455
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1456
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1457
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1458
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1459
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1460
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1461
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1462
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1463
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1464
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1465
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1466
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1467
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1468
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1469
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1470
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1471
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1472
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1473
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1474
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1475
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1476
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1477
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1478
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1479
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1480
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1481
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1482
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1483
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1484
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1485
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1486
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1487
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1488
!
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1489
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1490
contentsStartsWithContentsOf:aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1491
    "return true if the contents of the file represented by aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1492
     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
  1493
     This compares the files actual contents; not the filenames."
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1494
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1495
    ^ aFilename asFilename contentsIsPrefixOf:self
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1496
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1497
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1498
     |s|
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1499
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1500
     s := 'testFile1' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1501
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1502
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1503
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1504
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1505
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1506
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1507
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1508
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1509
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1510
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1511
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1512
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1513
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1514
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1515
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1516
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1517
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1518
     s nextPutAll:'44444'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1519
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1520
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1521
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1522
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1523
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1524
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1525
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1526
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1527
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1528
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1529
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1530
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1531
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1532
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1533
     s nextPutAll:'33334'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1534
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1535
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1536
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1537
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1538
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1539
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1540
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1541
hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1542
    "return an integer useful as a hash-key"
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1543
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1544
    ^ nameString hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1545
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1546
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1547
sameContentsAs:aFilename
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1548
    "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
  1549
     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
  1550
     This compares the files actual contents; not the filenames."
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1551
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1552
    |f2|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1553
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1554
    f2 := aFilename asFilename.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1555
    f2 fileSize = self fileSize ifFalse:[^ false].
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1556
    ^ self contentsIsPrefixOf:f2.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1557
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1558
    "
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1559
     'Make.proto' asFilename sameContentsAs:'Makefile'  
7122
5c925f402f6f comment
Claus Gittinger <cg@exept.de>
parents: 7120
diff changeset
  1560
     'Make.proto' asFilename sameContentsAs:'Make.proto'   
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1561
    "
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1562
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1563
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1564
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1565
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1566
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1567
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1568
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1569
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1570
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1571
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1572
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1573
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1574
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1575
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1576
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1577
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1578
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifFalse:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1579
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1580
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1581
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1582
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1583
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1584
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1585
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1586
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1587
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1588
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1589
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1590
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1591
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1592
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1593
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1594
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1595
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1596
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1597
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1598
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1599
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1600
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1601
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1602
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1603
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1604
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1605
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1606
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1607
!Filename methodsFor:'converting'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1608
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1609
asAbsoluteFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1610
    "return the receiver converted to a filename with
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1611
     an absolute pathname."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1612
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  1613
    ^ self class named:self pathName
7332
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1614
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1615
    "
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1616
     '.' asFilename
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1617
     '.' asFilename asAbsoluteFilename
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1618
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1619
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1620
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1621
asCanonicalizedFilename
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1622
    "return the receiver converted to a filename without intermediate ..'s and .'s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1623
     (similar to an absolute pathname, but symlinks are not resolved)."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1624
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1625
    ^ self class named:(self class canonicalize:nameString)
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1626
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1627
    "
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1628
      'c:\test\work' asFilename asCanonicalizedFilename
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1629
      '/test/work' asFilename asCanonicalizedFilename
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1630
    "
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1631
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1632
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1633
asFilename
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1634
    "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
  1635
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1636
    "Thats pretty easy here :-)"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1637
    ^ self
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1638
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1639
    "Modified: 12.11.1996 / 12:40:03 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1640
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1641
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1642
asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1643
    "return the receiver converted to a string"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1644
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1645
    ^ nameString
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
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1648
asURI
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1649
    "return the receiver converted to a string"
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1650
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1651
    ^ FileURI fromFilename:self.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1652
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  1653
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1654
components
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1655
    "return the receivers filename components - that is the name of each directory
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1656
     along the pathName (that DOES include the root directory)"
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1657
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1658
    ^ self class components:self name
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1659
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1660
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1661
     '.' asFilename asAbsoluteFilename components 
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1662
     'Makefile' asFilename asAbsoluteFilename components     
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1663
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1664
!
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  1665
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1666
makeLegalFilename 
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1667
    "convert the receivers name to be a legal filename.
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1668
     This removes/replaces invalid characters and/or compresses
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1669
     the name as required by the OS.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1670
     The implementation may change in the future to be more
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1671
     OS specific."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1672
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1673
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1674
     actually, in Unix spaces are allowed - but it makes life
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1675
     so hard; therefore, replace them by underscores ...
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1676
    "
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1677
    (nameString includes:Character space) ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1678
	nameString := nameString copyReplaceAll:(Character space) with:$_.
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1679
    ].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1680
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1681
     need more - especially on SYS5.3 type systems, 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1682
     we may want to contract the fileName to 14 characters.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1683
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1684
    ^ self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1685
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1686
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1687
     'hello world' asFilename makeLegalFilename 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1688
    "
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  1689
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1690
    "Modified: / 20.7.1998 / 13:16:51 / cg"
2707
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1691
!
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1692
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1693
withEncoding:encodingSymbol
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1694
    "dummy for now - for ST80 compatibility"
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1695
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1696
    ^ self
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1697
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  1698
    "Created: 20.6.1997 / 17:01:28 / cg"
2
claus
parents: 1
diff changeset
  1699
! !
claus
parents: 1
diff changeset
  1700
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1701
!Filename methodsFor:'enumerating-contents'!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1702
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1703
allDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1704
    "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
  1705
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1706
     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
  1707
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1708
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1709
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1710
     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
  1711
     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
  1712
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1713
    self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1714
	|eachFileOrDirectory|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1715
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1716
	eachFileOrDirectory := self construct:eachFileOrDirectoryName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1717
	eachFileOrDirectory isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1718
	    aBlock value:eachFileOrDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1719
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1720
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1721
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1722
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1723
     '.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1724
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1725
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1726
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1727
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1728
allParentDirectoriesDo:aBlock
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1729
    "evaluate aBlock for all (recursive) directories along the parent directory path.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1730
     The block is invoked with a filename-arguments."
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1731
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1732
    |parent here|
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1733
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1734
    here := self.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1735
    parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1736
    [here notNil and:[parent ~= here]] whileTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1737
        aBlock value:parent.    
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1738
        here := parent.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1739
        parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1740
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1741
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1742
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1743
     '.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1744
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1745
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  1746
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1747
directoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1748
    "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
  1749
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1750
     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
  1751
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1752
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1753
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1754
     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
  1755
     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
  1756
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1757
    self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1758
	eachFileOrDirectory isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1759
	    aBlock value:eachFileOrDirectory
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1760
	]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1761
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1762
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1763
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1764
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1765
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1766
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1767
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1768
directoryContentsAsFilenamesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1769
    "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
  1770
     The block is invoked with a filename-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1771
     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
  1772
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1773
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1774
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1775
     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
  1776
     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
  1777
     Notice: this enumerates fileName objects; see also
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1778
     #directoryContentsDo:, which enumerates strings."
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1779
6776
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  1780
    self directoryContentsDo:[:entry |
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  1781
        aBlock value:(self construct:entry).
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  1782
    ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1783
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1784
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1785
     '.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1786
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1787
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1788
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1789
    "Modified: / 23.12.1999 / 20:56:35 / cg"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1790
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1791
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1792
directoryContentsDo:aBlock
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1793
    "evaluate aBlock for each file in the directory represented by the receiver.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1794
     The block is invoked with a string as argument.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1795
     The enumerations order is undefined - i.e. usually NOT sorted by
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1796
     filenames (but by creation time - on some systems).
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1797
     This excludes entries for '.' or '..'.
7473
5474c91e0aa3 Comments
Stefan Vogel <sv@exept.de>
parents: 7464
diff changeset
  1798
     An exception is raised it the directory does not exist..
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1799
     So users of this method better test for existing directory before.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1800
     Notice: this enumerates strings; see also
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1801
     #directoryContentsAsFilenamesDo:, which enumerates fileName objects."
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1802
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1803
    |s fn|
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1804
7846
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  1805
    FileStream openErrorSignal 
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  1806
        handle:[:ex |] 
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  1807
        do:[
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  1808
            s := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  1809
        ].
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  1810
    s isNil ifTrue:[^ self].
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1811
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1812
    [
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1813
        [s atEnd] whileFalse:[
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1814
            fn := s nextLine.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1815
            ((fn ~= '.') and:[fn ~= '..']) ifTrue:[        
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1816
                aBlock value:fn
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1817
            ]
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1818
        ]
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1819
    ] ensure:[
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1820
        s close
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1821
    ].
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1822
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1823
    "
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1824
     '.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
7473
5474c91e0aa3 Comments
Stefan Vogel <sv@exept.de>
parents: 7464
diff changeset
  1825
     'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1826
    "
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1827
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1828
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1829
    "Modified: / 23.12.1999 / 20:56:35 / cg"
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1830
!
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  1831
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1832
recursiveDirectoryContentsDo:aBlock 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1833
    "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
  1834
     The block is invoked with a string-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1835
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1836
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1837
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1838
     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
  1839
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1840
    self recursiveDirectoryContentsDo:aBlock directoryPrefix:''
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1841
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1842
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1843
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1844
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1845
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1846
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1847
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1848
    "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
  1849
     The block is invoked with a string-argument.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1850
     The walk is breadth-first.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1851
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1852
     Subdirectory files are included with a relative pathname.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1853
     A proceedable exception is raised forn non-accessable directories.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1854
     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
  1855
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1856
    |fileNames dirNames p|
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1857
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1858
    fileNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1859
    dirNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1860
    self directoryContentsDo:[:f | |t|
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1861
        t := self construct:f.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1862
        t isDirectory ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1863
            t isSymbolicLink ifFalse:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1864
                dirNames add:f
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1865
            ]
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1866
        ] ifFalse:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1867
            fileNames add:f
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1868
        ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1869
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1870
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1871
    aPrefix size > 0 ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1872
        p := aPrefix , self separator
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1873
    ] ifFalse:[
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1874
        p := ''
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1875
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1876
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1877
    fileNames do:[:aFile | aBlock value:(p , aFile)].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1878
    dirNames do:[:dN |
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1879
        aBlock value:(p , dN).
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1880
        (self construct:dN)
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1881
            recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN)
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1882
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1883
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1884
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1885
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1886
     '/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1887
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1888
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1890
withAllDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1891
    "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
  1892
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1893
     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
  1894
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1895
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1896
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1897
     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
  1898
     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
  1899
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1900
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1901
	aBlock value:self.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  1902
	self allDirectoriesDo:aBlock
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1903
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1904
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1905
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1906
     '.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1907
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1908
! !
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  1909
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1910
!Filename methodsFor:'error handling'!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1911
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1912
accessDeniedError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1913
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1914
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1915
    "report an error that access to some file was denied"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1916
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1917
    |errNo errString|
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1918
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1919
    errNo := OperatingSystem lastErrorNumber.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1920
    errString := OperatingSystem lastErrorString.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1921
    errString size == 0 ifTrue:[
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1922
        errString := ''.
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1923
    ] ifFalse:[
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1924
        errString := ' (' , errString , ')'
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1925
    ].
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1926
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1927
    ^ OperatingSystem accessDeniedErrorSignal
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1928
        raiseRequestWith:filename
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1929
        errorString:(' : ' , filename asString , errString)
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1930
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  1931
    "Modified: / 26.9.1999 / 16:11:44 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1932
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1933
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1934
fileCreationError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1935
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1936
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1937
    "report an error that some file could not be created"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1938
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1939
    ^ OperatingSystem accessDeniedErrorSignal
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1940
        raiseRequestWith:filename
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  1941
        errorString:(' - cannot create/write file: ' , filename asString)
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1942
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1943
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1944
fileNotFoundError:filename 
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1945
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1946
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1947
    "report an error that some file was not found"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1948
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1949
    ^ OperatingSystem fileNotFoundErrorSignal
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1950
	raiseRequestWith:filename
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1951
	errorString:('file not found: ' , filename asString)
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1952
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1953
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1954
removeError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1955
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1956
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1957
    "report an error that some file could not be removed"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1958
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1959
    ^ OperatingSystem accessDeniedErrorSignal
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1960
	raiseRequestWith:filename
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  1961
	errorString:('cannot remove: ' , filename asString)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1962
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1963
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1964
reportError:string with:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1965
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1966
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1967
    "report an error"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  1968
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1969
    ^ OperatingSystem errorSignal
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1970
	raiseRequestWith:filename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1971
	errorString:string
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1972
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1973
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1974
!Filename methodsFor:'file access'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1975
3015
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1976
appendStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1977
    "return a stream for appending to the file represented by the receiver.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1978
     If the file does not already exist, it is created.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1979
     Same as #appendingWriteStream for ST-80 compatibility."
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1980
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1981
    ^ self appendingWriteStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1982
!
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  1983
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1984
appendingWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1985
    "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
  1986
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1987
     if it does exist, writes are appended at the end."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1988
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  1989
    ^ FileStream appendingOldFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1990
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1991
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1992
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1993
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1994
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1995
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1996
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1997
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1998
     s := '/tmp/foo' asFilename appendingWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  1999
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2000
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2001
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2002
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2003
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2004
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2005
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2006
newReadWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2007
    "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
  2008
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2009
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2010
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2011
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2012
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2013
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2014
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2015
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2016
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2017
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2018
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2019
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2020
     s := '/tmp/foo' asFilename newReadWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2021
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2022
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2023
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2024
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2025
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2026
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2027
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2028
readStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2029
    "return a stream for reading from the file represented by the receiver.
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2030
     Raises an error if the file does not exist."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2031
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2032
    ^ FileStream readonlyFileNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2033
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2034
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2035
     '/tmp/foo' asFilename readStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2036
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2037
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2038
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2039
readWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2040
    "return a stream for read/write the file represented by the receiver.
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2041
     If the file does not already exist, it is created.
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2042
     If the file does exist, it is NOT truncated, but rewritten at the beginning."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2043
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2044
    ^ FileStream fileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2045
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2046
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2047
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2048
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2049
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2050
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2051
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2052
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2053
     s := '/tmp/foo' asFilename readWriteStream. 
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2054
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2055
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2056
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2057
     '/tmp/foo' asFilename contents      
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2058
     '/tmp/foo' asFilename remove      
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2059
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2060
!
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
writeStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2063
    "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
  2064
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2065
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2066
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2067
    ^ FileStream newFileForWritingNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2068
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2069
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2070
     '/tmp/foo' asFilename writeStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2071
    "
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2072
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2073
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2074
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2075
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2076
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2077
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2078
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2079
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2080
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2081
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2082
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2083
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2084
     '/tmp/foo' asFilename contents  
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2085
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2086
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2087
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2088
!Filename methodsFor:'file access - migration'!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2089
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2090
appendingWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2091
    "return a stream for appending to the file represented by the receiver.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2092
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2093
     if it does exist, writes are appended at the end.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2094
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2095
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2096
     Use this method for migration of old smalltalk code that expects a nil return code
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2097
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2098
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2099
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2100
        FileStream appendingOldFileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2101
      ] on:FileStream openErrorSignal do:[:ex| nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2102
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2103
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2104
newReadWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2105
    "return a stream for read/write the file represented by the receiver.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2106
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2107
     if it does exist, it is truncated.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2108
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2109
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2110
     Use this method for migration of old smalltalk code that expects a nil return code
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2111
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2112
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2113
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2114
         FileStream newFileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2115
    ] on:FileStream openErrorSignal do:[:ex|nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2116
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2117
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2118
readStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2119
    "return a stream for reading from the file represented by the receiver.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2120
     If the file does not already exist, nil is returned.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2121
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2122
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2123
     Use this method for migration of old smalltalk code that expects a nil return code
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2124
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2125
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2126
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2127
        FileStream readonlyFileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2128
    ] on:FileStream openErrorSignal do:[:ex|nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2129
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2130
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2131
     '/tmp/foo' asFilename readStreamOrNil 
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2132
     '/tmp/foo' asFilename readStream 
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2133
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2134
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2135
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2136
readWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2137
    "return a stream for read/write the file represented by the receiver.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2138
     If the file does not already exist, it is created.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2139
     If the file does exist, it is NOT truncated, but rewritten at the beginning
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2141
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2142
     Use this method for migration of old smalltalk code that expects a nil return code
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2143
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2144
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2145
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2146
        FileStream fileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2147
    ] on:FileStream openErrorSignal do:[:ex|^ nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2148
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2149
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2150
writeStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2151
    "return a stream for writing to the file represented by the receiver.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2152
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2153
     if it does exist, it is truncated.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2154
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2155
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2156
     Use this method for migration of old smalltalk code that expects a nil return code
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2157
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2158
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2159
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2160
        FileStream newFileForWritingNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2161
    ] on:FileStream openErrorSignal do:[:ex|^ nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2162
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2163
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2164
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2165
     '/etc/foo' asFilename writeStreamOrNil 
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2166
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2167
! !
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2168
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2169
!Filename methodsFor:'file accessRights'!
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2170
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2171
addAccessRights:aCollection
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2172
    "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
  2173
     by the receiver. The argument must be a collection of symbols,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2174
     such as #readUser, #writeGroup etc."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2175
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2176
    |access osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2177
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2178
    osName := self osNameForFile.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2179
    access := OperatingSystem accessModeOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2180
    aCollection do:[:accessSymbol |
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2181
	access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2182
    ].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2183
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2184
	^ self accessDeniedError:self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2185
    ]
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2186
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2187
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2188
     'foo' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2189
     'foo' asFilename addAccessRights:#(readUser readGroup readOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2190
     'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2191
     'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2192
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2193
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2194
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2195
makeExecutable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2196
    "make the file executable - you must have permission to do so.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2197
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2198
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2199
    ^ self addAccessRights:#(executeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2200
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2201
    "Created: 9.1.1996 / 15:32:47 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2202
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2203
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2204
makeExecutableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2205
    "make the file executable for all - you must have permission to do so.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2206
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2207
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2208
    ^ self addAccessRights:#(executeUser executeGroup executeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2209
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2210
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2211
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2212
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2213
makeExecutableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2214
    "make the file executable for the group - you must have permission to do so.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2215
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2216
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2217
    ^ self addAccessRights:#(executeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2218
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2219
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2220
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2221
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2222
makeReadable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2223
    "make the file readable for  the owner - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2224
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2225
    ^ self addAccessRights:#(readUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2226
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2227
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2228
makeReadableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2229
    "make the file readable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2230
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2231
    ^ self addAccessRights:#(readUser readGroup readOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2232
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2233
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2234
makeReadableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2235
    "make the file readable for the group - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2236
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2237
    ^ self addAccessRights:#(readGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2238
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2239
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2240
makeUnwritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2241
    "make the file unwritable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2242
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2243
    ^ self removeAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2244
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2245
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2246
makeWritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2247
    "make the file writableable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2248
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2249
    ^ self addAccessRights:#(writeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2250
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2251
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2252
makeWritableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2253
    "make the file writable for all - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2254
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2255
    ^ self addAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2256
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2257
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2258
makeWritableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2259
    "make the file writable for the group - you must have permission to do so."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2260
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2261
    ^ self addAccessRights:#(writeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2262
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2263
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2264
removeAccessRights:aCollection
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2265
    "remove the access rights as specified in aCollection for the file represented
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2266
     by the receiver. The argument must be a collection of symbols,
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2267
     such as #readUser, #writeGroup etc.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2268
     Raises an exception if not successful."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2269
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2270
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2271
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2272
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2273
    access := OperatingSystem accessModeOf:osName.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2274
    aCollection do:[:accessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2275
	access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2276
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2277
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2278
	^ self accessDeniedError:self
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2279
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2280
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2281
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2282
     'foo' asFilename writeStream close.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2283
     'foo' asFilename removeAccessRights:#(readUser readGroup readOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2284
     'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2285
     'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2286
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2287
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2288
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2289
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2290
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2291
symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2292
    "return the access rights of the file as a aCollection of access symbols.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2293
     The returned collection consists of symbols like:
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2294
        #readUser, #writeGroup etc."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2295
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2296
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2297
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2298
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2299
    access := OperatingSystem accessModeOf:osName.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2300
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2301
    ^ 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2302
        #(  readUser writeUser executeUser
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2303
            readGroup writeGroup executeGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2304
            readOthers writeOthers executeOthers
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2305
          ) select:[:eachSymbolicAccessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2306
                access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2307
            ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2308
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2309
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2310
     'Makefile' asFilename symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2311
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2312
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2313
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2314
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2315
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2316
symbolicAccessRights:aCollectionOfSymbols
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2317
    "set the access rights of the file given a aCollection of access symbols.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2318
     The collection must consist of symbols like:
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2319
        #readUser, #writeGroup etc."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2320
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2321
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2322
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2323
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2324
    access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2325
                bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2326
              ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2327
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2328
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2329
        ^ self accessDeniedError:self
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2330
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2331
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2332
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2333
     |rights|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2334
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2335
     rights := 'Makefile' asFilename symbolicAccessRights. 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2336
     'Makefile' asFilename symbolicAccessRights:(rights , #(executeOthers)). 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2337
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2338
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2339
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2340
! !
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2341
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2342
!Filename methodsFor:'file operations'!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2343
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2344
appendTo:newNameOrStream
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2345
    "append the file - the argument must be convertable to a filename.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2346
     Raises an exception, if an error occurs."
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2347
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2348
    |inStream outStream outStreamToClose|
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2349
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2350
    inStream := self readStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2351
    [
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2352
        newNameOrStream isStream ifTrue:[
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2353
            outStream := newNameOrStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2354
        ] ifFalse:[
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2355
            outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2356
        ].
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2357
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2358
        [
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2359
            inStream copyToEndInto:outStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2360
        ] on:OperatingSystem errorSignal do:[:ex|
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2361
            ^ self fileCreationError:newNameOrStream
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2362
        ]
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2363
    ] ensure:[
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2364
        inStream close.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2365
        outStreamToClose notNil ifTrue:[outStreamToClose close].
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2366
    ].
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2367
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2368
    "
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2369
     '/etc/group' asFilename appendTo:'/tmp/Makefile.foo'.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2370
     'Makefile' asFilename appendTo:'/tmp/Makefile.foo'
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2371
     'Makefile' asFilename copyTo:'/'
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2372
     'smalltalk' asFilename copyTo:'/dev/null'
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2373
    "
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2374
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2375
    "Modified: / 23.12.1999 / 21:52:36 / cg"
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2376
!
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2377
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2378
basicMakeDirectory
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2379
    "create a directory with the receivers name.
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2380
     Return true if successful, false if not."
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2381
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2382
    ^ OperatingSystem createDirectory:(self osNameForDirectory)
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2383
!
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2384
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2385
copyTo:newName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2386
    "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
  2387
     Raises an exception, if an error occurs."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2388
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2389
    |inStream outStream|
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2390
8535
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2391
    "Contents is not copied if newName represent same file as me."
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2392
    newName asFilename asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ].
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2393
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2394
    inStream := self readStream.
8535
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2395
    inStream isNil ifTrue:[
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2396
        ^ self fileNotFoundError:self 
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2397
    ].
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2398
    [
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2399
        outStream := newName asFilename writeStream.
8535
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2400
        outStream isNil ifTrue:[
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2401
            ^ self fileCreationError:newName asFilename
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2402
        ].
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2403
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2404
        [
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2405
            inStream copyToEndInto:outStream.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2406
        ] on:OperatingSystem errorSignal do:[:ex|
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2407
            ^ self fileCreationError:newName asFilename
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2408
        ]
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2409
    ] ensure:[
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2410
        inStream close.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2411
        outStream notNil ifTrue:[outStream close].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2412
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2413
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2414
    "
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2415
     'Makefile' asFilename copyTo:'/tmp/Makefile.foo'
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2416
     'Makefile' asFilename copyTo:'/'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2417
     'smalltalk' asFilename copyTo:'/dev/null'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2418
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2419
5134
48758d82be48 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5132
diff changeset
  2420
    "Modified: / 23.12.1999 / 21:52:36 / cg"
8535
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2421
    "Modified: / 10.9.2004 / 09:49:28 / janfrog"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2422
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2423
6983
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2424
createAsEmptyFile
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2425
    "create an empty file with the receivers name.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2426
     Raises an exception if not successful
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2427
    (either already existing or creation not possible)"
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2428
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2429
    |writeStream|
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2430
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2431
    self exists ifTrue:[
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2432
        OperatingSystem accessDeniedErrorSignal
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2433
            raiseRequestWith:self
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2434
            errorString:(' - file exists: ' , self asString).
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2435
        ^ self
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2436
    ].  
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2437
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2438
    FileStream openErrorSignal handle:[:ex|
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2439
        self fileCreationError:self.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2440
        ^ self
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2441
    ] do:[    
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2442
        writeStream := self newReadWriteStream.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2443
    ].
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2444
    writeStream close.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2445
!
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  2446
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2447
delete
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2448
    "remove the file - same as remove, for ST-80 compatibility"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2449
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2450
    self remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2451
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2452
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2453
makeDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2454
    "create a directory with the receivers name.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2455
     Raises an exception if not successful"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2456
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2457
    (self basicMakeDirectory) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2458
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2459
	"/ could have existed before ...
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2460
	"/
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2461
	(self exists and:[self isDirectory]) ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2462
	    self fileCreationError:self.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2463
	    ^ false
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2464
	]
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2465
    ].
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2466
    ^ true
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2467
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2468
    "Modified: / 5.5.1999 / 13:36:33 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2469
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2470
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2471
moveFileTo:newName
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2472
    "copy the file represented by the receiver, then delete it.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2473
     This is different to renaming in case of cross device moves.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2474
     Raise an exception if not successful.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2475
     (Notice, that a rename is tried first, in case of non-cross device move)"
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2476
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2477
    [self renameTo:newName] 
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2478
        on:(OperatingSystem errorSignal) 
7134
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2479
        do:[:ex |
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2480
            ex signal == OperatingSystem fileNotFoundErrorSignal ifTrue:[
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2481
                ex reject
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2482
            ].
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2483
            self copyTo:newName. 
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2484
            self remove
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2485
        ].
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2486
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2487
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2488
     |f s|
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2489
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2490
     f := '/tmp/foo' asFilename.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2491
     s := f writeStream.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2492
     s nextPutLine:'hello'.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2493
     s close.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2494
     f renameTo:'./foo'
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2495
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2496
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2497
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2498
     |f s|
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2499
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2500
     f := '/tmp/foo' asFilename.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2501
     s := f writeStream.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2502
     s nextPutLine:'hello'.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2503
     s close.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2504
     f moveTo:'./foo'
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2505
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2506
!
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2507
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2508
moveTo:newName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2509
    "copy the file represented by the receiver, then delete it.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2510
     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
  2511
     Raise an exception if not successful.
3d801043be3f dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 5577
diff changeset
  2512
     (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
  2513
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2514
    [self renameTo:newName] 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2515
        on:(OperatingSystem errorSignal) 
7134
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2516
        do:[:ex |
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2517
            ex signal == OperatingSystem fileNotFoundErrorSignal ifTrue:[
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2518
                ex reject
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2519
            ].
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  2520
6995
a7650ef2b1be move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6983
diff changeset
  2521
            self isDirectory ifTrue:[
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2522
                self recursiveMoveDirectoryTo:newName.
6995
a7650ef2b1be move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6983
diff changeset
  2523
            ] ifFalse:[
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  2524
                self moveFileTo:newName.
6995
a7650ef2b1be move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6983
diff changeset
  2525
            ].
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  2526
        ].
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2527
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2528
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2529
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2530
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2531
     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
  2532
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2533
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2534
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2535
     f renameTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2536
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2537
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2538
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2539
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2540
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2541
     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
  2542
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2543
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2544
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2545
     f moveTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  2546
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2547
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2548
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2549
recursiveCopyTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2550
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2551
     Otherwise, copy the directory and recursively
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2552
     and recursively all of its subfiles/subdirectories.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2553
     Raises an exception if not successful."
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2554
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2555
    |ok d|
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2556
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2557
    self isDirectory ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2558
	d := destination asFilename.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2559
	(d exists and:[d isDirectory]) ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2560
	    d := d construct:self baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2561
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2562
	^ self copyTo:d
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2563
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2564
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2565
    "/ typically, an 'cp -r' is faster;
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2566
    "/ 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
  2567
    "/ fallBack doing a manual directory walk.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2568
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2569
    ok := OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2570
	    recursiveCopyDirectory:(self osNameForDirectory)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2571
	    to:(destination asFilename osNameForDirectory).
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2572
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2573
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2574
	self recursiveCopyWithoutOSCommandTo:destination
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2575
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2576
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2577
    "Created: / 5.5.1999 / 13:35:01 / cg"
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2578
    "Modified: / 31.5.1999 / 13:11:34 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2579
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2580
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2581
recursiveCopyWithoutOSCommandTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2582
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2583
     Otherwise, copy the directory and all of its subfiles/subdirectories.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2584
     This one walks down the directory hierarchy, not using any OS
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2585
     command to do the copy.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2586
     Raises an exception if not successful."
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2587
4245
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2588
    |destinationFilename d|
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2589
610136f7e16b recursive copy of directories
Claus Gittinger <cg@exept.de>
parents: 4199
diff changeset
  2590
    d := destination asFilename.
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2591
"/    (d exists and:[d isDirectory]) ifTrue:[
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2592
"/        d := d construct:self baseName.
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2593
"/    ].
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2594
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2595
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2596
	destinationFilename := d asFilename construct:self baseName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2597
	destinationFilename makeDirectory.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2598
	self directoryContents do:[:aFilenameString |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2599
	    |src dst|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2600
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2601
	    src := self construct:aFilenameString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2602
	    src isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2603
		src recursiveCopyWithoutOSCommandTo:destinationFilename
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2604
	    ] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2605
		src copyTo:(destinationFilename construct:aFilenameString)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2606
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2607
	]
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2608
    ] ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2609
	self copyTo:d
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2610
    ]
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2611
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2612
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2613
     '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2614
     'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2615
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2616
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  2617
    "Modified: / 31.5.1999 / 18:12:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2618
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2619
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2620
recursiveMakeDirectory
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2621
    "create a directory with the receivers name and all required intermediate
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2622
     directories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2623
     Raises an exception if not successful."
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2624
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2625
    (OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2626
	^ self fileCreationError:self
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2627
    ]
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2628
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2629
    "Created: / 27.11.1995 / 23:36:40 / cg"
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2630
    "Modified: / 5.5.1999 / 13:38:42 / cg"
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2631
!
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  2632
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2633
recursiveMoveDirectoryTo:newName
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2634
    "recursively copy the directory represented by the receiver, then delete it.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2635
     This is different to renaming in case of cross device moves.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2636
     Raise an exception if not successful.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2637
     (Notice, that a rename is tried first, in case of non-cross device move)"
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2638
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2639
    [self renameTo:newName] 
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2640
        on:(OperatingSystem errorSignal) 
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2641
        do:[ 
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2642
            self recursiveCopyTo:newName.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2643
            self recursiveRemove
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2644
        ].
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2645
!
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  2646
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2647
recursiveRemove
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2648
    "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
  2649
     Otherwise, remove the directory and all of its subfiles/subdirectories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2650
     Raise an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2651
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2652
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2653
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2654
    "/ typically, an 'rm -rf' is faster and removes better;
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2655
    "/ 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
  2656
    "/ fallBack doing a manual directory walk.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2657
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2658
    ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory).
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2659
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2660
	self recursiveRemoveWithoutOSCommand
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2661
    ].
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2662
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2663
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2664
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2665
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2666
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2667
	Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2668
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2669
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2670
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2671
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2672
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2673
     ('foo' asFilename recursiveRemove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2674
	Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2675
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2676
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2677
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2678
    "Created: / 14.11.1995 / 11:19:29 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2679
    "Modified: / 5.5.1999 / 13:43:35 / cg"
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2680
!
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2681
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2682
recursiveRemoveWithoutOSCommand
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2683
    "if I represent a regular file, remove it.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2684
     Otherwise, remove the directory and all of its subfiles/subdirectories.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2685
     Raise an error if not successful.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2686
     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
  2687
     command to do the remove."
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2688
4939
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  2689
    |files|
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  2690
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2691
    self isDirectory ifTrue:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2692
	(files := self directoryContents) size > 0 ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2693
	    files do:[:aFilenameString |
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2694
		|f|
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2695
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2696
		f := self construct:aFilenameString.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2697
		f isDirectory ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2698
		    f recursiveRemoveWithoutOSCommand
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2699
		] ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2700
		    f remove
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2701
		].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2702
	    ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2703
	]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2704
    ].
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  2705
    self remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2706
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2707
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2708
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2709
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  2710
     'foo' asFilename remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2711
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2712
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2713
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2714
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  2715
     'foo' asFilename recursiveRemove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2716
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2717
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2718
    "Created: / 25.2.1998 / 19:50:40 / cg"
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  2719
    "Modified: / 25.2.1998 / 19:52:08 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2720
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2721
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2722
remove
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  2723
    "remove the file/directory.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2724
     Raises an exception if not successful.
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  2725
     Use #recursiveRemove in order to (recursively) remove non empty directories."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2726
8741
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2727
    |linkInfo osName ok|
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2728
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2729
    osName := self osNameForFile.
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2730
    linkInfo := self linkInfo.
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2731
    (linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2732
        ok := OperatingSystem removeDirectory:osName
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2733
    ] ifFalse:[
8741
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  2734
        ok := OperatingSystem removeFile:osName
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2735
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2736
    ok ifFalse:[
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2737
        self exists ifTrue:[
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2738
            self removeError:self
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  2739
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2740
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2741
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2742
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2743
     (FileStream newFileNamed:'foo') close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2744
     'foo' asFilename remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2745
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2746
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2747
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2748
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2749
     'foo/bar' asFilename writeStream close.
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  2750
     'foo' asFilename remove.   'expect an exception'
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  2751
     'foo' asFilename recursiveRemove.   
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2752
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2753
3113
43e75ed892cf Removing a symlink to a directory must call #removeFile:.
Stefan Vogel <sv@exept.de>
parents: 3077
diff changeset
  2754
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2755
    "Modified: / 5.5.1999 / 13:41:12 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2756
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2757
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2758
removeDirectory
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2759
    "remove the directory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2760
     Raises an exception if not successful (or if its not a directory).
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2761
     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
  2762
     Use #recursiveRemove in order to (recursively) remove non empty directories."
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2763
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2764
    |ok|
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2765
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2766
    ok := OperatingSystem removeDirectory:(self osNameForFile).
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2767
    ok ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2768
	self exists ifFalse:[ ^ self].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2769
	self removeError:self
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2770
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2771
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2772
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2773
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2774
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2775
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2776
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2777
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2778
     'foo' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2779
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2780
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2781
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2782
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2783
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2784
     'foo/bar' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2785
     ('foo' asFilename remove) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2786
	Transcript showCR:'could not remove foo'
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2787
     ]
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2788
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2789
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2790
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2791
    "Modified: / 5.5.1999 / 13:41:12 / cg"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2792
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2793
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2794
removeFile
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2795
    "remove the file.
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2796
     Raises an exception if not successful (or if its not a file).
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  2797
     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
  2798
     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
  2799
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  2800
    (OperatingSystem removeFile:self osNameForFile) ifFalse:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  2801
        self exists ifTrue:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  2802
            self removeError:self
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  2803
        ].
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2804
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2805
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2806
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2807
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2808
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2809
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2810
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2811
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2812
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2813
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2814
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2815
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  2816
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2817
renameOrCopyTo:newName
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2818
    "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
  2819
     Raises an exception if not successful.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2820
     This does basically the same as #renameTo:, with one exception:
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2821
     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
  2822
     fails, and #renameTo: raises an exception;
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2823
     in contrast, this method falls back to copying the file."
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2824
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2825
    |newFilename|
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2826
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2827
    newFilename := newName asFilename.
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2828
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2829
    (OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2830
	renameFile:(self osNameForFile) 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2831
	to:(newFilename osNameForFile)
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2832
    ) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2833
	self exists ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2834
	    ^ self fileNotFoundError:self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2835
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2836
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2837
	OperatingSystem isUNIXlike ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2838
	    OperatingSystem lastErrorSymbol == #EXDEV ifTrue:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2839
		"/ try to copy - and remove the original
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2840
		"/ this helps with cross-device renames.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2841
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2842
	      self copyTo:newName.
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2843
	      ^ self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2844
	  ].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2845
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2846
	^ self accessDeniedError:newName asFilename.
5086
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2847
    ].
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2848
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2849
    "
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2850
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2851
    "
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2852
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2853
    "Modified: / 5.5.1999 / 13:41:27 / cg"
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2854
!
dbeb79c72b84 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5032
diff changeset
  2855
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2856
renameTo:newName
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 659
diff changeset
  2857
    "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
  2858
     Raises an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2859
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2860
    (OperatingSystem 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2861
	renameFile:(self osNameForFile) 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2862
	to:(newName asFilename osNameForFile)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2863
    ) ifFalse:[
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2864
	self exists ifFalse:[
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2865
	    ^ self fileNotFoundError:self
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2866
	].
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  2867
	^ self accessDeniedError:newName asFilename.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2868
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2869
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2870
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2871
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2872
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2873
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2874
    "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
  2875
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2876
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2877
truncateTo:newSize
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2878
    "change the files size.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2879
     This may not be supported on all operating systems
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2880
     (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
  2881
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  2882
    (OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  2883
        ^ 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
  2884
    ]
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2885
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2886
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2887
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2888
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2889
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2890
     s next:1000 put:$1.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2891
     s close.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  2892
     ('test' asFilename fileSize) printCR.
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2893
     'test' asFilename truncateTo:100.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  2894
     ('test' asFilename fileSize) printCR.
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  2895
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2896
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2897
    "Modified: / 5.5.1999 / 13:41:59 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2898
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2899
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2900
!Filename methodsFor:'file queries'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2901
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2902
accessTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2903
    "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
  2904
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2905
    | i |
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2906
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2907
    (i := self info) isNil ifTrue:[^ nil].
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2908
    ^ i accessTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2909
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2910
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2911
     Filename currentDirectory accessTime 
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2912
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2913
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2914
    "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
  2915
    "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
  2916
    "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
  2917
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  2918
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2919
creationTime
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2920
    "return a timeStamp containing the files creation time.
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2921
     NOTICE: only windoof distinguishes creation from modification;
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2922
     under unix, nil is returned (callers should fall back and use mod-time then"
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2923
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2924
    |i|
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2925
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2926
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2927
    ^ i creationTime
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2928
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2929
    "
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2930
     Filename currentDirectory creationTime 
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2931
    "
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2932
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2933
    "Created: / 9.7.1996 / 10:18:59 / cg"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2934
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2935
    "Modified: / 14.8.1998 / 17:42:50 / cg"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2936
!
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  2937
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2938
dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2939
    "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
  2940
     that responds to the at: message with arguments 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2941
     #modified, #accessed or #statusChanged."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2942
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2943
    |info dates osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2944
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2945
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2946
    info := OperatingSystem infoOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2947
    info isNil ifTrue:[
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  2948
        "maybe this is a symbolic link with a broken link target.
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  2949
         Answer the dates of the link itself"
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2950
        info := OperatingSystem linkInfoOf:osName.
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2951
        info isNil ifTrue:[
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2952
            ^ nil
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2953
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2954
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2955
    dates := IdentityDictionary new.
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2956
    dates at:#created put:(info creationTime).
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2957
    dates at:#modified put:(info modificationTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2958
    dates at:#accessed put:(info accessTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  2959
    dates at:#statusChanged put:(info statusChangeTime).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2960
    ^ dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2961
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2962
    "
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  2963
     Filename currentDirectory dates  
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2964
     '../regression' asFilename dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2965
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2966
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  2967
    "Modified: 1.11.1996 / 20:19:24 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2968
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2969
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2970
fileSize
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2971
    "return the size of the file in bytes"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2972
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2973
    |i|
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2974
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2975
    (i := self info) isNil ifTrue:[^ nil].
6794
498d85323172 use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents: 6793
diff changeset
  2976
    ^ i fileSize
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2977
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  2978
    "Modified: / 17.8.1998 / 10:23:46 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2979
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2980
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2981
fileType
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2982
    "this returns a string describing the type of contents of
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2983
     the file. This is done using the unix 'file' command,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2984
     (which usually is configurable by /etc/magic).
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2985
     On non-unix systems, this may simply return 'file', 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2986
     not knowning about the contents.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2987
     Warning:
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2988
         Since the returned string differs among systems (and language settings),
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2989
         it is only useful for user-information; 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  2990
         NOT as a tag to be used by a program."
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2991
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  2992
    |buffer s n suffix idx baseNm info|
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2993
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2994
    "/ since we cannot depend on a 'file' command being available,
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2995
    "/ do the most obvious ones here. 
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2996
    "/ (also useful since the 'file' command takes some time, and the code
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  2997
    "/  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
  2998
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  2999
    info := self linkInfo.
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3000
    info isSymbolicLink ifTrue:[
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3001
        ^ 'symbolic link to ' , info path
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3002
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3003
    info isDirectory ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3004
        self isReadable ifFalse:[^ 'directory, unreadable'].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3005
        self isExecutable ifFalse:[^ 'directory, locked'].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3006
        ^ 'directory'
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  3007
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3008
    info isCharacterSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3009
        ^ 'character device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3010
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3011
    info isBlockSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3012
        ^ 'block device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3013
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3014
    info isSocket ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3015
        ^ 'socket'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3016
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3017
    info isFifo ifTrue:[
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3018
        ^ 'fifo'
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3019
    ].
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3020
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  3021
    self isReadable ifFalse:[^ 'unreadable'].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3022
    info fileSize == 0 ifTrue:[^ 'empty'].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  3023
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3024
    suffix := self suffix asLowercase.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3025
    baseNm := self withoutSuffix baseName asLowercase.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3026
6826
debb693dd98a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6804
diff changeset
  3027
    ((#('st' 'rc' 'chg' 'htm' 'html' 'ps' 'cls' 'pac') includes:suffix)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3028
    or:[#('makefile') includes:baseNm]) ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3029
7685
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7680
diff changeset
  3030
        buffer := String new:2048.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3031
        s := self readStreamOrNil.
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3032
        s notNil ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3033
            n := s nextBytes:buffer size into:buffer.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3034
            s close.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3035
            buffer := buffer asLowercase.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3036
            (#('st' 'cls') includes:suffix) ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3037
                #(
6826
debb693dd98a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6804
diff changeset
  3038
                        ('from squeak'        'smalltalk source (Squeak)')
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3039
                        ('from dolphin'       'smalltalk source (Dolphin)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3040
                        ('from visualworks'   'smalltalk source (VisualWorks)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3041
                        ('categoriesforclass' 'smalltalk source (Dolphin)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3042
                        ('methodsfor!!'        'smalltalk source (Dolphin, ST/V or V''age)')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3043
                        ('subclass:'          'smalltalk source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3044
                        ('methodsfor:'        'smalltalk source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3045
                 ) pairsDo:[:pattern :what | 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3046
                    (buffer findString:pattern) ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3047
                        ^ what
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3048
                    ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3049
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3050
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3051
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3052
            (buffer findString:'methodsfor:') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3053
                ^ 'smalltalk changes / method source'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3054
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3055
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3056
            (suffix = 'rc') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3057
                (buffer findString:'st/x startup') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3058
                    ^ 'smalltalk startup script'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3059
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3060
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3061
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3062
            (suffix = 'htm' or:[suffix = 'html']) ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3063
                (idx := buffer findString:'<h') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3064
                    ((buffer continuesWith:'<head' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3065
                    or:[(buffer continuesWith:'<html' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3066
                    or:[(buffer continuesWith:'<h1' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3067
                    or:[(buffer continuesWith:'<h2' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3068
                    or:[(buffer continuesWith:'<h3' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3069
                    or:[(buffer continuesWith:'<h4' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3070
                    or:[(buffer continuesWith:'<h5' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3071
                    or:[(buffer continuesWith:'<h6' startingAt:idx)]]]]]]])
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3072
                    ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3073
                        ^ 'HTML document text'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3074
                    ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3075
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3076
            ].
1614
4e1a64b19247 inline detect postscript documents
Claus Gittinger <cg@exept.de>
parents: 1612
diff changeset
  3077
        
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3078
            (suffix = 'ps') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3079
                (buffer findString:'%!!ps-adobe') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3080
                    ^ 'PostScript document'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3081
                ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3082
            ].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3083
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3084
            (baseNm = 'makefile') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3085
                (buffer startsWith:'#') ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3086
                    ^ 'make rules'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3087
                ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3088
            ]
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3089
        ]
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  3090
    ].
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3091
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3092
    ^ 'file'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3093
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3094
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3095
     'Makefile' asFilename fileType 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3096
     '.' asFilename fileType     
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3097
     '/dev/null' asFilename fileType 
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3098
     '/usr/tmp' asFilename fileType 
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3099
     '/tmp/.X11-unix/X0' asFilename fileType 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3100
     'smalltalk.rc' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3101
     'bitmaps/SBrowser.xbm' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3102
    "
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3103
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3104
    "Modified: / 21.7.1998 / 11:25:56 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3105
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3106
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3107
id
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3108
    "return the files/directories file-id (inode number)"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3109
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3110
    ^ OperatingSystem idOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3111
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3112
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3113
     Filename currentDirectory id 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3114
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3115
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3116
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3117
    "Created: 5.8.1997 / 19:26:01 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3118
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3119
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3120
info
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3121
    "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
  3122
     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
  3123
     the returned object) is:
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3124
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3125
	 type  - a symbol giving the files fileType
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3126
	 mode  - numeric access mode 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3127
	 uid   - owners user id
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3128
	 gid   - owners group id
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3129
	 size  - files size
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3130
	 id    - files number (i.e. inode number)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3131
	 accessed      - last access time (as osTime-stamp)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3132
	 modified      - last modification time (as osTime-stamp)
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3133
	 statusChanged - last staus change (as osTime-stamp)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3134
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3135
     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
  3136
     all of the information.
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3137
     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
  3138
	modified
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3139
	size
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3140
	type
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3141
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3142
     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
  3143
     to either handle nil values,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3144
     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
  3145
     (i.e. instead of:
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3146
	someFilename type == #directory
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3147
      use
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3148
	someFilename isDirectory
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3149
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3150
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3151
    ^ OperatingSystem infoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3152
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3153
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3154
     Filename currentDirectory info
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3155
     '/dev/null' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3156
     '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
  3157
     '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
  3158
     '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
  3159
     '../../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
  3160
     '.' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3161
     '..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3162
     '..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3163
     '..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3164
     '..\..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3165
     'c:\' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3166
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3167
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3168
    "Modified: / 17.8.1998 / 10:24:10 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3169
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3170
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3171
linkInfo
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3172
    "return the files info. If it is a symbolic link return the info of the link itself
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3173
     instead of the link's target.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3174
     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
  3175
     receiver represents a symbolic link, the links information 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3176
     is returned 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3177
     (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
  3178
      which is accessed via the symbolic link).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3179
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3180
     In addition to the normal entries, Unix returns an additional entry:
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3181
         path -> the target files pathname
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3182
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3183
     See the comment in #info for more details."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3184
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3185
    ^ OperatingSystem linkInfoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3186
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3187
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3188
     Filename currentDirectory linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3189
     '/dev/null' asFilename linkInfo    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3190
     'Make.proto' asFilename linkInfo   
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  3191
     'Make.proto' asFilename linkInfo path  
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3192
     'source/Point.st' asFilename linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3193
     '../../libbasic/Point.st' asFilename linkInfo 
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3194
     '/usr/tmp' asFilename linkInfo 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3195
    "
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  3196
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  3197
    "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
  3198
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3199
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3200
modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3201
    "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
  3202
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3203
    |i|
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3204
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3205
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3206
    ^ i modificationTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3207
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3208
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3209
     Filename currentDirectory modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3210
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3211
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3212
    "Created: / 9.7.1996 / 10:18:59 / cg"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3213
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3214
    "Modified: / 14.8.1998 / 17:42:50 / cg"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3215
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3216
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3217
type
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3218
    "return the symbolic type of the file"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3219
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3220
    ^ OperatingSystem typeOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3221
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3222
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3223
     Filename currentDirectory type 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3224
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3225
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3226
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3227
    "Created: 5.8.1997 / 19:31:26 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3228
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3229
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3230
!Filename methodsFor:'file utilities'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3231
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3232
edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3233
    "start an editView on the file represented by the receiver"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3234
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3235
    EditTextView openOn:self asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3236
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3237
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3238
     'smalltalk.rc' asFilename edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3239
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3240
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3241
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3242
fileIn
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3243
    "load smalltalk code from the file"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3244
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  3245
    |s rslt|
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  3246
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  3247
    s := self readStream.
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  3248
    [
6422
d91c6082c200 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6402
diff changeset
  3249
        rslt := s fileIn.
d91c6082c200 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6402
diff changeset
  3250
    ] ensure:[
d91c6082c200 #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 6402
diff changeset
  3251
        s close.
5200
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  3252
    ].
2f5ba099906e close file after fileIn
Claus Gittinger <cg@exept.de>
parents: 5174
diff changeset
  3253
    ^ rslt.
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  3254
! !
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  3255
2
claus
parents: 1
diff changeset
  3256
!Filename methodsFor:'instance creation'!
claus
parents: 1
diff changeset
  3257
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3258
construct:subname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3259
    "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
  3260
     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
  3261
     (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
  3262
     The argument may not specify an absolute path name.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3263
     Please do not use this to create filenames with suffixes,
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3264
     since some systems require special naming conventions.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3265
     See also: #withSuffix: (which is different, but often needed)."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3266
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  3267
    ^ self class named:(self constructString:subname)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3268
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3269
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3270
     '/tmp' asFilename construct:'foo'    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3271
     '/' asFilename construct:'foo'         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3272
     '/usr/tmp' asFilename construct:'foo'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3273
     '/foo/bar' asFilename construct:'baz' 
6670
7792348f31e7 Comments
Stefan Vogel <sv@exept.de>
parents: 6662
diff changeset
  3274
     '/foo/bar' asFilename construct:'baz' asFilename 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3275
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3276
     Bad example; works on UNIX, but may not on others:
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3277
       'foo/bar.baz' construct:'.suff'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3278
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3279
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3280
    "Modified: 29.2.1996 / 20:55:06 / cg"
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3281
!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3282
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3283
constructDirectory:subname
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3284
    "same as #construct: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3285
     (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
  3286
     
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3287
    ^ self class named:(self constructDirectoryString:subname)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3288
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3289
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3290
constructDirectoryString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3291
    "same as #constructString: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3292
     (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
  3293
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3294
    ^ self constructString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3295
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3296
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3297
constructString:subName
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3298
    "taking the receiver as a directory name, construct a new
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3299
     filename-string for an entry within this directory 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3300
     (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
  3301
     The argument may not specify an absolute path name.
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3302
     The code below works for UNIX & MSDOS; 
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3303
     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
  3304
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3305
    |sepString sub|
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3306
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3307
    sub := subName asString.
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  3308
    sepString := self class separatorString.
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  3309
    nameString size == 0 ifTrue:[
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  3310
        ^ sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3311
    ].
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3312
    (nameString endsWith:sepString) ifTrue:[
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  3313
        ^ nameString , sub
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  3314
    ].
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3315
    ^ nameString , sepString , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3316
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3317
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3318
     '/tmp' asFilename constructString:'foo'   
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3319
     '/' asFilename constructString:'foo'         
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3320
     '/usr/tmp' asFilename constructString:'foo'
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3321
     '/foo/bar' asFilename constructString:'baz' 
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  3322
     '' asFilename constructString:'baz' 
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3323
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3324
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3325
    "Modified: / 7.9.1995 / 10:15:22 / claus"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3326
    "Created: / 9.9.1997 / 08:57:08 / cg"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3327
    "Modified: / 20.1.1998 / 15:58:23 / md"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3328
    "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
  3329
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3330
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3331
filenameFor:fileName
6973
c46e1d005ea4 comment
Claus Gittinger <cg@exept.de>
parents: 6943
diff changeset
  3332
    "return a filename representing the argument, fileName
c46e1d005ea4 comment
Claus Gittinger <cg@exept.de>
parents: 6943
diff changeset
  3333
     either in myself (if the arg is a releative path) or absolute otherwise."
2944
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3334
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3335
    |f|
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3336
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3337
    f := fileName asFilename.
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3338
    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
  3339
    ^ (self construct:fileName)
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3340
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3341
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3342
     '/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
  3343
     '/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
  3344
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3345
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3346
    "Created: 18.9.1997 / 14:34:14 / stefan"
2
claus
parents: 1
diff changeset
  3347
! !
claus
parents: 1
diff changeset
  3348
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3349
!Filename methodsFor:'misc'!
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3350
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3351
, aString
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3352
    "this allows filenames to understand how names are concatenated.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  3353
     Returns a string consisting of the receivers name, concatenated
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3354
     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
  3355
     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
  3356
     See also: #withSuffix: which is new and better."
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3357
5866
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  3358
    <resource:#obsolete>
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  3359
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3360
    self obsoleteMethodWarning:'use #construct:'.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  3361
    ^ (nameString , aString asString)
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3362
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3363
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3364
     'Makefile' asFilename , '.bak'        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3365
     ('Makefile' asFilename , '.bak') asFilename  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3366
     'Makefile' asFilename withSuffix:'bak' 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3367
     'Makefile' asFilename construct:'.bak'     
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3368
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3369
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3370
    "Modified: 7.9.1997 / 23:45:36 / cg"
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3371
! !
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  3372
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3373
!Filename methodsFor:'printing & storing'!
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3374
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3375
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  3376
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  3377
     The format is suitable for a human - not meant to be read back."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3378
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3379
    aStream nextPutAll:(self class name).
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3380
    aStream nextPutAll:'('''.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3381
    nameString printOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3382
    aStream nextPutAll:''')'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3383
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3384
    "Modified: 7.9.1997 / 23:46:20 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3385
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3386
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3387
storeOn:aStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3388
    "append a printed representation of the receiver to aStream,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3389
     which allows reconstructing it via readFrom:"
328
claus
parents: 326
diff changeset
  3390
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3391
    aStream nextPut:$(.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3392
    nameString storeOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3393
    aStream nextPutAll:' asFilename)'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3394
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3395
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7236
diff changeset
  3396
!Filename methodsFor:'private-accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3397
6227
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3398
getName
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3399
    "get the raw filename"
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3400
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3401
    ^ nameString 
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3402
!
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  3403
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3404
setName:aString
38
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  3405
    "set the filename"
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  3406
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3407
    nameString := self nameWithSpecialExpansions:aString.
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3408
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3409
    "Modified: / 21.7.1998 / 10:44:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3410
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  3411
2
claus
parents: 1
diff changeset
  3412
!Filename methodsFor:'queries'!
claus
parents: 1
diff changeset
  3413
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3414
canBeWritten
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3415
    "same as isWritable - for ST-80 compatibility"
328
claus
parents: 326
diff changeset
  3416
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3417
    ^ self isWritable
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3418
328
claus
parents: 326
diff changeset
  3419
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3420
     '/foo/bar' asFilename canBeWritten 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3421
     '/tmp' asFilename canBeWritten   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3422
     'Makefile' asFilename canBeWritten   
328
claus
parents: 326
diff changeset
  3423
    "
claus
parents: 326
diff changeset
  3424
!
claus
parents: 326
diff changeset
  3425
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3426
exists
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3427
    "return true, if such a file exists."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3428
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3429
    ^ OperatingSystem isValidPath:(self osNameForAccess)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  3430
85
claus
parents: 77
diff changeset
  3431
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3432
     '/foo/bar' asFilename exists 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3433
     '/tmp' asFilename exists  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  3434
     'Makefile' asFilename exists   
85
claus
parents: 77
diff changeset
  3435
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3436
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  3437
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3438
filenamesMatching:aPattern
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3439
    "VW compatibility"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3440
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3441
    ^ (self filesMatching:aPattern) asOrderedCollection
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3442
	    collect:[:eachName | self construct:eachName]
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3443
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3444
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3445
     '/etc' asFilename filenamesMatching:'a*;c*' 
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3446
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3447
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3448
    "Created: / 15.4.1997 / 15:40:02 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3449
    "Modified: / 3.8.1998 / 21:22:15 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3450
!
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  3451
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3452
filesMatching:aPattern
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3453
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3454
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3455
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3456
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3457
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3458
    |matchers notCaseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3459
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3460
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3461
    notCaseSensitive := self class isCaseSensitive not.
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3462
    ^ self directoryContents
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3463
	select:[:name | 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3464
		(matchers detect:[:p | p match:name ignoreCase:notCaseSensitive] ifNone:0) ~~ 0
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3465
	       ]
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3466
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3467
    "
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3468
     '/etc' asFilename filesMatching:'a*;c*' 
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3469
    "
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3470
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3471
    "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
  3472
    "Modified: / 3.8.1998 / 21:22:15 / cg"
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3473
!
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3474
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3475
filesMatchingWithoutDotDirs:aPattern
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3476
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3477
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3478
     Exclude '.' and '..' from the returned list.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3479
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3480
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3481
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3482
    |matchers notCaseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3483
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3484
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3485
    notCaseSensitive := self class isCaseSensitive not.
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3486
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3487
    ^ self directoryContents 
6085
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3488
	select:[:name | 
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3489
		name ~= '.'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3490
		and:[name ~= '..'
94355d623def *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5934
diff changeset
  3491
		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
  3492
      ]
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3493
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3494
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3495
     Filename currentDirectory filesMatching:'M*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3496
     '/etc' asFilename filesMatching:'[a-z]*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3497
     '../../libbasic' asFilename filesMatching:'[A-D]*.st'  
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3498
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  3499
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  3500
    "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
  3501
    "Modified: / 3.8.1998 / 21:22:30 / cg"
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3502
!
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  3503
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3504
isExecutable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3505
    "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
  3506
     For directories, true is returned if the directory can be entered.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3507
     See isExecutableProgram for a related check."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3508
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3509
    ^ OperatingSystem isExecutable:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3510
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3511
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3512
     '/foo/bar' asFilename isExecutable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3513
     '/tmp' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3514
     'Makefile' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3515
     '/bin/ls' asFilename isExecutable   
356
claus
parents: 328
diff changeset
  3516
    "
claus
parents: 328
diff changeset
  3517
!
claus
parents: 328
diff changeset
  3518
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3519
isExecutableProgram
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3520
    "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
  3521
     (i.e. for directories, false is returned.)"
356
claus
parents: 328
diff changeset
  3522
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3523
    |osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3524
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3525
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3526
    ^ (OperatingSystem isExecutable:osName)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3527
      and:[(OperatingSystem isDirectory:osName) not]
356
claus
parents: 328
diff changeset
  3528
claus
parents: 328
diff changeset
  3529
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3530
     '/tmp' asFilename isExecutable         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3531
     '/bin/ls' asFilename isExecutable       
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3532
     '/tmp' asFilename isExecutableProgram   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3533
     '/bin/ls' asFilename isExecutableProgram    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3534
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3535
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3536
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3537
isHidden
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3538
    "return true, if the receiver represents a hidden file.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3539
     The definitions of hidden files depends on the OS used;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3540
     on UNIX, a name starting with a period is considered hidden;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3541
     on MSDOS, the files hidden attribute is used.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3542
     VMS has no concept of hidden files."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3543
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3544
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3545
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3546
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3547
isMountPoint:aPathName
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3548
    "return true, if I represent a mount-point.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3549
     Warning: 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3550
        the receiver must be an absolute pathname, 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3551
        because a realPath is not used/generated for the query (to avoid automounting).
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3552
        Aka: do not ask: '../../' asFilename isMountPoint;
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3553
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3554
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3555
    self isAbsolute ifFalse:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3556
        self error:'this query must be done on an absolute pathname'.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3557
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3558
    ^ OperatingSystem isMountPoint:(self name)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3559
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  3560
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3561
isReadable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3562
    "return true, if such a file exists and is readable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3563
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3564
    ^ OperatingSystem isReadable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3565
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3566
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3567
     '/foo/bar' asFilename isReadable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3568
     '/tmp' asFilename isReadable      
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3569
     'Makefile' asFilename isReadable   
328
claus
parents: 326
diff changeset
  3570
    "
claus
parents: 326
diff changeset
  3571
!
claus
parents: 326
diff changeset
  3572
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3573
isWritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3574
    "return true, if such a file exists and is writable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3575
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3576
    ^ OperatingSystem isWritable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3577
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3578
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3579
     '/foo/bar' asFilename isWritable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3580
     '/tmp' asFilename isWritable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3581
     'Makefile' asFilename isWritable   
328
claus
parents: 326
diff changeset
  3582
    "
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3583
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  3584
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3585
separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3586
    "return the directory-separator character"
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 class separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3589
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3590
    "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
  3591
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3592
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3593
!Filename methodsFor:'queries-contents'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3594
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3595
mimeTypeFromName
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3596
    "return the mimeType as guessed from the files name/and or extension.
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3597
     This could be less accurate than mimeTypeOfContents, but avoids
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3598
     reading the file (is therefore much faster).
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3599
     Also it works with non-existing files.
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3600
     Returns nil for directories and other non-regular files."
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3601
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3602
    ^ MIMETypes mimeTypeForFilename:(self name)
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3603
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3604
    "
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3605
     'Makefile' asFilename mimeTypeFromName     
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3606
     '.' asFilename mimeTypeFromName            
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3607
     '/dev/null' asFilename mimeTypeFromName   
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3608
     '/tmp/.X11-unix/X0' asFilename mimeTypeFromName  
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3609
     'smalltalk.rc' asFilename mimeTypeFromName     
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3610
     'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName    
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3611
     '../../rules/stmkmf' asFilename mimeTypeFromName  
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3612
     '/bläh' asFilename mimeTypeFromName               
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3613
    "
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3614
!
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  3615
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3616
mimeTypeOfContents
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3617
    "this tries to guess the mime type of contents of
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3618
     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
  3619
     or the contents is unknown.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3620
     This is done using some heuristics, and may need some improvement"
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3621
8036
35bf398bb5d8 #mimeTypeOfContents do not ask for baseName and suffix (opt. win)
ca
parents: 7888
diff changeset
  3622
    |type buffer s size idx idx2|
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3623
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3624
    type := self type.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3625
    type isNil ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3626
        ^ nil.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3627
    ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3628
    type == #directory ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3629
        ^ nil
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3630
    ].                                                              
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3631
    type == #characterSpecial ifTrue:[
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3632
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3633
    ].
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3634
    type == #blockSpecial ifTrue:[                                     
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3635
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3636
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3637
    type == #socket ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3638
        ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3639
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3640
    self fileSize == 0 ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3641
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3642
    s := self readStreamOrNil.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3643
    s isNil ifTrue:[^ nil].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3644
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3645
    "/ read some data from the file ...
7685
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7680
diff changeset
  3646
    buffer := String new:2048.
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3647
6943
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  3648
    s errorSignal handle:[:ex |
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  3649
        size := 0.
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  3650
    ] do:[
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  3651
        size := s nextBytes:buffer size into:buffer.
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  3652
    ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3653
    s close.
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3654
    buffer := buffer asLowercase.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3655
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3656
    (idx := buffer findString:'mimetype:') ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3657
        idx := idx + 'mimetype:' size.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3658
        idx := buffer indexOfNonSeparatorStartingAt:idx.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3659
        idx2 := buffer indexOfSeparatorStartingAt:idx.
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3660
        idx2 > idx ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3661
            ^ buffer copyFrom:idx to:idx2-1
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3662
        ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3663
    ].
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3664
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3665
    #(
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3666
            ('interchangeversion:'       'application/x-smalltalk-source-sif')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3667
            ('subclass:'                 'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3668
            ('methodsfor:'               'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3669
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3670
            ('<body:'                    'text/html')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3671
            ('%!!ps-adobe'                'application/postscript')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3672
            ('#!! /bin/sh'                'application/x-sh')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3673
            ('#!!/bin/sh'                 'application/x-sh')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3674
            "/ ('#!! /bin/bash'              'application/x-bash')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3675
            "/ ('#!!/bin/bash'               'application/x-bash')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3676
            ('<?xml version='            'text/xml')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3677
        
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3678
            ('from dolphin'              'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3679
            ('from visualworks'          'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3680
            ('categoriesforclass' 'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3681
            ('methodsfor!!'        'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3682
            ('subclass:'          'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3683
            ('methodsfor:'        'application/x-smalltalk-source')
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3684
     ) pairsDo:[:pattern :what | 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3685
        (buffer findString:pattern) ~~ 0 ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3686
            ^ what
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3687
        ]
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3688
    ].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3689
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3690
    (idx := buffer findString:'<H') ~~ 0 ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3691
        ((buffer continuesWith:'<HEAD' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3692
        or:[(buffer continuesWith:'<HTML' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3693
        or:[(buffer continuesWith:'<H1' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3694
        or:[(buffer continuesWith:'<H2' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3695
        or:[(buffer continuesWith:'<H3' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3696
        or:[(buffer continuesWith:'<H4' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3697
        or:[(buffer continuesWith:'<H5' startingAt:idx)
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3698
        or:[(buffer continuesWith:'<H6' startingAt:idx)]]]]]]])
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3699
        ifTrue:[
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3700
            ^ 'text/html'
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3701
        ]
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3702
    ].
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3703
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3704
    [size ~~ 0 and:[(buffer at:size) isPrintable]] whileTrue:[size := size - 1].
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3705
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3706
    size == 0 ifTrue:[
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3707
        ^ 'text/plain'
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3708
    ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3709
    ^ nil
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3710
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3711
    "
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3712
     'Makefile' asFilename mimeTypeOfContents     
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  3713
     '.' asFilename mimeTypeOfContents            
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3714
     '/dev/null' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3715
     '/tmp/.X11-unix/X0' asFilename mimeTypeOfContents 
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3716
     'smalltalk.rc' asFilename mimeTypeOfContents    
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3717
     'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents    
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3718
     '../../rules/stmkmf' asFilename mimeTypeOfContents
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3719
     '/bläh' asFilename mimeTypeOfContents
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3720
    "
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  3721
5012
3134cc1bd02b checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5011
diff changeset
  3722
    "Modified: / 19.11.1999 / 15:58:29 / cg"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3723
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3724
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3725
!Filename methodsFor:'queries-path & name'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3726
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3727
baseName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3728
    "return my baseName as a string.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3729
     - thats the file/directory name without leading parent-dirs.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3730
     (i.e. '/usr/lib/st/file' asFilename baseName -> 'file'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3731
       and '/usr/lib'         asFilename baseName -> lib).
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  3732
     This method does not check if the path is valid.
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  3733
     The code here should work for Unix and MSDOS, but needs to be redefined
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  3734
     for VMS (and maybe others as well).
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3735
     See also: #pathName, #directoryName and #directoryPathName.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3736
     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
  3737
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3738
    |len index sep endIdx|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3739
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3740
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3741
    len := nameString size.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3742
    ((len == 1) and:[(nameString at:1) == sep]) ifTrue:[
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  3743
        ^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3744
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3745
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3746
    endIdx := len.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3747
    len > 1 ifTrue:[
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  3748
        (nameString at:len) == sep ifTrue:[endIdx := endIdx - 1].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3749
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3750
    index := nameString lastIndexOf:sep startingAt:len-1.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3751
    ^ 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
  3752
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3753
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3754
     '/foo/bar' asFilename baseName  
4903
1487c740eaba comment
Claus Gittinger <cg@exept.de>
parents: 4901
diff changeset
  3755
     '/foo/bar.cc' asFilename baseName  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3756
     '.' asFilename baseName          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3757
     '..' asFilename baseName         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3758
     '../..' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3759
     '../../libbasic' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3760
     '../../libpr' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3761
     '../../libbasic/Object.st' asFilename baseName        
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3762
     '/' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3763
     '\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3764
     'c:\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3765
     '\\idefix' asFilename baseName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3766
    "
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3767
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  3768
    "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
  3769
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3770
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3771
directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3772
    "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
  3773
     - 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
  3774
       the receiver is contained in.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3775
     (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
  3776
      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
  3777
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  3778
    ^ self class named:(self directoryName)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3779
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3780
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3781
     '/foo/bar' asFilename directory      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3782
     '/foo/bar' asFilename directoryName  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3783
     '/foo/bar' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3784
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3785
     '.' asFilename directory        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3786
     '..' asFilename directory       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3787
     '../..' asFilename directory     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3788
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3789
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3790
    "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
  3791
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3792
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3793
directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3794
    "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
  3795
     - 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
  3796
       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
  3797
     This method does not check if the path is valid.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3798
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3799
     (i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3800
       and '/usr/lib' asFilename directoryName         -> /usr').
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3801
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3802
     (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
  3803
      a string instead of a Filename instance).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3804
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3805
     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
  3806
     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
  3807
3954
20cc39f4e75c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3893
diff changeset
  3808
    |index sep sepString p rest|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3809
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3810
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3811
    sepString := sep asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3812
    (nameString = sepString) ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3813
        "/
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3814
        "/ the trivial '/' case
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3815
        "/
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3816
        ^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3817
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3818
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3819
    "/
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3820
    "/ strip off multiple trailing slashes
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3821
    "/
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3822
    p := nameString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3823
    [p endsWith:sepString] whileTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3824
        (p = sepString) ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3825
            ^ p
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3826
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3827
        p := p copyWithoutLast:1
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3828
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3829
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3830
    "/ strip off trailing components
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3831
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3832
    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
  3833
    index == 0 ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3834
        "/ no separator found
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3835
        p = '.' ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3836
            ^ '..'
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3837
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3838
        p = '..' ifTrue:[
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3839
            ^ '../..'
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3840
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3841
        ^ '.'
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3842
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3843
    rest := p copyFrom:(index+1).
7342
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  3844
    (rest = '.') ifTrue:[
7519
0cfe202e7e3e #directoryName returned a Filename
Stefan Vogel <sv@exept.de>
parents: 7473
diff changeset
  3845
        ^ p copyTo:index-1.
7342
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  3846
    ].
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  3847
    (rest = '..') ifTrue:[
7343
Claus Gittinger <cg@exept.de>
parents: 7342
diff changeset
  3848
        ^ (self class named:(p copyTo:(index-1))) directoryName
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3849
    ].
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3850
    index == 1 ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3851
        ^ '/'
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3852
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3853
    ^ p copyTo:(index - 1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3854
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3855
    "
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3856
     '/home' asFilename directoryName          
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3857
     '/foo/bar/' asFilename directoryName    
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3858
     '/foo/bar/' asFilename directory      
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3859
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3860
     '/foo/bar' asFilename directoryName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3861
     'bitmaps' asFilename directoryName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3862
     'bitmaps' asFilename directoryPathName        
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  3863
     '.' asFilename directoryName           
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3864
     '.' asFilename directoryPathName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3865
     '..' asFilename directoryName       
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  3866
     '..' asFilename directoryPathName       
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3867
     '../..' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3868
     '../..' asFilename directoryPathName     
7343
Claus Gittinger <cg@exept.de>
parents: 7342
diff changeset
  3869
     '/foo/bar/baz/..' asFilename directoryName     
Claus Gittinger <cg@exept.de>
parents: 7342
diff changeset
  3870
     '/foo/bar/baz/.' asFilename directoryName     
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3871
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3872
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  3873
    "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
  3874
    "Modified: / 21.10.1998 / 22:52:25 / cg"
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  3875
    "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
  3876
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3877
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3878
directoryPathName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3879
    "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
  3880
     - 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
  3881
       the receiver is contained in.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3882
     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
  3883
4373
87d2d048e232 return instances of my class when asking for directory etc.
Claus Gittinger <cg@exept.de>
parents: 4324
diff changeset
  3884
    ^ (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
  3885
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3886
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3887
     '/foo/bar/' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3888
     '/foo/bar' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3889
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3890
     '.' asFilename directoryPathName      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3891
     '.' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3892
     '.' asFilename directory          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3893
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3894
     '..' asFilename directoryPathName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3895
     '..' asFilename directoryName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3896
     '..' asFilename directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3897
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3898
     '../..' asFilename directoryPathName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3899
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3900
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3901
    "Modified: 7.9.1995 / 10:42:13 / claus"
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  3902
    "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
  3903
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3904
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3905
filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3906
    "try to complete the receiver filename.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3907
     BAD DESIGN: has side effect on the receiver.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3908
     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
  3909
       it returns a collection of matching filename objects,
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3910
       and changes the receivers filename-string to the longest common
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3911
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3912
     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
  3913
     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
  3914
     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
  3915
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3916
    ^ self filenameCompletionIn:nil
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3917
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3918
    " 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3919
     'mak' asFilename filenameCompletion  
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3920
     'Make' asFilename filenameCompletion  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3921
     'Makef' asFilename filenameCompletion;yourself  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3922
     '/u' asFilename filenameCompletion             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3923
     '../../libpr' asFilename inspect filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3924
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3925
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  3926
    "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
  3927
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3928
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3929
filenameCompletionIn:aDirectory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3930
    "try to complete the receiver filename.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3931
     BAD DESIGN: has side effect on the receiver.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3932
     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
  3933
       it returns a collection of matching filename objects,
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3934
       and changes the receivers filename-string to the longest common
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3935
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3936
     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
  3937
     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
  3938
     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
  3939
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3940
    |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
  3941
     sepString parentString prefix nMatch nm caseless lcBaseName|
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3942
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3943
    caseless := self class isCaseSensitive not.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3944
    matching := OrderedCollection new.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3945
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3946
    nm := self nameWithSpecialExpansions:nameString.
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
  3947
    nm := self class canonicalize:nm.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3948
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  3949
    sepString := self class separatorString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3950
    (nm endsWith:sepString) ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3951
        "/ two exceptions here: 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3952
        "/   if there is only one file in the directory, that one must be it.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3953
        "/   otherwise, return the longest common prefix of all files.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3954
        self isDirectory ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3955
            |first longest|
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3956
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3957
            first := nil.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3958
            self directoryContentsDo:[:fileName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3959
                ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3960
                    matching add:fileName.    
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3961
                    first isNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3962
                        first := longest := fileName.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3963
                    ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3964
                        "/ more than one file
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3965
                        longest := longest commonPrefixWith:fileName ignoreCase:caseless.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3966
                        longest isEmpty ifTrue:[ ^ #() ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3967
                    ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3968
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3969
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3970
            longest notNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3971
                nameString := (self constructString:longest).
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3972
                 ^ matching
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3973
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3974
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3975
        ^ #()
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3976
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3977
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3978
    parentString := self class parentDirectoryName.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3979
    baseName := self baseName.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  3980
    baseName ~= nm ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3981
        prefix := self directoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3982
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3983
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3984
    self isAbsolute ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3985
        dir := self directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3986
    ] ifFalse:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3987
        aDirectory isNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3988
            dir := self directory
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3989
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3990
            dir := (aDirectory construct:nm) directory
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3991
        ]
1049
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
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3994
    caseless ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3995
        lcBaseName := baseName asLowercase
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3996
    ].
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  3997
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  3998
    dir class errorReporter openErrorSignal handle:[:ex|
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  3999
        ^ #().
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4000
    ] do:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4001
        dir directoryContents do:[:fileName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4002
            ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4003
                ((caseless and:[fileName asLowercase startsWith:lcBaseName])
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4004
                or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4005
                    matching add:fileName
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4006
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4007
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4008
        ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4009
    ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4010
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4011
    (nMatch := matching size) > 1 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4012
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4013
         find the longest common prefix
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4014
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4015
        matchLen := baseName size.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4016
        matchLen > matching first size ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4017
            try := baseName.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4018
            allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4019
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4020
            try := matching first copyTo:matchLen.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4021
            allMatching := true.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4022
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4023
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4024
        [allMatching] whileTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4025
            matching do:[:aName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4026
                ((caseless and:[aName asLowercase startsWith:try asLowercase])
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4027
                or:[caseless not and:[aName startsWith:try]]) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4028
                    allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4029
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4030
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4031
            allMatching ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4032
                matchLen <  matching first size ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4033
                    matchLen := matchLen + 1.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4034
                    try := matching first copyTo:matchLen.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4035
                ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4036
                    allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4037
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4038
            ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4039
                try := matching first copyTo:matchLen - 1.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4040
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4041
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4042
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4043
         and set my name to the last full match
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4044
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4045
        nameString := nm := try
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4046
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4047
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4048
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4049
     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
  4050
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4051
    prefix notNil ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4052
        prefix = sepString ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4053
            "/ avoid introducing double slashes
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4054
            prefix := ''
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4055
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4056
        matching := matching collect:[:n | prefix , sepString , n].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4057
        nMatch == 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4058
            nameString := nm := matching first
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4059
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4060
            nMatch > 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4061
                nameString := nm := prefix , sepString , nm
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4062
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4063
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4064
    ] ifFalse:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4065
        nMatch == 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4066
            nameString := nm := matching first
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4067
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4068
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4069
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4070
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4071
     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
  4072
     (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
  4073
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4074
    ^ matching
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4075
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4076
    " trivial cases:
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4077
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4078
     '../' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4079
     '/' asFilename filenameCompletion      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4080
     '/usr/' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4081
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4082
     'mak' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4083
     'Make' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4084
     'Makef' asFilename filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4085
     '/u' asFilename filenameCompletion             
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4086
     '../../libpr' asFilename filenameCompletion
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4087
     '/etc/mail/auth/xx' asFilename filenameCompletion
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4088
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4089
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  4090
    "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
  4091
    "Modified: / 30.4.1999 / 09:39:52 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  4092
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  4093
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4094
head 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4095
    "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
  4096
     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
  4097
     (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
  4098
      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
  4099
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4100
    ^ self directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4101
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4102
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4103
     Filename currentDirectory head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4104
     'Makefile' asFilename head    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4105
     '/foo/bar/baz.st' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4106
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4107
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4108
    "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
  4109
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4110
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4111
isAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4112
    "return true, if the receiver represents an absolute pathname
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4113
     (in contrast to one relative to the current directory)."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4114
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4115
    (nameString startsWith:self class separator) ifTrue:[^ true].
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4116
    ^ self isVolumeAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4117
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4118
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4119
     '/foo/bar' asFilename isAbsolute   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4120
     '..' asFilename isAbsolute         
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4121
     '..' asAbsoluteFilename isAbsolute         
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4122
     'source/SBrowser.st' asFilename isAbsolute  
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4123
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4124
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4125
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4126
isExplicitRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4127
    "return true, if this name is an explicit relative name
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4128
     (i.e. starts with './' or '../', to avoid path-prepending)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4129
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4130
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4131
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4132
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4133
isImplicit
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4134
    "return true, if the receiver represents a builtin file.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4135
     The definitions of builtin files depends on the OS used;
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4136
     on UNIX, '.' and '..' are builtin names."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4137
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4138
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4139
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4140
    "Created: 18.9.1997 / 18:04:51 / stefan"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4141
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4142
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4143
isParentDirectoryOf:aFilenameOrString
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4144
    "warning: may lead to automounting"
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4145
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4146
    |filenameArg otherName myName|
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4147
7236
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  4148
    filenameArg := aFilenameOrString asFilename.
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  4149
    filenameArg isDirectory ifFalse:[
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  4150
        filenameArg := filenameArg directory.
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  4151
    ].
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4152
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4153
    otherName := filenameArg name.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4154
    myName := self name.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4155
    (otherName startsWith:myName ) ifTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4156
        ^ (otherName ~= myName)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4157
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4158
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4159
    otherName := filenameArg pathName.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4160
    myName := self pathName.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4161
    (otherName startsWith:myName ) ifTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4162
        ^ (otherName ~= myName)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4163
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4164
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4165
    filenameArg allParentDirectoriesDo:[:parent |
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4166
        parent pathName = myName ifTrue:[^ true].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4167
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4168
    ^ false.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4169
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4170
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4171
     '/etc' asFilename isParentDirectoryOf:'/etc/passwd' 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4172
     '/etc' asFilename isParentDirectoryOf:'/etc/'   
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4173
     '/etc' asFilename isParentDirectoryOf:'/etc'   
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4174
     '/home' asFilename isParentDirectoryOf:Filename currentDirectory 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4175
     '/' asFilename isParentDirectoryOf:'/phys/qnx'      
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4176
    "       
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4177
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4178
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4179
isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4180
    "return true, if this name is interpreted relative to some
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4181
     directory (opposite of absolute)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4182
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4183
    ^ self isAbsolute not
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4184
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4185
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4186
     './foo/bar' asFilename isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4187
     '../../foo/bar' asFilename isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4188
     '/foo/bar' asFilename isRelative     
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4189
     'bar' asFilename isRelative          
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4190
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4191
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4192
    "Modified: 16.1.1997 / 01:19:14 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4193
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4194
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4195
isRootDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4196
    "return true, if I represent the root directory 
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4197
     (i.e. I have no parentDir)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4198
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4199
    "/ mhmh - should we use:
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4200
    "/
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4201
    "/ parentDir := self construct:'..'.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4202
    "/ (parentDir exists
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4203
    "/ and:[parentDir isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4204
    "/ and:[parentDir id ~= self id]]) ifTrue:[
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4205
    "/    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4206
    "/ ].
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4207
    "/ ^ true
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4208
    "/
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4209
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4210
    ^ self pathName = Filename rootDirectory pathName
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4211
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4212
    "Modified: 23.10.1997 / 00:38:35 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4213
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4214
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4215
isVolumeAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4216
    "return true, if the receiver represents an absolute pathname
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4217
     on some disk volume (MSDOS only)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4218
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4219
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4220
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4221
    "Modified: 7.9.1997 / 23:54:33 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4222
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4223
2987
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4224
localPathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4225
    "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
  4226
     but without any volume information.
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4227
     Only makes a difference on MSDOS & VMS systems."
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4228
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4229
    ^ self pathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4230
!
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  4231
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4232
name
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4233
    "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
  4234
     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
  4235
     See also: pathName"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4236
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4237
"/    self isAbsolute ifTrue:[^ self pathName].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4238
    ^ nameString
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4239
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4240
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4241
     '/foo/bar' asFilename name        
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4242
     '/foo/bar' asFilename pathName    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4243
     '.' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4244
     '.' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4245
     '../..' asFilename name             
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4246
     '../..' asFilename pathName 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4247
     'bitmaps' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4248
     'bitmaps' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4249
     '/tmp/../usr' asFilename name       
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4250
     '/tmp/../usr' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4251
     'source/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4252
     'source/..' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4253
     '/tmp/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4254
     '/tmp/..' asFilename pathName    
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4255
    "
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4256
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  4257
    "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
  4258
!
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4259
7308
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4260
nameString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4261
    "raw access to nameString - req'd for xml-store/reload"
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4262
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4263
    ^ nameString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4264
!
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4265
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4266
nameString:aString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4267
    "raw access to nameString - req'd for xml-store/reload"
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4268
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4269
    nameString := aString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4270
!
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  4271
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4272
pathName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4273
    "return the full pathname of the file represented by the receiver,
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4274
     as a string. This will not include ..'s. 
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4275
     If the path represented by the receiver does NOT represent a valid path,
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4276
     no compression will be done (for now; this may change).
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4277
     See also: name"
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4278
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4279
    |p|
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  4280
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4281
"/    sep := self class separator.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4282
"/    (nameString startsWith:sep) ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4283
"/        parentName := self class parentDirectoryName.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4284
"/        (nameString findString:parentName) == 0 ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4285
"/            ^ nameString
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4286
"/        ]
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4287
"/    ].
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4288
    p := OperatingSystem pathNameOf:nameString.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4289
    ^ p
2
claus
parents: 1
diff changeset
  4290
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4291
    "
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4292
     '/foo/bar' asFilename pathName  
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4293
     '.' asFilename pathName         
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4294
     '../..' asFilename pathName     
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4295
     '../..' asFilename name           
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4296
     '/tmp/../usr' asFilename pathName   
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4297
     '/././usr' asFilename pathName     
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4298
    "
159
514c749165c3 *** empty log message ***
claus
parents: 132
diff changeset
  4299
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  4300
    "Modified: 27.4.1996 / 18:19:52 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4301
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4302
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4303
physicalPathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4304
    "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
  4305
     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
  4306
     final target. Otherwise, its the receivers pathName itself.
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4307
     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
  4308
     nil is returned."
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4309
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4310
    |t path info|
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4311
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4312
    info := self linkInfo.
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4313
    info isNil ifTrue:[
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4314
        " I do not exist"
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4315
        ^ nil.
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4316
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4317
    info isSymbolicLink ifFalse:[
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4318
        ^ self pathName
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4319
    ].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4320
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4321
    t := self.
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4322
    [
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4323
        path := info path.
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4324
        path isNil ifTrue:[
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4325
            "/ cannot happen
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4326
            ^ nil
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4327
        ].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4328
        t := (self class named:t directoryName) construct:path.
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4329
        info := t linkInfo.
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4330
        info isNil ifTrue:[
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4331
            "t does not exist"
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4332
             ^ nil
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4333
        ].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4334
    ] doWhile:[info isSymbolicLink].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4335
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4336
    ^ t pathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4337
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4338
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4339
     '/foo/bar' asFilename physicalPathName  
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4340
     '.' asFilename physicalPathName         
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4341
     '../..' asFilename physicalPathName     
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4342
     '/usr/tmp' asFilename physicalPathName           
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4343
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4344
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4345
    "Modified: 21.12.1996 / 15:29:50 / cg"
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4346
!
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  4347
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4348
tail
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4349
    "the files name without directory prefix as a string. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4350
     An alias for baseName, for ST-80 compatiblity."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4351
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4352
    ^ self baseName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4353
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4354
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4355
     Filename currentDirectory tail 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4356
     'Makefile' asFilename tail    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4357
     '/foo/bar/baz.st' asFilename tail  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4358
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4359
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4360
    "Modified: 29.2.1996 / 20:19:50 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4361
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4362
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4363
tail:nComponents
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4364
    "return the last n components of myself.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4365
     - thats the file/directory name without leading parent-dirs.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4366
     (i.e. '/usr/lib/st/file' asFilename tail:2 -> 'st/file'
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4367
       and '/usr/lib'         asFilename tail:1 -> lib).
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4368
     This method does not check if the path is valid.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4369
     The code here should work for Unix and MSDOS, but needs to be redefined
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4370
     for VMS (and maybe others as well).
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4371
     See also: #pathName, #directoryName and #directoryPathName."
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4372
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4373
    |sep components tail start|
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4374
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4375
    sep := self class separator.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4376
    components := self components.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4377
    start := components size - nComponents + 1.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4378
    start < 1 ifTrue:[
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4379
        start := 1.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4380
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4381
    start = 1 ifTrue:[
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4382
        tail := ''
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4383
    ] ifFalse:[
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4384
        tail := components at:start.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4385
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4386
    start+1 to:components size do:[:i|
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4387
        tail := tail, sep, (components at:i).
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4388
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4389
    ^ tail.    
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4390
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4391
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4392
    "
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4393
     '/foo/bar' asFilename tail:1  
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4394
     '/foo/bar' asFilename tail:2  
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4395
     '/foo/bar' asFilename tail:3  
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4396
     '/foo/bar.cc' asFilename tail:2  
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4397
     '.' asFilename tail:3          
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4398
     '..' asFilename tail:3         
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4399
     '../..' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4400
     '../../libbasic' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4401
     '../../libbasic' asFilename asCanonicalizedFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4402
     '../../libpr' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4403
     '../../libbasic/Object.st' asFilename asCanonicalizedFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4404
     '/' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4405
     '\' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4406
     'c:\' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4407
     '\\idefix' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4408
    "
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4409
!
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  4410
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4411
volume
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4412
    "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
  4413
     This is only used with MSDOS and VMS filenames 
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4414
     - by default (and on unix), an empty string is returned"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4415
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  4416
    ^ ''
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4417
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4418
    "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
  4419
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4420
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4421
!Filename methodsFor:'queries-type'!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4422
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4423
isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4424
    "return true, if the receiver represents an existing,
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4425
     readable directories pathname."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4426
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4427
    ^ OperatingSystem isDirectory:(self osNameForAccess)
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4428
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4429
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4430
     '/foo/bar' asFilename isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4431
     '/tmp' asFilename isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4432
     'Makefile' asFilename isDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4433
     'c:\' asFilename isDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4434
     'd:\' asFilename isDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4435
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4436
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4437
    "Modified: / 21.9.1998 / 15:53:10 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4438
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4439
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4440
isNonEmptyDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4441
    "return true, if the receiver represents an existing,
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4442
     readable directories pathname, and the directory is not empty."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4443
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  4444
    FileStream openErrorSignal
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  4445
        handle:[:ex ]
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  4446
        do:[
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  4447
            self directoryContentsDo:[:pathString|^ true].
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4448
        ].
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4449
    ^ false.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4450
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4451
    "
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  4452
     '/foo/bar' asFilename isNonEmptyDirectory 
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4453
     '/tmp' asFilename isNonEmptyDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4454
     '/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4455
     '/tmp/empty' asFilename removeDirectory.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4456
     'Makefile' asFilename isNonEmptyDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4457
     'c:\' asFilename isNonEmptyDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4458
     'd:\' asFilename isNonEmptyDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4459
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4460
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4461
    "Modified: / 21.9.1998 / 15:53:10 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4462
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4463
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4464
isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4465
    "return true, if the receiver represents a socket, named pipe, fifo
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4466
     or device special file (i.e. anything non regular and non-directory)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4467
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4468
    |t|
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4469
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4470
    t := self type.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4471
    ^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]])
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4472
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4473
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4474
     '/foo/bar' asFilename isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4475
     '/tmp' asFilename isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4476
     'Makefile' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4477
     'c:\' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4478
     'd:\' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4479
     '/dev/null' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4480
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4481
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4482
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4483
isSymbolicLink
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4484
    "return true, if the file represented by the receiver is a symbolic
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4485
     link. Notice that not all OS's support symbolic links; those that do
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4486
     not will always return false."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4487
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4488
    ^ OperatingSystem isSymbolicLink:(self osNameForFile)
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4489
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4490
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4491
     'Make.proto' asFilename isSymbolicLink  
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4492
     'Makefile' asFilename isSymbolicLink   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4493
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4494
! !
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4495
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4496
!Filename methodsFor:'reading-directories'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4497
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4498
directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4499
    "return the contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4500
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4501
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4502
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4503
     So users of this method better test for existing directory before.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4504
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4505
        this returns the file-names as strings; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4506
        see also #directoryContentsAsFilenames, which returns fileName instances."
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4507
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4508
    |s contents|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4509
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4510
    s := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4511
    s isNil ifTrue:[^nil].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4512
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4513
    [ 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4514
        contents := s contents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4515
    ] ensure:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4516
        s close
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4517
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4518
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4519
    contents remove:'.' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4520
    contents remove:'..' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4521
    ^ contents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4522
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4523
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4524
     '.' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4525
     '/XXXdoesNotExist' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4526
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4527
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4528
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4529
    "Modified: / 3.8.1998 / 21:36:21 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4530
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4531
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4532
directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4533
    "return the contents of the directory as a collection of filenames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4534
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4535
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4536
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4537
     So users of this method better test for existing directory before.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4538
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4539
        this returns the file-names as fileName instances; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4540
        see also #directoryContents, which returns strings."
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4541
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4542
    |names|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4543
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4544
    names := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4545
    names isNil ifTrue:[^ nil].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4546
    ^ names asOrderedCollection collect:[:entry | self construct:entry].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4547
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4548
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4549
     '.' asFilename directoryContentsAsFilenames   
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4550
     '/XXXdoesNotExist' asFilename directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4551
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4552
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4553
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4554
fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4555
    "return the full contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4556
     This is much like #directoryContents, but includes an entry for the
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4557
     parent directory, if there is one.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4558
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4559
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4560
     So users of this method better test for existing directory before."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4561
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4562
    |files|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4563
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4564
    files := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4565
    files isNil ifTrue:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4566
	"/ mhmh - that one does not exist
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4567
	^ files
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4568
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4569
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4570
    "/ add/remove parentDirectory if there is one/none
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4571
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4572
    files remove:'.' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4573
    self isRootDirectory ifTrue:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4574
	files remove:'..' ifAbsent:nil.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4575
    ] ifFalse:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4576
	(files includes:'..') ifFalse:[
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4577
	    files addFirst:'..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4578
	]
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4579
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4580
    ^ files
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4581
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4582
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4583
     '.' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4584
     '/XXXdoesNotExist' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4585
     'd:\FET' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4586
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4587
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4588
    "Modified: / 21.9.1998 / 15:33:07 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4589
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4590
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4591
recursiveDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4592
    "return the contents of the directory and all subdirectories
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4593
     as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4594
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4595
     Subdirectory files are included with a relative pathname.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4596
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4597
        this returns the file-names as strings; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4598
        see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4599
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4600
     Warning: this may take a long time to execute."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4601
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4602
    |fileNames dirNames|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4603
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4604
    fileNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4605
    dirNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4606
    self directoryContents do:[:f |
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4607
        (self construct:f) isDirectory ifTrue:[
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4608
            dirNames add:f
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4609
        ] ifFalse:[
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4610
            fileNames add:f
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4611
        ]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4612
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4613
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4614
    dirNames do:[:dN |
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4615
        |dd subFiles|
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4616
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4617
        dd := dN asFilename.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4618
        subFiles := (self construct:dN) recursiveDirectoryContents.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4619
        fileNames addAll:(subFiles collect:[:f | dd constructString:f])
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4620
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4621
    ^ fileNames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4622
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4623
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4624
     '.' asFilename recursiveDirectoryContents 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4625
     '../../clients' asFilename recursiveDirectoryContents 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4626
    "
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4627
!
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4628
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4629
recursiveDirectoryContentsAsFilenames
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4630
    "return the contents of the directory and all subdirectories
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4631
     as a collection of filenames.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4632
     This excludes any entries for '.' or '..'.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4633
     Returns nil for non-existing directories; however, this behavior
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4634
     may be changed in the near future, to raise an exception instead.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4635
     So users of this method better test for existing directory before.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4636
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4637
        this returns the file-names as fileName instances; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4638
        see also #recursiveDirectoryContents, which returns strings.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4639
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4640
     Warning: this may take a long time to execute."
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4641
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4642
    |names|
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4643
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4644
    names := self recursiveDirectoryContents.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4645
    names isNil ifTrue:[^ nil].
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4646
    ^ names asOrderedCollection collect:[:entry | self construct:entry].
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4647
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4648
    "
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4649
     '.' asFilename recursiveDirectoryContentsAsFilenames   
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4650
     '/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  4651
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4652
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4653
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4654
!Filename methodsFor:'reading-files'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4655
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4656
binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4657
    "return the binary contents of the file (as a byteArray);
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  4658
     Raises an error, if the file is unreadable/non-existing."
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4659
    
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  4660
    ^ self 
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4661
        readingFileDo:[:s | 
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4662
            |nBytes bytes n|
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4663
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4664
            s binary.
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4665
            nBytes := self fileSize.
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4666
            (nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4667
                bytes := ByteArray uninitializedNew:nBytes.
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4668
                n := s 
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4669
                            nextBytes:nBytes
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4670
                            into:bytes
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4671
                            startingAt:1.
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4672
                n == nBytes ifTrue:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4673
                    bytes
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4674
                ] ifFalse:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4675
                    bytes copyTo:n
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4676
                ]
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4677
            ] ifFalse:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4678
                s contentsOfEntireFile
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4679
            ]
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4680
        ]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4681
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4682
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4683
     'Makefile' asFilename binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4684
     'foobar' asFilename binaryContentsOfEntireFile   
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4685
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4686
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4687
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4688
contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4689
    "return the contents of the file as a collection of lines;
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  4690
     Raises an error, if the file is unreadable/non-existing.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4691
     See also #contentsOfEntireFile, which returns a string for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4692
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4693
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4694
    ^ self readingFileDo:[:s | s contents].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4695
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4696
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4697
     'Makefile' asFilename contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4698
     'foobar' asFilename contents            
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4699
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4700
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4701
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4702
    "Created: / 11.7.1996 / 14:09:11 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4703
    "Modified: / 15.10.1998 / 11:41:45 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4704
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4705
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4706
contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4707
    "return the contents of the file as a string;
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  4708
     Raises an error, if the file is unreadable/non-existing.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4709
     See also #contents, which returns the lines as stringCollection for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4710
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4711
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4712
    ^ self readingFileDo:[:s | s contentsOfEntireFile].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4713
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4714
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4715
     'Makefile' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4716
     'foobar' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4717
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4718
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4719
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4720
    "Modified: / 15.10.1998 / 11:42:05 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4721
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4722
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4723
readingFileDo:aBlock
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4724
    "create a read-stream on the receiver file, evaluate aBlock, passing that stream as arg,
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4725
     and return the blocks value. 
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4726
     If the file cannot be opened, an exception is raised or
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4727
     (old behavior, will vanish:)the block is evaluated with a nil argument.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4728
     Ensures that the stream is closed."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4729
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4730
    |stream result|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4731
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4732
    stream := self readStream.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4733
    [
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4734
        result := aBlock value:stream
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4735
    ] ensure:[
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4736
        stream close
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4737
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4738
    ^ result
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4739
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4740
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4741
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4742
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4743
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4744
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4745
     rslt := 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4746
        '/etc/passwd' asFilename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4747
            readingFileDo:[:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4748
                s nextLine
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4749
            ]. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4750
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4751
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4752
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4753
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4754
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4755
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4756
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4757
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4758
     rslt :=
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4759
        '/etc/passwd' asFilename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4760
            readingFileDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4761
                [:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4762
                    |shells|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4763
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4764
                    shells := Bag new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4765
                    s linesDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4766
                        [:line |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4767
                            |parts|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4768
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4769
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4770
                            shells add:(parts seventh).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4771
                        ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4772
                    shells contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4773
                ].           
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4774
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4775
    "
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4776
!
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4777
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4778
readingLinesDo:aBlock
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4779
    "create a read-stream on the receiver file,
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4780
     evaluate aBlock for each line read from the stream.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4781
     If the file cannot be opened, an error is raised.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4782
     Ensures that the stream is closed."
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4783
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4784
    self readingFileDo:[:stream |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4785
        stream linesDo:aBlock
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4786
    ].
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4787
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4788
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4789
    '/etc/passwd' asFilename 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4790
        readingLinesDo:[:eachLine |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4791
            Transcript showCR:eachLine.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4792
        ]. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4793
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4794
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4795
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4796
    '/etc/xxxxx' asFilename 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4797
        readingLinesDo:[:eachLine |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4798
            Transcript showCR:eachLine.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4799
        ]. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  4800
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4801
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  4802
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4803
!Filename methodsFor:'special accessing'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4804
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4805
nameWithSpecialExpansions:aString
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4806
    "return the nameString, expanding any OS specific
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4807
     macros. This should be redefined for OS's where such macros
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4808
     are common.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4809
     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
  4810
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4811
    ^ aString
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4812
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4813
    "Modified: / 21.7.1998 / 10:43:20 / cg"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4814
    "Created: / 21.7.1998 / 10:45:58 / cg"
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4815
!
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4816
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4817
osName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4818
    "special - return the OS's name for the receiver."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4819
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4820
    self isDirectory ifTrue:[
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4821
	^ self osNameForDirectory
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4822
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4823
    ^ self osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4824
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4825
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4826
osNameForAccess
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4827
    "internal - return the OS's name for the receiver to
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4828
     access its fileInfo.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4829
     This may be redefined for systems, where a special suffix must be
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4830
     added in order to access directories (or others) as a file.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4831
     (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
  4832
7064
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
  4833
    ^ self osNameForFile
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4834
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4835
    "Modified: / 21.7.1998 / 10:40:40 / cg"
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4836
!
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4837
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4838
osNameForDirectory
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4839
    "internal - return the OS's name for the receiver to
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4840
     access it as a directory."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4841
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4842
    ^ nameString
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4843
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4844
    "Modified: / 12.8.1998 / 14:44:32 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4845
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4846
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4847
osNameForDirectoryContents
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4848
    "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
  4849
     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
  4850
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4851
    ^ self osNameForDirectory
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4852
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4853
    "Created: / 3.8.1998 / 21:36:06 / cg"
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  4854
    "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
  4855
!
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  4856
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4857
osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4858
    "internal - return the OS's name for the receiver to
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4859
     access it as a file."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4860
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4861
    ^ nameString
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4862
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4863
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4864
!Filename methodsFor:'suffixes'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4865
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4866
hasSuffix:aSuffixString
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4867
    "return true if my suffix is the same as aString.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4868
     This cares for systems, where case is ignored in filenames"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4869
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4870
    |mySuffix|
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4871
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4872
    mySuffix := self suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4873
    self class isCaseSensitive ifTrue:[
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4874
        ^ mySuffix = aSuffixString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4875
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4876
    ^ mySuffix asLowercase = aSuffixString asLowercase
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4877
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4878
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4879
     'abc.st' asFilename hasSuffix:'st'   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4880
     'abc.ST' asFilename hasSuffix:'st'   
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4881
     '.ST' asFilename hasSuffix:'st'              -- false expected here
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4882
     '.foorc' asFilename hasSuffix:'foorc'        -- false expected here
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4883
     '.foorc.sav' asFilename hasSuffix:'sav'   
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4884
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4885
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4886
    "Modified: 7.9.1997 / 02:55:25 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4887
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4888
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4889
prefixAndSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4890
    "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
  4891
     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
  4892
     the prefix everything before, except for the period.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4893
     The directory name part is stripped off (i.e. the returned prefix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4894
     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
  4895
     (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
  4896
     For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'.
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4897
     An exception to the above: if the name starts with the suffixCharacter,
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4898
     that part is NOT considered a suffix. Thus, '.foorc' has no suffix and a prefix of
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4899
     '.foorc'.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4900
     See also: #withoutSuffix and #withSuffix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4901
     Notice: 
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4902
        there is currently no known system which uses other than
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4903
        the period character as suffixCharacter."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4904
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4905
    |nm idx|
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4906
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4907
    nm := self baseName.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4908
    idx := nm lastIndexOf:(self class suffixSeparator).
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4909
    "/ be careful: if the name consists only of suffix (i.e '.foo'),
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4910
    "/ the suffix is considered empty.
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4911
    ((idx == 1) or:[ idx == 0 ]) ifTrue:[
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4912
        ^ Array with:nm with:''
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4913
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4914
    ^ Array 
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4915
        with:(nm copyTo:idx-1)
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4916
        with:(nm copyFrom:idx+1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4917
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4918
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4919
     'abc.st' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4920
     'abc' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4921
     'a.b.c' asFilename prefixAndSuffix 
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4922
     '/foo/bar.c/baz.c' asFilename prefixAndSuffix 
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4923
     'a.' asFilename prefixAndSuffix    
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4924
     '.a' asFilename prefixAndSuffix    
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4925
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4926
     |parts| 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4927
     parts := 'Object.st' asFilename prefixAndSuffix.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4928
     ((parts at:1) , '.o') asFilename   
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4929
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4930
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4931
    "Modified: 7.9.1995 / 11:15:42 / claus"
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4932
    "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
  4933
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4934
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4935
suffix
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4936
    "return my suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4937
     The suffix is the namepart after the final period character,
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4938
     or the empty string, if the name does not contain a period."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4939
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4940
    ^ self prefixAndSuffix at:2
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4941
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4942
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4943
     'abc.st' asFilename suffix   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4944
     'abc' asFilename suffix      
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4945
     'a.b.c' asFilename suffix    
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4946
     'a.b.c' asFilename suffix    
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4947
     'a.' asFilename suffix    
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4948
     '.a' asFilename suffix    
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4949
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4950
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4951
    "Modified: 7.9.1995 / 11:09:03 / claus"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4952
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4953
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4954
withSuffix:aSuffix
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4955
    "return a new filename for the receivers name with a different suffix.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4956
     If the name already has a suffix, the new suffix replaces it;
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4957
     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
  4958
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4959
    |prefixName|
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4960
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4961
    prefixName := self withoutSuffix name.
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4962
    aSuffix isEmptyOrNil ifTrue:[
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4963
        ^ self class named:prefixName
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4964
    ].
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4965
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4966
    ^ self class named:
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4967
        (prefixName 
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4968
         , self class suffixSeparator asString 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  4969
         , aSuffix asString)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4970
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4971
    "
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  4972
     'abc.st' asFilename withSuffix:nil         
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4973
     'a.b.c' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4974
     '.b.c.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4975
     '.b.c' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4976
     '.c.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4977
     '.c' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4978
     'c.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4979
     '.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4980
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4981
     'abc.st' asFilename withSuffix:'o'         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4982
     'abc' asFilename withSuffix:'o'             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4983
     'a.b.c' asFilename withSuffix:'o'            
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4984
     'a.b.c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4985
     '.b.c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4986
     '.c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4987
     '.c' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4988
     'c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  4989
     '.' asFilename withSuffix:'o'            
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4990
     '/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
  4991
     '/foo/bar/baz.c' asFilename withSuffix:'st'   
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4992
     '/foo/bar.c/baz.c' asFilename withSuffix:'st'   
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4993
     '/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
  4994
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4995
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4996
    "Modified: 7.9.1995 / 11:15:42 / claus"
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  4997
    "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
  4998
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4999
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5000
withoutSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5001
    "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
  5002
     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
  5003
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  5004
    |nm idx idxFromEnd|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5005
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5006
    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
  5007
    idx := nm lastIndexOf:(self class suffixSeparator).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5008
    (idx == 0) ifTrue:[^ self].
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5009
    "/ be careful: if the name consists only of suffix (i.e '.foo'),
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5010
    "/ the suffix is considered empty.
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5011
    (idx == 1) ifTrue:[^self].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5012
3958
e5e1b16f33b6 fixed withoutSuffix in case its ./foo (i.e. .-dir and no suffix)
Claus Gittinger <cg@exept.de>
parents: 3954
diff changeset
  5013
    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
  5014
    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
  5015
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5016
    ^ 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
  5017
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5018
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5019
     'abc.st' asFilename withoutSuffix         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5020
     '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
  5021
     '/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
  5022
     '/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
  5023
     './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
  5024
     './abc.d' asFilename withoutSuffix            
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5025
     './.abc' asFilename withoutSuffix            
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5026
     'a.b.c' asFilename withoutSuffix           
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5027
     'a.b.' asFilename withoutSuffix           
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5028
     '.b.c' asFilename withoutSuffix           
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5029
     '.b.' asFilename withoutSuffix           
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5030
     '.b' asFilename withoutSuffix           
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  5031
     '/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
  5032
     '/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
  5033
     '/foo/bar.x/baz' asFilename withoutSuffix     
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  5034
     '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix   
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  5035
     '/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
  5036
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5037
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5038
    "Modified: 7.9.1995 / 11:15:42 / claus"
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  5039
    "Modified: 3.7.1996 / 10:49:58 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5040
! !
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5041
5597
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5042
!Filename methodsFor:'testing'!
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5043
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5044
isFilename
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5045
    "return true, if the receiver is some kind of filename;
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5046
     false is returned here - the method is redefined from Object."
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5047
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5048
    ^true
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5049
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5050
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5051
! !
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  5052
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  5053
!Filename class methodsFor:'documentation'!
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  5054
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  5055
version
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  5056
    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.288 2005-02-23 11:54:19 stefan Exp $'
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  5057
! !
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5058
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5059
Filename initialize!