Filename.st
author Claus Gittinger <cg@exept.de>
Mon, 08 Jun 2015 21:22:21 +0200
changeset 18465 e9e4bb62235f
parent 18272 d04d39e0f8cb
child 18274 042d13555f1f
child 18490 ec5c1c050681
permissions -rw-r--r--
added isOrdered query
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
     1
"{ Encoding: utf8 }"
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
     2
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     3
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     4
 COPYRIGHT (c) 1992 by Claus Gittinger
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
     5
              All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
"
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
    14
"{ Package: 'stx:libbasic' }"
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
    15
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
    16
"{ NameSpace: Smalltalk }"
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
    17
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    18
Object subclass:#Filename
14567
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
    19
	instanceVariableNames:'nameString'
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
    20
	classVariableNames:'TempDirectory DefaultTempDirectory ConcreteClass'
14567
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
    21
	poolDictionaries:''
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
    22
	category:'System-Support'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
    23
!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    24
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
    25
!Filename class methodsFor:'documentation'!
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    26
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    27
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    28
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    29
 COPYRIGHT (c) 1992 by Claus Gittinger
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    30
              All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    31
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    32
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    33
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    36
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    37
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    38
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
documentation
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    42
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    43
    Filenames; originally added for ST-80 compatibility, is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    44
    taking over functionality from other classes (FileDirectory).
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    45
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    46
    Instances of Filename do not nescessarily represent valid or existing
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    47
    files - i.e. it is possible (and useful) to have instances for non-existing
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    48
    files around. In other words: the name-string is not checked automatically
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    49
    for being correct or existing.
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    50
    Thus, it is possible to do queries such as:
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    51
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    52
        '/fee/foo/foe' asFilename exists     
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    53
        '/not_existing' asFilename isDirectory 
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    54
        '/foo/bar' asFilename isReadable 
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
    55
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
    56
    (all of the above examples will probably return false on your machine ;-).
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    57
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    58
    examples:
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    59
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    60
        'Makefile' asFilename readStream
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    61
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    62
        'newFile' asFilename writeStream
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    63
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    64
        Filename newTemporary writeStream
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    65
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    66
    Beside lots of protocol to query for a files attributes, the class
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    67
    protocol offers methods for filename completion, to construct pathes
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    68
    (in an OS-independent way) and to create temporary files.
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
    69
    Especially the path-construction methods (i.e. #construct:) are highly
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    70
    recommended in order to avoid having OS details (like directory separators
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    71
    being slash or backslash) spreaded in your application.
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    72
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    73
    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
    74
    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
    75
    UnixFilename, PCFilename, ...
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    76
    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
    77
    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
    78
    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
    79
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1225
diff changeset
    80
    [author:]
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    81
        Claus Gittinger
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    82
1286
4270a0b4917d documentation
Claus Gittinger <cg@exept.de>
parents: 1225
diff changeset
    83
    [see also:]
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    84
        String
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    85
        FileStream DirectoryStream PipeStream Socket
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    86
        OperatingSystem
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
    87
        Date Time
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    88
"
360
claus
parents: 359
diff changeset
    89
!
claus
parents: 359
diff changeset
    90
claus
parents: 359
diff changeset
    91
examples
claus
parents: 359
diff changeset
    92
"
claus
parents: 359
diff changeset
    93
    does a file/directory exist ?:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    94
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    95
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    96
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    97
        f := 'foobar' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    98
        ^ f exists  
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
    99
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   100
claus
parents: 359
diff changeset
   101
claus
parents: 359
diff changeset
   102
    is it a directory ?:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   103
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   104
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   105
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   106
        f := '/tmp' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   107
        ^ f isDirectory.   
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   108
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   109
claus
parents: 359
diff changeset
   110
        
claus
parents: 359
diff changeset
   111
    get the working directory:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   112
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   113
        ^ Filename defaultDirectory
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   114
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   115
claus
parents: 359
diff changeset
   116
claus
parents: 359
diff changeset
   117
    get a files full pathname 
claus
parents: 359
diff changeset
   118
    (caring for relative names or symbolic links):
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   119
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   120
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   121
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   122
        f := '..' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   123
        ^ f pathName  
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   124
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   125
claus
parents: 359
diff changeset
   126
claus
parents: 359
diff changeset
   127
    get a directories directory:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   128
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   129
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   130
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   131
        f := Filename defaultDirectory.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   132
        ^ f directory 
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   133
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   134
claus
parents: 359
diff changeset
   135
claus
parents: 359
diff changeset
   136
    get a files directory:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   137
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   138
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   139
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   140
        f := './smalltalk' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   141
        ^ f directory 
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   142
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   143
claus
parents: 359
diff changeset
   144
claus
parents: 359
diff changeset
   145
    getting access & modification times:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   146
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   147
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   148
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   149
        f := '/tmp' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   150
        ^ f dates
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   151
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   152
claus
parents: 359
diff changeset
   153
    access time only:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   154
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   155
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   156
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   157
        f := '/tmp' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   158
        ^ f dates at:#accessed  
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   159
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   160
        
claus
parents: 359
diff changeset
   161
claus
parents: 359
diff changeset
   162
    getting all information on a file/directory:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   163
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   164
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   165
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   166
        f := '/tmp' asFilename.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   167
        ^ f info
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   168
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   169
claus
parents: 359
diff changeset
   170
claus
parents: 359
diff changeset
   171
    getting a temporary file (unique name):
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   172
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   173
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   174
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   175
        f := Filename newTemporary.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   176
        ^ f    
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   177
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   178
claus
parents: 359
diff changeset
   179
    creating, writing, reading and removing a temporary file:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   180
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   181
        |f writeStream readStream|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   182
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   183
        f := Filename newTemporary.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   184
        writeStream := f writeStream.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   185
        writeStream nextPutAll:'hello world'.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   186
        writeStream cr.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   187
        writeStream close.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   188
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   189
        'contents (as seen by unix''s cat command:' printNL.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   190
        OperatingSystem executeCommand:('cat ' , f pathName).
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   191
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   192
        readStream := f readStream.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   193
        Transcript showCR:'contents as seen by smalltalk:'.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   194
        Transcript showCR:(readStream upToEnd).
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   195
        readStream close.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   196
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   197
        f delete.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   198
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   199
        
claus
parents: 359
diff changeset
   200
claus
parents: 359
diff changeset
   201
    getting a directories contents:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   202
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   203
        |f files|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   204
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   205
        f := Filename currentDirectory.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   206
        files := f directoryContents.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   207
        Transcript showCR:'the files are:'.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   208
        Transcript showCR:(files printString).
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   209
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   210
claus
parents: 359
diff changeset
   211
claus
parents: 359
diff changeset
   212
    editing a file:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   213
                                                                        [exBegin]
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   214
        |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   215
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   216
        f := Filename newTemporary.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   217
        (f writeStream) nextPutAll:'hello world'; close.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   218
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   219
        f edit
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   220
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   221
"
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
   222
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   223
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   224
!Filename class methodsFor:'initialization'!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   225
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   226
initialize
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   227
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   228
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   229
    ConcreteClass isNil ifTrue:[
7702
aa9eedcf00d2 only init once.
Claus Gittinger <cg@exept.de>
parents: 7697
diff changeset
   230
        self initializeConcreteClass
aa9eedcf00d2 only init once.
Claus Gittinger <cg@exept.de>
parents: 7697
diff changeset
   231
    ].
2906
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
     self initialize
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
    "Created: 7.9.1997 / 23:32:55 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   238
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   239
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   240
initializeConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   241
    "initialize for the OS we are running on"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   242
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   243
    OperatingSystem isUNIXlike ifTrue:[
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   244
        ConcreteClass := UnixFilename
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   245
    ] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   246
        ConcreteClass := PCFilename
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   247
    ] ifFalse:[OperatingSystem isVMSlike ifTrue:[
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   248
        ConcreteClass := OpenVMSFilename
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   249
    ] ifFalse:[
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   250
        self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'.
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   251
    ]]].
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
    ConcreteClass isNil ifTrue:[
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   254
        self error:'Filename: Missing concrete Filename class'.
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   255
    ].
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   256
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   257
    "
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   258
     self initializeConcreteClass
2906
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
    "Modified: 7.9.1997 / 23:32:37 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   262
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   263
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   264
reinitialize
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   265
    "initialize for the OS we are running on (after a restart)"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   266
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   267
    TempDirectory := nil.
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   268
    self initializeConcreteClass.
2906
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
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   271
     self reinitialize
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   272
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   273
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   274
    "Created: / 07-09-1997 / 23:33:02 / cg"
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   275
    "Modified: / 29-08-2006 / 12:40:28 / cg"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   276
! !
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   277
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   278
!Filename class methodsFor:'instance creation'!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   279
17227
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   280
applicationDataDirectory
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   281
    "return the directory, where user-and-application-specific private files are to be
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   282
     located (ini-files, preferences etc.).
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   283
     Under windows, something like 'C:\Users\Administrator\AppData\Roaming\<appName>'
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   284
     is returned, under unix, we use ~/.<appName> (but see details in UnixOS).
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   285
     For smalltalk itself (the IDE), 'smalltalk' is used as appName.
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   286
     If the directory does not exist, it is created"
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   287
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   288
    |exeName|
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   289
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   290
    Smalltalk isStandAloneApp ifTrue:[
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   291
        exeName := OperatingSystem nameOfSTXExecutable.
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   292
    ] ifFalse:[
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   293
        exeName := 'smalltalk'
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   294
    ].
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   295
    ^ self applicationDataDirectoryFor:exeName
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   296
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   297
    "                    
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   298
     Filename applicationDataDirectory   
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   299
    "
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   300
!
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   301
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   302
applicationDataDirectoryFor:appName
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   303
    "return the directory, where user-and-application-specific private files are to be
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   304
     located (ini-files, preferences etc.).
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   305
     Under windows, something like 'C:\Users\Administrator\AppData\Roaming\<appName>'
12973
dd18a7271b60 comment/format in: #applicationDataDirectoryFor:
sr
parents: 12972
diff changeset
   306
     is returned, under unix, we use ~/.<appName> (but see details in UnixOS).
12974
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   307
     If the directory does not exist, it is created"
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   308
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   309
    |s dir|
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   310
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   311
    s := OperatingSystem getApplicationDataDirectoryFor:appName.
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   312
    s isNil ifTrue:[
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   313
        ^ self homeDirectory
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   314
    ].
12974
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   315
    dir := self named:s.
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   316
    dir exists ifFalse:[
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   317
        dir makeDirectory
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   318
    ].
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   319
    ^ dir
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   320
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   321
    "                    
17227
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   322
     Filename applicationDataDirectoryFor:'smalltalk'        
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   323
     Filename applicationDataDirectoryFor:'expecco'        
17227
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   324
      applicationDataDirectoryFor:'expecco'        
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   325
    "
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   326
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   327
    "Created: / 29-07-2010 / 12:05:35 / sr"
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   328
!
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   329
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   330
currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   331
    "return a filename for the current directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   332
13109
89476863464e getCurrentDirectory
Stefan Vogel <sv@exept.de>
parents: 13057
diff changeset
   333
    ^ self named:(OperatingSystem getCurrentDirectory).
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   334
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   335
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   336
     Filename currentDirectory 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   337
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   338
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   339
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   340
defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   341
    "ST80 compatibility: same as currentDirectory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   342
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   343
    ^ self currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   344
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   345
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   346
     Filename defaultDirectory 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   347
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   348
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   349
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   350
defaultTempDirectory
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   351
    "return the default temp directory as a filename.
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   352
     That is the same as TempDirectory, except that TempDirectory can be changed
17048
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   353
     from the outside (via tempDirectory:) whereas this is the OS's original default.
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   354
     Use this for files which MUST remain the same (stx_sourceCache)"
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   355
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   356
    DefaultTempDirectory isNil ifTrue:[
17048
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   357
        self tempDirectory.  "/ actually sets DefaultTempDirectory as side effect
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   358
        DefaultTempDirectory isNil ifTrue:[
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   359
            DefaultTempDirectory := TempDirectory
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   360
        ].
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   361
    ].
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   362
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   363
    DefaultTempDirectory exists ifFalse:[
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   364
        DefaultTempDirectory
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   365
            makeDirectory; 
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   366
            addAccessRights:#(readUser readGroup readOthers 
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   367
                              writeUser writeGroup writeOthers
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   368
                              executeUser executeGroup executeOthers
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   369
                              removeOnlyByOwner).
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   370
    ].
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   371
    ^ DefaultTempDirectory
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   372
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   373
    "
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   374
     Filename tempDirectory           
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   375
     Filename defaultTempDirectory           
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   376
    "
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   377
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   378
    "Created: / 07-03-1996 / 14:51:18 / cg"
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   379
    "Modified: / 29-08-2006 / 12:57:16 / cg"
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   380
!
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   381
10546
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   382
desktopDirectory
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   383
    "return your desktop directory.
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   384
     Under windows, thats the real desktop directory; 
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   385
     under other OperatingSystems, the home directory is returned."
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   386
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   387
    |s|
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   388
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   389
    s := OperatingSystem getDesktopDirectory.
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   390
    s isNil ifTrue:[
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   391
        ^ self homeDirectory
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   392
    ].
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   393
    ^ self named:s
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   394
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   395
    "
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   396
     Filename desktopDirectory        
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   397
    "
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   398
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   399
    "Created: / 16-05-2007 / 13:18:34 / cg"
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   400
!
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   401
11763
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   402
documentsDirectory
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   403
    "return your documents directory.
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   404
     Under windows, thats the real 'Documents' or 'My Documents'; 
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   405
     under other OperatingSystems, the home directory is returned."
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   406
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   407
    |s|
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   408
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   409
    s := OperatingSystem getDocumentsDirectory.
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   410
    s isNil ifTrue:[
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   411
        ^ self homeDirectory
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   412
    ].
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   413
    ^ self named:s
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   414
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   415
    "
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   416
     Filename documentsDirectory        
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   417
    "
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   418
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   419
    "Created: / 16-05-2007 / 13:18:34 / cg"
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   420
!
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   421
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   422
findDefaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   423
    "same as #defaultDirectory for ST80 compatibility"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   424
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   425
    ^ self defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   426
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   427
    "Created: 20.6.1997 / 17:00:29 / 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
fromComponents:aCollectionOfDirectoryNames
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   431
    "create & return a new filename from components given in
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   432
     aCollectionOfDirectoryNames. If the first component is the name of the
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   433
     root directory (i.e. '/') an absolute path-filename is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   434
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   435
    self isAbstract ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   436
        ^ ConcreteClass fromComponents:aCollectionOfDirectoryNames
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   437
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   438
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   439
    ^ self named:(self nameFromComponents:aCollectionOfDirectoryNames)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   440
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   441
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   442
     Filename fromComponents:#('/' 'foo' 'bar' 'baz')  
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   443
     PCFilename fromComponents:#('/' 'foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   444
     UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   445
     OpenVMSFilename fromComponents:#('foo' 'bar' 'baz')
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   446
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   447
     Filename fromComponents:#('foo' 'bar' 'baz')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   448
     Filename fromComponents:#('/')  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   449
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   450
     Filename fromComponents:
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   451
         (Filename components:('.' asFilename pathName))
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   452
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   453
     Filename fromComponents:
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   454
         (Filename components:('.' asFilename name)) 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   455
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   456
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   457
    "Modified: 8.9.1997 / 00:23:16 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   458
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   459
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   460
fromUser
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   461
    "show a box to enter a filename. 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   462
     Return a filename instance or nil (if cancel was pressed)."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   463
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   464
    |name|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   465
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   466
    name := Dialog 
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   467
        requestFileName:'filename:' 
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   468
        default:nil
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   469
        fromDirectory:(FileSelectionBox lastFileSelectionDirectory).
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   470
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   471
    name notEmptyOrNil ifTrue:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   472
        ^ self named:name
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   473
    ].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   474
    ^ nil
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   475
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   476
    "
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   477
     Filename fromUser 
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   478
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   479
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   480
    "Modified: 19.4.1996 / 13:57:44 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   481
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   482
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   483
homeDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   484
    "return your homeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   485
     Some OperatingSystems do not support this - on those, the defaultDirectory
17113
a521179b677c class: Filename
Claus Gittinger <cg@exept.de>
parents: 17112
diff changeset
   486
     (which is the currentDirectory) is returned.
a521179b677c class: Filename
Claus Gittinger <cg@exept.de>
parents: 17112
diff changeset
   487
     Notice: services under windows also do not have a home directory."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   488
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   489
    |s|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   490
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   491
    s := OperatingSystem getHomeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   492
    s isNil ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
   493
        ^ self defaultDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   494
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   495
    ^ self named:s
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   496
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   497
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   498
     Filename homeDirectory        
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   499
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   500
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   501
    "Modified: 8.9.1997 / 00:25:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   502
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   503
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   504
named:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   505
    "return a filename for a directory named aString.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   506
     This is the same as 'aString asFilename'."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   507
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   508
    self isAbstract ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   509
        ^ ConcreteClass named:aString
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   510
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   511
    ^ self basicNew setName:aString
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   512
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   513
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   514
     Filename named:'/tmp/fooBar'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   515
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   516
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   517
    "Modified: 7.9.1997 / 23:30:06 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   518
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   519
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   520
newTemporary
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   521
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   522
     The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   523
     unix process id, and nn is a unique number, incremented with every
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   524
     call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   525
     If any of the environment variables ST_TMPDIR or TMPDIR is set, 
4757
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   526
     its value defines the temp directory.
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   527
     Notice, that no file is created by this - only a unique name
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   528
     is generated.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   529
16787
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   530
     DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporary
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   531
     (the insecurity is due to a small chance for some other program to open/create
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   532
      the file, as only a name is generated here. However, chances are small as the name
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   533
      is reasonably random - but for security relevant applications, this may be relevant)
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   534
    "
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   535
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   536
    ^ self newTemporaryIn:(self tempDirectory)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   537
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   538
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   539
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   540
     Filename newTemporary     
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   541
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   542
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   543
    "Modified: 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   544
    "Modified: 7.3.1996 / 14:51:33 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   545
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   546
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   547
newTemporaryDirectory
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   548
    "return a new unique temporary directory - use this for temporary files.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   549
     The directories returned are '/tmp/stxtmp_xx_nn' where xx is our
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   550
     unix process id, and nn is a unique number, incremented with every
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   551
     call to this method.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   552
     If any of the environment variables ST_TMPDIR or TMPDIR is set, 
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   553
     its value defines the temp directory."
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   554
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   555
    ^ self newTemporaryDirectoryIn:(self tempDirectory)
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   556
!
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   557
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   558
newTemporaryDirectoryIn:aDirectoryOrNil
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   559
    "return a new unique temporary directory in another directory, or the current dir.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   560
     Use this for temporary files.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   561
     The directories returned are '/tmp/stxtmp_xx_nn' where xx is our
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   562
     unix process id, and nn is a unique number, incremented with every
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   563
     call to this method.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   564
     If any of the environment variables ST_TMPDIR or TMPDIR is set, 
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   565
     its value defines the temp directory."
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   566
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   567
    |tempdir|
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   568
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
   569
    tempdir := self newTemporaryIn:aDirectoryOrNil.
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   570
    tempdir exists ifTrue:[
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   571
        tempdir recursiveRemove.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   572
    ].
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   573
    tempdir makeDirectory.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   574
    ^ tempdir
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   575
!
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   576
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   577
newTemporaryIn:aDirectoryOrNil
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   578
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   579
     The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn',
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   580
     where xx is our unix process id, and nn is a unique number, incremented 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   581
     with every call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   582
     Notice: only a unique filename object is created and returned - no physical
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   583
     file is created by this method (i.e. you have to send #writeStream or
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   584
     whatever to it in order to really create something).
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   585
     See also: #newTemporary which looks for a good temp directory.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   586
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   587
     DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:"
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   588
12617
7c826d99119a comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12529
diff changeset
   589
    ^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(self tempFileNameTemplate)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   590
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   591
    "temp files in '/tmp':
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   592
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   593
     Filename newTemporary    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   594
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   595
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   596
    "temp files somewhere 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   597
     (not recommended - use above since it can be controlled via shell variables):
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   598
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   599
     UnixFilename newTemporaryIn:'/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   600
     UnixFilename newTemporaryIn:'/tmp'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   601
     UnixFilename newTemporaryIn:'/usr/tmp'    
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   602
     UnixFilename newTemporaryIn:'/'  
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   603
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   604
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   605
    "a local temp file:
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   606
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   607
     Filename newTemporaryIn:''         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   608
     Filename newTemporaryIn:nil         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   609
     Filename newTemporaryIn:'.'         
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   610
     Filename newTemporaryIn:('source' asFilename) 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   611
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   612
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   613
    "Modified: / 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   614
    "Modified: / 11.8.1998 / 22:51:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   615
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   616
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   617
newTemporaryIn:aDirectoryOrNil nameTemplate:template
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   618
    "return a new unique filename - use this for temporary files.
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   619
     The filenames returned are in aDirectoryOrNil and named after the given template,
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   620
     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
   621
     with every call to this method respectively.
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   622
     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
   623
     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
   624
     whatever to it in order to really create something).
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   625
     See also: #newTemporary which looks for a good temp directory.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   626
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   627
     DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:nameTemplate:"
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   628
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   629
    |nameString newTempFilename|
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   630
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   631
    self isAbstract ifTrue:[
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   632
        ^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   633
    ].
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   634
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   635
    "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
   636
     the following should work on all systems ..."
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   637
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   638
    [
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   639
        "Use random numbers in order to improve the security 
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   640
         by making the generated names less predictable"
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   641
        nameString := template bindWith:(OperatingSystem getProcessId) with:RandomGenerator new nextInteger.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   642
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   643
        aDirectoryOrNil isNil ifTrue:[
12918
a9de9243a951 changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents: 12910
diff changeset
   644
            newTempFilename := self named:nameString
a9de9243a951 changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents: 12910
diff changeset
   645
        ] ifFalse:[
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   646
            newTempFilename := aDirectoryOrNil asFilename construct:nameString
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   647
        ]
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   648
    ] doWhile:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   649
        "care for existing leftOver tempFiles
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   650
         from a previous boot of the OS
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   651
         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
   652
         the last time before system reboot ...)"
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   653
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   654
        newTempFilename exists
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   655
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   656
    ^ newTempFilename
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   657
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   658
    "temp files in '/tmp':
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   659
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   660
     Filename newTemporary    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   661
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   662
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   663
    "temp files somewhere 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   664
     (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
   665
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   666
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   667
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'  
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   668
     UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2'    
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   669
     UnixFilename newTemporaryIn:'/'        nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   670
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   671
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   672
    "a local temp file:
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   673
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   674
     Filename newTemporaryIn:''             nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   675
     Filename newTemporaryIn:nil            nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   676
     Filename newTemporaryIn:'.'            nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   677
     Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' 
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   678
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   679
12918
a9de9243a951 changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents: 12910
diff changeset
   680
    "Modified: / 07-09-1995 / 10:48:31 / claus"
a9de9243a951 changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents: 12910
diff changeset
   681
    "Modified: / 07-05-2010 / 11:46:05 / cg"
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   682
!
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   683
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   684
nullDevice
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   685
    "return the filename of the nullDevice (if available).
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   686
     returns nil, if the OperatingSystem does not support this."
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   687
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   688
    |s|
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   689
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   690
    s := self nullFilename.
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   691
    s isNil ifTrue:[
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   692
        ^ nil
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   693
    ].
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   694
    ^ self named:s
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   695
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   696
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   697
     Filename nullDevice
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   698
     UnixFilename nullDevice
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   699
     PCFilename nullDevice
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   700
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   701
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   702
    "Created: / 19.5.1999 / 12:24:26 / cg"
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   703
!
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   704
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   705
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   706
    "create & return a new filename from components given in
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   707
     aCollectionOfDirectoryNames on a host named remoteHostString. 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   708
     An absolute network-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   709
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   710
    self isAbstract ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   711
        ^ ConcreteClass remoteHost:remoteHostString 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   712
                        rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   713
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   714
10390
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   715
    remoteHostString notEmptyOrNil ifTrue:[
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   716
        self error:'remote hosts are not supported by OS'
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   717
    ].
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   718
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   719
    ^ self rootComponents:aCollectionOfDirectoryNames
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   720
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   721
    "
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   722
      'file:///tmp/test' asURI asFilename 
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   723
    "
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   724
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   725
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   726
rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   727
    "create & return a new filename from components given in
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   728
     aCollectionOfDirectoryNames. 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   729
     An absolute path-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   730
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   731
    |sep s|
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   732
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   733
    self isAbstract ifTrue:[
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   734
        ^ ConcreteClass rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   735
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   736
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   737
    "/ fallBack - works on Unix & MSDOS
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   738
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   739
    sep := self separatorString.
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
   740
    s := CharacterWriteStream new.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   741
    aCollectionOfDirectoryNames do:[:component |
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   742
        component ~= sep ifTrue:[
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   743
            s nextPutAll:sep; nextPutAll:component
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   744
        ]
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   745
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   746
    s := s contents.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   747
    s size == 0 ifTrue:[s := sep].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   748
    ^ self named:s
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   749
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   750
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   751
     Filename rootComponents:#('/' 'foo' 'bar' 'baz')
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   752
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   753
     Filename rootComponents:#('foo' 'bar' 'baz')  
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   754
     PCFilename rootComponents:#('foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   755
     UnixFilename rootComponents:#('foo' 'bar' 'baz')  
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   756
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   757
     Filename rootComponents:#('/')  
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   758
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   759
     Filename rootComponents:
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   760
         (Filename components:('.' asFilename pathName))
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   761
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   762
     Filename rootComponents:
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   763
         (Filename components:('.' asFilename name)) 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   764
    "
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   765
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   766
    "Modified: 8.9.1997 / 00:23:16 / cg"
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   767
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   768
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   769
rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   770
    "return a filename for the root directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   771
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   772
    self isAbstract ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   773
        ^ ConcreteClass rootDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   774
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   775
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   776
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   777
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   778
    ^ self named:(self separatorString)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   779
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   780
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   781
     Filename rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   782
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   783
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   784
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   785
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   786
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   787
rootDirectoryOnVolume:aVolumeName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   788
    "return a filename for the root directory on some volume"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   789
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   790
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
   791
        ^ ConcreteClass rootDirectoryOnVolume:aVolumeName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   792
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   793
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   794
    "/ fallBack - works on Unix (not on MSDOS or VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   795
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   796
    ^ self rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   797
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   798
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   799
     Filename rootDirectoryOnVolume:'/phys/idefix'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   800
     Filename rootDirectoryOnVolume:'d:'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   801
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   802
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   803
    "Modified: / 5.10.1998 / 12:45:39 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   804
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   805
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   806
tempDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   807
    "return the temp directory as a filename.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   808
     If any of the environment variables STX_TMPDIR, ST_TMPDIR,
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   809
     TMPDIR or TEMPDIR is set, its value defines the name, 
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   810
     otherwise, '/tmp' is used. (at least on unix ...).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   811
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   812
     Notice: do not hardcode '/tmp' into your programs - things may be
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   813
             different on other operating systems. Also, the user may want to set the
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   814
             TMPDIR environment variable to have her temp files somewhere else."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   815
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   816
    |tempDir|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   817
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   818
    TempDirectory isNil ifTrue:[
17048
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   819
        tempDir := self named:(self defaultTempDirectoryName pathName).
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   820
        tempDir exists ifFalse:[
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   821
            tempDir
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   822
                makeDirectory; 
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   823
                addAccessRights:#(readUser readGroup readOthers 
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   824
                                  writeUser writeGroup writeOthers
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   825
                                  executeUser executeGroup executeOthers
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   826
                                  removeOnlyByOwner).
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   827
        ].
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   828
        TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'.
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   829
    ].
10551
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   830
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   831
    "Make sure, that the TempDirectory exists - it might have been removed
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   832
     by a cleanup (cron) job.
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   833
     Since it is shared between users, it must be accessable by all users."
10551
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   834
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   835
    TempDirectory exists ifFalse:[
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   836
        TempDirectory 
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   837
            makeDirectory; 
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   838
            addAccessRights:#(readUser readGroup readOthers 
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   839
                              writeUser writeGroup writeOthers
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   840
                              executeUser executeGroup executeOthers
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
   841
                              removeOnlyByOwner).
10551
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   842
    ].
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   843
    ^ TempDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   844
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   845
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   846
     Filename tempDirectory           
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   847
     Filename tempDirectory pathName   
8660
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   848
     Filename tempDirectory exists    
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   849
     Filename tempDirectory isWritable   
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   850
     (Filename tempDirectory construct:'foo') makeDirectory   
8660
a14239ed6ac3 check for tempDir to be present (WIN32 kludge)
penk
parents: 8535
diff changeset
   851
     (Filename tempDirectory construct:'foo') remove   
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   852
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   853
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   854
    "Created: / 07-03-1996 / 14:51:18 / cg"
13781
c691e88e1900 changed: #tempDirectory
Claus Gittinger <cg@exept.de>
parents: 13779
diff changeset
   855
    "Modified: / 07-10-2011 / 18:39:25 / cg"
11757
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   856
!
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   857
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   858
tempDirectory:aFilename
17048
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   859
    "set the default temporary directory.
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   860
     This allows overwriting the automatically determined tmpDirectory
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   861
     by a knowledgable stand alone startup program.
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   862
     Do not use elsewhere (and only if absolutely requried)"
11757
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   863
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   864
    |temp|
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   865
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   866
    aFilename isNil ifTrue:[
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   867
        TempDirectory := nil.
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   868
        ^ self.
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   869
    ].
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   870
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   871
    temp := aFilename asFilename.
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   872
    self assert:temp isDirectory.
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   873
    TempDirectory := temp.
16382
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   874
!
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   875
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   876
trashDirectoryOrNil
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   877
    "if the underlying OS uses/supports a trash folder,
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   878
     return it. Otherwise return nil.
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   879
     Asks the OS for the pathname; for example, on OSX, '~/.Trash' is returned."
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   880
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   881
    |s|
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   882
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   883
    s := OperatingSystem getTrashDirectory.
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   884
    s isNil ifTrue:[
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   885
        ^ nil
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   886
    ].
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   887
    ^ self named:s
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   888
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   889
    "
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   890
     Filename desktopDirectory        
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   891
    "
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   892
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   893
    "Created: / 16-05-2007 / 13:18:34 / cg"
16648
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   894
!
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   895
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   896
usersPrivateSmalltalkDirectory
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   897
    ^ Filename homeDirectory / '.smalltalk'
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   898
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   899
    "
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   900
     Filename usersPrivateSmalltalkDirectory
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   901
    "
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   902
! !
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   903
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   904
!Filename class methodsFor:'defaults'!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   905
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   906
concreteClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   907
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   908
     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
   909
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   910
    ^ ConcreteClass ? self
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   911
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   912
    "Created: 14.2.1997 / 16:36:13 / cg"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   913
    "Modified: 7.9.1997 / 23:29:20 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   914
!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   915
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   916
defaultClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   917
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   918
     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
   919
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   920
    ^ ConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   921
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   922
    "Modified: 8.9.1997 / 00:36:01 / cg"
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   923
!
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   924
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   925
defaultTempDirectoryName
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   926
    "return the default temp directory as a filename.
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   927
     This is used, if no special preferences were defined in
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   928
     any of the TEMP-environment variables (see tempDirectory)."
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   929
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   930
    self isAbstract ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   931
        ^ ConcreteClass defaultTempDirectoryName
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   932
    ].
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   933
10994
1a3776d0b845 always return a fileName from defaultTempDirectoryName
fm
parents: 10969
diff changeset
   934
    ^ '/tmp' asFilename
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   935
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   936
    "
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   937
     Filename defaultTempDirectoryName           
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   938
    "
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   939
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   940
    "Modified: 7.9.1995 / 10:48:31 / claus"
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   941
    "Created: 7.3.1996 / 14:51:18 / cg"
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   942
    "Modified: 8.9.1997 / 00:24:53 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   943
! !
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   944
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   945
!Filename class methodsFor:'misc'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
   946
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   947
filterSeps:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   948
    "ST80 compatibility:
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   949
     filter out (invalid) separators in aFilenameString.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   950
     We recommend using #makeLegalFilename"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   951
16762
32497763707a class: Filename
Claus Gittinger <cg@exept.de>
parents: 16761
diff changeset
   952
    ^ aFilenameString copyReplaceAll:(Character space) with:$_ ifNone:aFilenameString.
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   953
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   954
    "Created: / 1.11.1997 / 12:39:50 / cg"
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
   955
    "Modified: / 18.7.1998 / 22:53:24 / cg"
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   956
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
   957
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   958
nameWithSpecialExpansions:aString
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   959
    "return the nameString, expanding any OS specific macros. 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   960
     Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)"
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   961
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   962
    |dir user cutIdx idx userInfo|
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   963
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   964
    (aString startsWith:'~') ifFalse:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   965
        ^ aString.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   966
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   967
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   968
    aString size > 1 ifTrue:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   969
        idx := aString indexOf:self separator.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   970
        idx == 0 ifTrue:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   971
            "aString is '~user'"
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   972
            user := aString copyFrom:2.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   973
            cutIdx := aString size + 1.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   974
        ] ifFalse:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   975
            "aString is '~user/something'"
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   976
            user := aString copyFrom:2 to:(idx - 1).
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   977
            cutIdx := idx.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   978
        ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   979
        user notEmpty ifTrue:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   980
            userInfo := OperatingSystem userInfoOf:user.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   981
            userInfo notNil ifTrue:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   982
                dir := userInfo at:#dir ifAbsent:nil.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   983
            ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   984
            dir isNil ifTrue:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   985
"/                 ('Filename [info]: unknown user: ' , user) infoPrintCR.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   986
                ^ aString
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   987
            ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   988
        ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   989
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   990
    dir isNil ifTrue:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   991
        "aString is '~' or '~/'"
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   992
        dir := OperatingSystem getHomeDirectory.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   993
        cutIdx := 2.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   994
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   995
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   996
    ^ dir , (aString copyFrom:cutIdx)
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   997
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   998
    "
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
   999
     Filename new nameWithSpecialExpansions:'~'      
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1000
     Filename new nameWithSpecialExpansions:'~\work'  
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1001
     Filename new nameWithSpecialExpansions:'~stefan'     
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1002
     Filename new nameWithSpecialExpansions:'~stefan\work' 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1003
     Filename new nameWithSpecialExpansions:'~foo'    
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1004
     Filename new nameWithSpecialExpansions:'~foo\bar' 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1005
    "
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1006
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1007
    "
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1008
     UnixFilename new nameWithSpecialExpansions:'~'      
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1009
     UnixFilename new nameWithSpecialExpansions:'~/work'  
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1010
     UnixFilename new nameWithSpecialExpansions:'~stefan'     
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1011
     UnixFilename new nameWithSpecialExpansions:'~stefan/work' 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1012
     UnixFilename new nameWithSpecialExpansions:'~foo'    
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1013
     UnixFilename new nameWithSpecialExpansions:'~foo/bar' 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1014
    "
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1015
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1016
    "
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1017
     PCFilename new nameWithSpecialExpansions:'~'      
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1018
     PCFilename new nameWithSpecialExpansions:'~\work'   
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1019
     PCFilename new nameWithSpecialExpansions:'~stefan'     
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1020
     PCFilename new nameWithSpecialExpansions:'~stefan\work' 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1021
     PCFilename new nameWithSpecialExpansions:'~foo'    
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1022
     PCFilename new nameWithSpecialExpansions:'~foo\bar' 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1023
    "
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1024
!
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1025
16999
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1026
possiblyQuotedPathname:aPath
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1027
    "return a filename path usable as command line argument,
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1028
     by quoting in double quotes if there are any embedded special characters.
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1029
     On Unix systems, special characters might also be prefixed by a backslash character."
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1030
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1031
    (aPath startsWith:'"') ifFalse:[
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1032
        (aPath includes:Character space) ifTrue:[
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1033
            ^ '"',aPath,'"'
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1034
        ].
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1035
    ].
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1036
    ^ aPath
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1037
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1038
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1039
    "
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1040
     Filename possiblyQuotedPathname:'/tmp/bla'   
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1041
     Filename possiblyQuotedPathname:'/tmp directory/bla'   
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1042
     Filename possiblyQuotedPathname:'/tmp directory/bla file'   
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1043
    "
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1044
!
4d5ceea1cea6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16787
diff changeset
  1045
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1046
suggest:aFilenameString 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1047
    "return a fileNamestring based on the argument, 
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1048
     which is legal on the current platform."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1049
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1050
    ^ self canonicalize:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1051
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1052
    "Created: / 1.11.1997 / 12:42:39 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1053
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1054
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  1055
!Filename class methodsFor:'queries'!
2
claus
parents: 1
diff changeset
  1056
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1057
currentDirectoryName
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1058
    "return a filename for the current directory"
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1059
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1060
    self isAbstract ifTrue:[
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1061
        ^ ConcreteClass currentDirectoryName
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1062
    ].
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1063
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1064
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1065
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1066
    ^ '.'
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1067
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1068
    "
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1069
     Filename currentDirectoryName    
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1070
    "
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1071
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1072
    "Modified: / 8.9.1997 / 00:24:15 / cg"
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1073
    "Created: / 21.10.1998 / 17:49:57 / cg"
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1074
!
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1075
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1076
defaultDirectoryName
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1077
    "ST80 compatibility: return the defaultDirectories name (as a string)"
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1078
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1079
    ^ self defaultDirectory name
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1080
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1081
    "
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1082
     Filename defaultDirectoryName 
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1083
    "
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1084
!
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1085
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1086
directorySuffix
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1087
    "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
  1088
     The default is nil here, redefined for VMS"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1089
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1090
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1091
        ^ ConcreteClass directorySuffix
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1092
    ].
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1093
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1094
    ^ nil
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1095
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1096
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1097
errorReporter
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1098
    "who knows the signals to report errors?"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1099
        
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1100
    ^ FileStream
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1101
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1102
    "Created: 2.7.1996 / 12:30:25 / stefan"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1103
!
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1104
440
claus
parents: 422
diff changeset
  1105
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock
claus
parents: 422
diff changeset
  1106
    "perform filename completion on aString in some directory;
claus
parents: 422
diff changeset
  1107
     return the longest matching filename prefix as a string.
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1108
     The boolean directoriesOnly and filesOnly control respectively,
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1109
     if only directories or only regular files are to be considered for completion.
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1110
     If multiple files match, the exception block aBlock is evaluated with a 
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1111
     filename representing the directory (where the match was done) as argument.
440
claus
parents: 422
diff changeset
  1112
     (this may be different from the inDirectory argument, if aString is absolute
claus
parents: 422
diff changeset
  1113
      or starts with ../)"
claus
parents: 422
diff changeset
  1114
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1115
    self isAbstract ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1116
        ^ ConcreteClass 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1117
            filenameCompletionFor:aString 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1118
            directory:inDirectory       
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1119
            directoriesOnly:directoriesOnly 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1120
            filesOnly:filesOnly 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1121
            ifMultiple:aBlock
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1122
    ].
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1123
    ^ 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
  1124
!
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1125
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1126
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
  1127
    "perform filename completion on aString in some directory;
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1128
     return the longest matching filename prefix as a string.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1129
     The boolean directoriesOnly and filesOnly control respectively,
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1130
     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
  1131
     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
  1132
     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
  1133
     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
  1134
     (list of matched filenames)  as arguments.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1135
     (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
  1136
      or starts with ../)"
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1137
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1138
    |s f matchSet nMatch name dir isAbsolute sep|
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1139
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1140
    aString size == 0 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1141
        aBlock value:(self named:'.').
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1142
        ^ ''
440
claus
parents: 422
diff changeset
  1143
    ].
claus
parents: 422
diff changeset
  1144
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1145
    sep := self separator.
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1146
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1147
    "/ 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
  1148
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1149
    f := self named:aString.
3854
a13d0d489365 care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
  1150
    isAbsolute := f isAbsolute.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1151
    matchSet := f filenameCompletionIn:inDirectory.  "/ BAD DESIGN: has side effect on f
440
claus
parents: 422
diff changeset
  1152
    dir := f directory.
claus
parents: 422
diff changeset
  1153
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1154
    matchSet := matchSet select:[:aFilename |
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1155
        |f isDir|
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1156
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1157
        isAbsolute ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1158
            f := aFilename asFilename
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1159
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1160
            f := (dir construct:aFilename). 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1161
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1162
        isDir := f isDirectory.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1163
        directoriesOnly ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1164
            isDir
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1165
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1166
            filesOnly ifTrue:[    
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1167
                isDir not
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1168
            ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1169
                true
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1170
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1171
        ]
440
claus
parents: 422
diff changeset
  1172
    ].
claus
parents: 422
diff changeset
  1173
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
  1174
    f := f asCanonicalizedFilename.
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1175
        (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
  1176
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1177
         more than one possible completion -
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1178
        "
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1179
        aMultipleBlock notNil ifTrue:[
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1180
            aMultipleBlock value:f value:matchSet.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1181
        ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1182
        aBlock value:f
440
claus
parents: 422
diff changeset
  1183
    ].
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1184
440
claus
parents: 422
diff changeset
  1185
    "
claus
parents: 422
diff changeset
  1186
     even with more than one possible completion,
claus
parents: 422
diff changeset
  1187
     f's name is now the common prefix
claus
parents: 422
diff changeset
  1188
    "
claus
parents: 422
diff changeset
  1189
    name := f asString.
4323
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
  1190
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
  1191
    nMatch <= 1 ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1192
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1193
         exactly one possible completion -
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1194
        "
3752
cbf9fa32eb28 fixed completion.
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
  1195
"/        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
  1196
        false "directoriesOnly" ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1197
            (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
  1198
                (name endsWith:sep) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1199
                    name := name , sep asString
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1200
                ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1201
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1202
        ]
440
claus
parents: 422
diff changeset
  1203
    ].
claus
parents: 422
diff changeset
  1204
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1205
    s := name.
440
claus
parents: 422
diff changeset
  1206
claus
parents: 422
diff changeset
  1207
    "/ special: if there was no change, and the string represented
claus
parents: 422
diff changeset
  1208
    "/ 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
  1209
    ((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
  1210
        (s endsWith:sep) ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1211
            (self named:s) isDirectory ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1212
                ^ s , sep asString
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1213
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1214
        ].
440
claus
parents: 422
diff changeset
  1215
    ].
claus
parents: 422
diff changeset
  1216
claus
parents: 422
diff changeset
  1217
    ^ s
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1218
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1219
    "Modified: / 30.4.1999 / 09:40:13 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1220
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1221
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1222
filesMatching:aPattern
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1223
    "return a collection of strings, representing the names
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1224
     of files matching aPattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1225
     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
  1226
     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
  1227
     The returned strings are the expanded names, in the same form
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1228
     as given in pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1229
     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
  1230
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1231
    |basePattern dir d files|
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1232
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1233
    self isAbstract ifTrue:[
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  1234
        ^ ConcreteClass filesMatching:aPattern
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1235
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1236
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1237
    "/ the following works on Unix & MSDOS (but not on openVMS)
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1238
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1239
    dir := aPattern asFilename directoryName.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1240
    basePattern := aPattern asFilename baseName.
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1241
    d := dir asFilename.
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  1242
    files := dir asFilename filesMatchingWithoutDotDirs:basePattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1243
    dir = '.' ifTrue:[^ files].
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1244
    ^ files collect:[:base | d constructString:base].
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1245
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1246
    "
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1247
     Filename filesMatching:'*'   
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1248
     Filename filesMatching:'/*'
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1249
     Filename filesMatching:'/usr/local/*'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1250
    "
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1251
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1252
    "Modified: 8.9.1997 / 00:32:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1253
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1254
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1255
isAbstract
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1256
    "return true, if this is not a concrete class"
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1257
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1258
    ^ self == Filename 
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1259
!
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1260
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1261
isBadCharacter:aCharacter
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1262
    "return true, if aCharacter is unallowed in a filename."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1263
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1264
    self isAbstract  ifTrue:[
8095
bfbd1309a4a6 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8036
diff changeset
  1265
        ^ ConcreteClass isBadCharacter:aCharacter
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1266
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1267
8095
bfbd1309a4a6 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8036
diff changeset
  1268
    ^ aCharacter isControlCharacter
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1269
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1270
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1271
isCaseSensitive
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1272
    "return true, if filenames are case sensitive.
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1273
     We ask the OS about this, to be independent here."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1274
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1275
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1276
        ^ ConcreteClass isCaseSensitive
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1277
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1278
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1279
    ^ OperatingSystem caseSensitiveFilenames
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1280
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1281
    "Modified: 8.9.1997 / 00:33:32 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1282
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1283
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1284
localNameStringFrom:aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1285
    "ST-80 compatibility.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1286
     what does this do ? (used in FileNavigator-goody).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1287
     GUESS: 
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1288
        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
  1289
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1290
    self isAbstract ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1291
        ^ ConcreteClass localNameStringFrom:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1292
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1293
15227
c05949447505 refactored
Claus Gittinger <cg@exept.de>
parents: 15192
diff changeset
  1294
    ^ aString withoutPrefix:self separatorString
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1295
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1296
    "Modified: 7.9.1995 / 10:44:56 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1297
    "Modified: 8.9.1997 / 00:33:51 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1298
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1299
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1300
maxComponentLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1301
    "return the maximum number of characters a filename component may
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1302
     be in size. This depends on the OperatingSystem."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1303
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1304
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1305
        ^ ConcreteClass maxComponentLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1306
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1307
    ^ OperatingSystem maxFileNameLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1308
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1309
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1310
maxLength
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1311
    "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
  1312
     This depends on the OperatingSystem."
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1313
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1314
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1315
        ^ ConcreteClass maxLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1316
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1317
    ^ OperatingSystem maxPathLength
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1318
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1319
    "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
  1320
    "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
  1321
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1322
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1323
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1324
    "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
  1325
     The default is nil here"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1326
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1327
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1328
        ^ ConcreteClass nullFilename
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1329
    ].
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1330
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1331
    ^ OperatingSystem getNullDevice
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1332
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1333
    "Created: / 12.1.1998 / 12:15:30 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1334
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1335
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1336
parentDirectoryName 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1337
    "return the name used for the parent directory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1338
     This is '..' for unix and dos-like systems. 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1339
     (there may be more in the future."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1340
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1341
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1342
        ^ ConcreteClass parentDirectoryName
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1343
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1344
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1345
    ^ OperatingSystem parentDirectoryName
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1346
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1347
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1348
     Filename parentDirectoryName  
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1349
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1350
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1351
    "Modified: 8.9.1997 / 00:34:39 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1352
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1353
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1354
separator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1355
    "return the file/directory separator.
15246
a621e4f1fcc4 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15227
diff changeset
  1356
     This is to be redefined in concrete classes."
a621e4f1fcc4 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15227
diff changeset
  1357
a621e4f1fcc4 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15227
diff changeset
  1358
   ^ ConcreteClass separator
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1359
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1360
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1361
     Filename separator
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1362
     PCFilename separator
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1363
    "
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1364
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1365
    "Modified: 8.9.1997 / 00:20:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1366
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1367
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1368
separatorString
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1369
    "return the file/directory separator as a string."
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1370
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1371
    ^ self separator asString
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1372
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1373
    "
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1374
     Filename separatorString  
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1375
    "
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1376
!
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1377
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1378
suffixSeparator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1379
    "return the filename suffix separator.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1380
     Usually, this is $. for unix-like and msdos systems 
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1381
     (there is currently no known system, where this differs)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1382
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1383
     ^ $.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1384
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1385
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1386
      Filename suffixSeparator  
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1387
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1388
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1389
    "Modified: 7.9.1995 / 11:10:43 / claus"
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1390
    "Modified: 30.4.1996 / 12:14:25 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1391
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1392
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1393
tempFileNameTemplate
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1394
    "return a template for temporary files.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1395
     This is expanded with the current processID and a sequenceNumber
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1396
     to generate a unique filename."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1397
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1398
    self isAbstract ifTrue:[
8668
40e71fa11ff7 oops - fixed usage of UnixFilename in a windows system
ca
parents: 8660
diff changeset
  1399
        ^ ConcreteClass tempFileNameTemplate
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1400
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1401
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1402
    ^ 'stxtmp_%1_%2'
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1403
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1404
    "Created: 8.9.1997 / 00:01:46 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1405
    "Modified: 8.9.1997 / 00:35:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1406
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1407
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1408
volumes
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1409
    "ST-80 compatibility.
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1410
     GUESS: does it return the available drives on MSDOS systems ?
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1411
     Q: what does this do on Unix systems ? (used in FileNavigator-goody)."
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1412
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1413
    self isAbstract ifTrue:[
8679
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1414
        ^ ConcreteClass volumes
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1415
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1416
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1417
    ^ OperatingSystem getDriveList
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1418
8679
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1419
    "
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1420
     Filename volumes
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1421
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1422
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1423
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1424
!Filename class methodsFor:'utilities'!
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1425
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1426
canonicalize:aPathString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1427
    "convert the argument, aPathString to a good format.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1428
     This should eliminate useless directory components (i.e. '././')
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1429
     and useless tree walks (i.e. '../foo/..')."
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1430
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1431
    ^ self nameFromComponents:(self canonicalizedNameComponents:aPathString)
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1432
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1433
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1434
     Filename canonicalize:'/etc/../etc'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1435
     Filename canonicalize:'/home/cg/../'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1436
     Filename canonicalize:'/home/cg/../././'  
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1437
     Filename canonicalize:'./home/cg/../././'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1438
     Filename canonicalize:'/home/././cg/../././'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1439
     Filename canonicalize:'/home/././cg/././'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1440
     Filename canonicalize:'/home/cg/../../..'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1441
     Filename canonicalize:'cg/../../..'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1442
     Filename canonicalize:'./'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1443
     Filename canonicalize:'/home/.'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1444
     Filename canonicalize:'/home/../..'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1445
     Filename canonicalize:'//foo'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1446
     Filename canonicalize:'///foo'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1447
     Filename canonicalize:'//foo//bar'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1448
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1449
!
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1450
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1451
canonicalizedNameComponents:aPathString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1452
    "convert the argument, aPathString to a good format.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1453
     This should eliminate useless directory components (i.e. '././')
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1454
     and useless tree walks (i.e. '../foo/..').
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1455
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1456
     Answer a sequenceable collection of name components."
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1457
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1458
    |comps newComps rootName dotDot dot|
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1459
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1460
    dotDot := self parentDirectoryName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1461
    dot := self currentDirectoryName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1462
    rootName := self separatorString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1463
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1464
    comps := self components:aPathString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1465
    newComps := OrderedCollection new:comps size.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1466
    comps do:[:eachComponent |
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1467
        eachComponent ~= dot ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1468
            eachComponent = dotDot ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1469
               (newComps isEmpty 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1470
                or:[(newComps size == 1 and:[newComps first startsWith:rootName]) 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1471
                or:[newComps last = dotDot]]) ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1472
                   newComps add:eachComponent
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1473
               ] ifFalse:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1474
                   newComps removeLast
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1475
               ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1476
            ] ifFalse:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1477
                newComps add:eachComponent
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1478
            ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1479
        ]
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1480
    ]. 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1481
    "/ add current Directory if empty
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1482
    newComps isEmpty ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1483
        newComps add:dot.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1484
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1485
    ^ newComps
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1486
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1487
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1488
     Filename canonicalizedNameComponents:'/etc/../etc'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1489
     Filename canonicalizedNameComponents:'/home/cg/../'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1490
     Filename canonicalizedNameComponents:'/home/cg/../././'  
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1491
     Filename canonicalizedNameComponents:'./home/cg/../././'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1492
     Filename canonicalizedNameComponents:'/home/././cg/../././'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1493
     Filename canonicalizedNameComponents:'/home/././cg/././'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1494
     Filename canonicalizedNameComponents:'/home/cg/../../..'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1495
     Filename canonicalizedNameComponents:'cg/../../..'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1496
     Filename canonicalizedNameComponents:'/'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1497
     Filename canonicalizedNameComponents:'./'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1498
     Filename canonicalizedNameComponents:'/.'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1499
     Filename canonicalizedNameComponents:'/home/.'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1500
     Filename canonicalizedNameComponents:'/home'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1501
     Filename canonicalizedNameComponents:'/home/../..'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1502
     Filename canonicalizedNameComponents:'//foo'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1503
     Filename canonicalizedNameComponents:'///foo'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1504
     Filename canonicalizedNameComponents:'//foo//bar'   
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1505
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1506
!
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1507
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1508
components:aString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1509
    "separate the pathName given by aString into 
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  1510
     a collection containing the directory components and the file's name as
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1511
     the final component.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1512
     If the argument names an absolute path, the first component will be the
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1513
     name of the root directory (i.e. '/')."
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1514
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1515
    |sep f vol rest components|
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1516
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1517
    self isAbstract ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1518
        ^ ConcreteClass components:aString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1519
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1520
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1521
    "/ the following works on Unix & MSDOS (but not on openVMS)
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1522
    "/ However, MSDOS drive-letters and network drives are
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1523
    "/ not correctly handled here.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1524
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1525
    sep := self separator.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1526
    f := aString asFilename.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1527
    vol := f volume.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1528
    vol size ~~ 0 ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1529
        rest := f localPathName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1530
    ] ifFalse:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1531
        rest := aString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1532
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1533
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1534
    components := rest asCollectionOfSubstringsSeparatedBy:sep.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1535
    (rest startsWith:sep) ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1536
        "first was a separator - root directory - restore"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1537
        (rest size > 1 and:[rest second = sep and:[vol isEmptyOrNil]]) ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1538
            "keep \\ for windows network paths"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1539
            components at:1 put:(String with:sep with:sep).
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1540
        ] ifFalse:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1541
            components at:1 put:sep asString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1542
        ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1543
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1544
    components := components select:[:each| each notEmpty].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1545
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1546
    "/ prepend volume to first component (the root directory)
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1547
    vol size ~~ 0 ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1548
        components at:1 put:(vol , (components at:1)).
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1549
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1550
    ^ components
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1551
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1552
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1553
     Filename components:'/foo/bar/baz'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1554
     Filename components:'/'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1555
     Filename components:'//'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1556
     Filename components:'foo/bar/baz'  
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1557
     Filename components:'foo/bar'  
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1558
     Filename components:'foo'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1559
     Filename components:'/foo'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1560
     Filename components:'//foo'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1561
     Filename components:''     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1562
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1563
     Filename components:'\'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1564
     Filename components:'\foo'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1565
     Filename components:'\foo\'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1566
     Filename components:'\foo\bar'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1567
     Filename components:'\foo\bar\'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1568
     Filename components:'c:'        
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1569
     Filename components:'c:\'       
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1570
     Filename components:'c:\foo'      
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1571
     Filename components:'c:\foo\'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1572
     Filename components:'c:\foo\bar'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1573
     Filename components:'c:\foo\bar\'  
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1574
     Filename components:'\\idefix'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1575
     Filename components:'\\idefix\home'     
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1576
     Filename components:'\\idefix\home\bar'    
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1577
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1578
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1579
    "Modified: / 24.9.1998 / 19:10:52 / cg"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1580
!
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1581
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1582
nameFromComponents:aCollectionOfDirectoryNames
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1583
    "return a filenameString from components given in aCollectionOfDirectoryNames. 
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1584
     If the first component is the name of the root directory (i.e. '/'),
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1585
     an absolute path-string is returned."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1586
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1587
    |sep s|
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1588
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1589
    self isAbstract ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1590
        ^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1591
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1592
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1593
    "/ fallBack - works on Unix & MSDOS
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1594
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1595
    sep := self separatorString.
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1596
    s := ''.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1597
    aCollectionOfDirectoryNames keysAndValuesDo:[:index :component |
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1598
        index == 1 ifTrue:[
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1599
            s := component.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1600
        ] ifFalse:[
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1601
            (index == 2 and:[ (s endsWith:sep) ]) ifTrue:[
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1602
                s := s , component
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1603
            ] ifFalse:[
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1604
                s := s , sep , component
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1605
            ]
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1606
        ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1607
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1608
    ^ s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1609
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1610
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1611
     Filename nameFromComponents:#('/' 'foo' 'bar' 'baz')  
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1612
     Filename nameFromComponents:#('foo' 'bar' 'baz')  
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1613
     Filename nameFromComponents:#('/') 
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1614
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1615
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1616
     comps := Filename components:'/foo/bar/baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1617
     Filename nameFromComponents:comps        
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1618
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1619
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1620
     comps := Filename components:'\foo\bar\baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1621
     Filename nameFromComponents:comps          
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1622
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1623
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1624
     comps := Filename components:'c:\foo\bar\baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1625
     Filename nameFromComponents:comps            
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
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1628
     comps := Filename components:'foo\bar\baz'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1629
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1630
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1631
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1632
     comps := Filename components:'foo'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1633
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1634
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1635
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1636
     comps := Filename components:'\'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1637
     Filename nameFromComponents:comps            
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1638
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1639
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1640
     comps := Filename components:'c:\'.
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1641
     Filename nameFromComponents:comps            
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1642
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1643
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1644
    "Modified: 8.9.1997 / 00:23:16 / cg"
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1645
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1646
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1647
readingFile:aPathName do:aBlock
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1648
    "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
  1649
     and return the blocks value.
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1650
     Ensures that the stream is closed."
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1651
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1652
    ^ aPathName asFilename readingFileDo:aBlock.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1653
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1654
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1655
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1656
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1657
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1658
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1659
     rslt := 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1660
        Filename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1661
            readingFile:'/etc/passwd'
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1662
            do:[:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1663
                s nextLine
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1664
            ]. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1665
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1666
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1667
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1668
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1669
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1670
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1671
     |rslt|
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1672
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1673
     rslt :=
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1674
        Filename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1675
            readingFile:'/etc/passwd' 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1676
            do:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1677
                [:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1678
                    |shells|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1679
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1680
                    shells := Bag new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1681
                    s linesDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1682
                        [:line |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1683
                            |parts|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1684
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1685
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1686
                            shells add:(parts seventh).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1687
                        ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1688
                    shells contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1689
                ].           
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1690
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1691
    "
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1692
! !
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1693
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1694
!Filename methodsFor:'Compatibility-VW5.4'!
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1695
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1696
asLogicalFileSpecification
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1697
    ^ self
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1698
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1699
    "Created: / 30.10.2001 / 17:31:10 / cg"
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1700
!
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1701
10583
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1702
canBeWritten
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1703
    "same as isWritable - for ST-80 compatibility"
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1704
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1705
    ^ self isWritable
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1706
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1707
    "
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1708
     '/foo/bar' asFilename canBeWritten 
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1709
     '/tmp' asFilename canBeWritten   
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1710
     'Makefile' asFilename canBeWritten   
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1711
    "
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1712
!
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1713
7596
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1714
definitelyExists
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1715
    "for now - a kludge"
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1716
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1717
    ^ self exists
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1718
!
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1719
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1720
extension
6454
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1721
    "return the receiver's extension;
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1722
     that is the characters from and including
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1723
     the last period or nil, if there is none."
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1724
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1725
    |string idx|
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1726
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1727
    string := self asString.
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1728
    idx := string lastIndexOf:$..
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1729
    idx > 1 ifTrue:[
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1730
        ^ string copyFrom:idx
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1731
    ].
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1732
    ^ nil
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1733
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1734
    "
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1735
     'foo.html' asFilename extension   
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1736
     'foo.bar' asFilename extension       
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1737
     'foo.bar.baz' asFilename extension   
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1738
     'foo.' asFilename extension          
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1739
     'foo' asFilename extension           
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1740
     '.login' asFilename extension           
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1741
    "
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1742
! !
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1743
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1744
!Filename methodsFor:'comparing'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1745
16255
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1746
< aFilename
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1747
    "compare file names - used for sorting"
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1748
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1749
    ^ self asString < aFilename asString
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1750
!
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1751
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1752
= aFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1753
    "return true, if the argument represents the same filename"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1754
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1755
    |str|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1756
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1757
    self species == aFilename species ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  1758
        str := aFilename asString.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  1759
        self species isCaseSensitive ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  1760
            ^ nameString = str
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  1761
        ].
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  1762
        ^ nameString sameAs:str
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1763
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1764
    ^ false
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1765
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1766
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1767
contentsIsPrefixOf:aFilename
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1768
    "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
  1769
     is the same as or a prefix of the contents of the file represented by the argument, aFilename.
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  1770
     This compares the files' actual contents; not the filenames."
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1771
8771
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1772
    |f2 s1 s2 bufferSize buffer1 buffer2 n|
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1773
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1774
    bufferSize := 8192 * 4.
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1775
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1776
    f2 := aFilename asFilename.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1777
    self fileSize > f2 fileSize ifTrue:[^ false].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1778
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1779
    [
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1780
        s1 := self readStream.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1781
        s2 := f2 readStream.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1782
        s1 binary.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1783
        s2 binary.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1784
8771
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1785
        buffer1 := ByteArray new:bufferSize.
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1786
        buffer2 := ByteArray new:bufferSize.
7776
e67e1ad8f5b5 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7702
diff changeset
  1787
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1788
        [s1 atEnd] whileFalse:[
8771
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1789
            n := s1 nextBytes:bufferSize into:buffer1 startingAt:1.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1790
            n == 0 ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1791
                "/ receiver shorter.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1792
                ^ true
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1793
            ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1794
            (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
  1795
                "/ aFilename shorter
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1796
                ^ false
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1797
            ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1798
            buffer1 ~= buffer2 ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1799
                ^ false
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1800
            ]
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1801
        ].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1802
        "/ receiver shorter or same size.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1803
    ] ensure:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1804
        s1 notNil ifTrue:[s1 close]. 
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1805
        s2 notNil ifTrue:[s2 close]. 
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1806
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1807
    ^ true
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1808
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1809
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1810
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1811
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1812
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1813
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1814
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1815
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1816
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1817
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1818
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1819
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1820
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1821
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1822
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1823
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1824
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1825
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1826
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1827
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1828
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1829
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1830
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1831
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1832
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1833
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1834
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1835
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1836
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1837
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1838
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1839
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1840
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1841
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1842
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1843
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1844
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1845
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1846
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1847
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1848
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1849
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1850
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1851
!
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1852
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1853
contentsStartsWithContentsOf:aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1854
    "return true if the contents of the file represented by aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1855
     is the same as or a prefix of the contents of the file represented by the receiver.
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  1856
     This compares the files' actual contents; not the filenames."
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1857
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1858
    ^ aFilename asFilename contentsIsPrefixOf:self
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1859
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1860
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1861
     |s|
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1862
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1863
     s := 'testFile1' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1864
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1865
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1866
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1867
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1868
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1869
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1870
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1871
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1872
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1873
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1874
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1875
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1876
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1877
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1878
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1879
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1880
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1881
     s nextPutAll:'44444'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1882
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1883
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1884
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1885
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1886
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1887
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1888
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1889
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1890
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1891
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1892
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1893
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1894
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1895
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1896
     s nextPutAll:'33334'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1897
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1898
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1899
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1900
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1901
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1902
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1903
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1904
hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1905
    "return an integer useful as a hash-key"
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1906
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  1907
    self species isCaseSensitive ifFalse:[
11425
51d14050b0d6 changed #hash
Claus Gittinger <cg@exept.de>
parents: 11424
diff changeset
  1908
        ^ nameString asUppercase hash   
11424
c169cc34afe9 fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents: 11406
diff changeset
  1909
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1910
    ^ nameString hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1911
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1912
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1913
sameContentsAs:aFilename
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1914
    "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
  1915
     same contents as the file represented by the argument, aFilename.
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  1916
     This compares the file's actual contents; not the filenames."
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1917
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1918
    |f2|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1919
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1920
    f2 := aFilename asFilename.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1921
    f2 fileSize = self fileSize ifFalse:[^ false].
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1922
    ^ self contentsIsPrefixOf:f2.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1923
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1924
    "
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1925
     'Make.proto' asFilename sameContentsAs:'Makefile'  
7122
5c925f402f6f comment
Claus Gittinger <cg@exept.de>
parents: 7120
diff changeset
  1926
     'Make.proto' asFilename sameContentsAs:'Make.proto'   
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1927
    "
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1928
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1929
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1930
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1931
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1932
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1933
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1934
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1935
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1936
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1937
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1938
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1939
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1940
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1941
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1942
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1943
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1944
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifFalse:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1945
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1946
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1947
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1948
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1949
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1950
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1951
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1952
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1953
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1954
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1955
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1956
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1957
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1958
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1959
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1960
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1961
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1962
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1963
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1964
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1965
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1966
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1967
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1968
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1969
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1970
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1971
! !
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
!Filename methodsFor:'converting'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1974
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1975
asAbsoluteFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1976
    "return the receiver converted to a filename with
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1977
     an absolute pathname."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1978
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  1979
    ^ self species named:self pathName
7332
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1980
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1981
    "
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1982
     '.' asFilename
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1983
     '.' asFilename asAbsoluteFilename
9173
312ada56e4a9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9062
diff changeset
  1984
     'c:' asFilename asAbsoluteFilename
7332
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  1985
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1986
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1987
10769
5623284ae0a0 +autoDeletedFiles
Claus Gittinger <cg@exept.de>
parents: 10663
diff changeset
  1988
asAutoDeletedFilename
13653
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  1989
    "will automatically delete myself, when no longer referenced"
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  1990
11784
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  1991
    ^ AutoDeletedFilename basicNew setName:self name
13653
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  1992
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  1993
    "Modified (comment): / 07-09-2011 / 12:20:59 / cg"
10769
5623284ae0a0 +autoDeletedFiles
Claus Gittinger <cg@exept.de>
parents: 10663
diff changeset
  1994
!
5623284ae0a0 +autoDeletedFiles
Claus Gittinger <cg@exept.de>
parents: 10663
diff changeset
  1995
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1996
asCanonicalizedFilename
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1997
    "return the receiver converted to a filename without intermediate ..'s and .'s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1998
     (similar to an absolute pathname, but symlinks are not resolved)."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1999
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  2000
    ^ self species named:(self species canonicalize:nameString)
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2001
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2002
    "
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2003
      'c:\test\work' asFilename asCanonicalizedFilename
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2004
      '/test/work' asFilename asCanonicalizedFilename
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2005
    "
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2006
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2007
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2008
asFilename
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2009
    "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
  2010
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2011
    "Thats pretty easy here :-)"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2012
    ^ self
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2013
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2014
    "Modified: 12.11.1996 / 12:40:03 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2015
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2016
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2017
asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2018
    "return the receiver converted to a string"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2019
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2020
    ^ nameString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2021
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2022
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2023
asURI
15001
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2024
    "return the receiver converted to a file URI"
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2025
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2026
    ^ FileURI fromFilename:self.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2027
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2028
15001
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2029
asURL
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2030
    "return an URL-object from myself"
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2031
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2032
    ^ URL fromString:self pathName.
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2033
!
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2034
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2035
components
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2036
    "return the receivers filename components - that is the name of each directory
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2037
     along the pathName (that DOES include the root directory)"
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2038
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  2039
    ^ self species components:self name
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2040
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2041
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2042
     '.' asFilename asAbsoluteFilename components 
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2043
     'Makefile' asFilename asAbsoluteFilename components     
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2044
    "
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2045
!
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2046
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2047
makeLegalFilename 
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2048
    "convert the receivers name to be a legal filename.
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2049
     This removes/replaces invalid characters and/or compresses
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2050
     the name as required by the OS.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2051
     The implementation may change in the future to be more
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2052
     OS specific."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2053
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2054
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2055
     actually, in Unix spaces are allowed - but it makes life
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2056
     so hard; therefore, replace them by underscores ...
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2057
    "
16761
3b2057603c18 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16755
diff changeset
  2058
    nameString := nameString copyReplaceAll:(Character space) with:$_ ifNone:nameString.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2059
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2060
     need more - especially on SYS5.3 type systems, 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2061
     we may want to contract the fileName to 14 characters.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2062
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2063
    ^ self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2064
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2065
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2066
     'hello world' asFilename makeLegalFilename 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2067
    "
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2068
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  2069
    "Modified: / 20.7.1998 / 13:16:51 / cg"
2707
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2070
!
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2071
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2072
withEncoding:encodingSymbol
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2073
    "dummy for now - for ST80 compatibility"
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2074
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2075
    ^ self
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2076
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2077
    "Created: 20.6.1997 / 17:01:28 / cg"
2
claus
parents: 1
diff changeset
  2078
! !
claus
parents: 1
diff changeset
  2079
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  2080
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2081
!Filename methodsFor:'enumerating-contents'!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2082
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2083
allDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2084
    "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
  2085
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2086
     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
  2087
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2088
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2089
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2090
     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
  2091
     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
  2092
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2093
    self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | 
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2094
        |eachFileOrDirectory|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2095
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2096
        eachFileOrDirectory := self construct:eachFileOrDirectoryName.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2097
        eachFileOrDirectory isDirectory ifTrue:[
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2098
            aBlock value:eachFileOrDirectory
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2099
        ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2100
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2101
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2102
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2103
     '.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2104
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2105
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2106
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2107
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2108
allParentDirectoriesDo:aBlock
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2109
    "evaluate aBlock for all (recursive) directories along the parent directory path.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2110
     The block is invoked with a filename-arguments."
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2111
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2112
    |parent here|
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2113
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2114
    here := self.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2115
    parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2116
    [here notNil and:[parent ~= here]] whileTrue:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2117
        aBlock value:parent.    
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2118
        here := parent.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2119
        parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2120
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2121
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2122
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2123
     '.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2124
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2125
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2126
9362
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2127
directories
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2128
    "return a collection of directories contained in the directory represented by the receiver."
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2129
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2130
    |collection|
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2131
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2132
    collection := OrderedCollection new.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2133
    self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | 
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2134
        eachFileOrDirectory isDirectory ifTrue:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2135
            collection add:eachFileOrDirectory.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2136
        ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2137
    ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2138
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2139
    ^ collection
9362
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2140
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2141
    "
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2142
     '.' asFilename directories.
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2143
    "
10557
2288b6652a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10551
diff changeset
  2144
2288b6652a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10551
diff changeset
  2145
    "Modified: / 29-05-2007 / 12:02:56 / cg"
9362
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2146
!
074ac7a3bc54 +directories
Claus Gittinger <cg@exept.de>
parents: 9263
diff changeset
  2147
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2148
directoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2149
    "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
  2150
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2151
     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
  2152
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2153
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2154
     OpenError is raised if I represent a non-existant or non-readable directories.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2155
     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
  2156
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2157
    self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2158
        eachFileOrDirectory isDirectory ifTrue:[
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2159
            aBlock value:eachFileOrDirectory
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2160
        ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2161
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2162
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2163
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2164
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2165
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2166
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2167
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2168
directoryContentsAsFilenamesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2169
    "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
  2170
     The block is invoked with a filename-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2171
     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
  2172
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2173
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2174
     An OpenError exception is raised it the directory does not exist or is not readable.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2175
     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
  2176
     Notice: this enumerates fileName objects; see also
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2177
     #directoryContentsDo:, which enumerates strings."
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2178
6776
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  2179
    self directoryContentsDo:[:entry |
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  2180
        aBlock value:(self construct:entry).
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  2181
    ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2182
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2183
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2184
     '.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2185
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2186
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2187
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2188
    "Modified: / 23.12.1999 / 20:56:35 / cg"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2189
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2190
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2191
directoryContentsDo:aBlock
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2192
    "evaluate aBlock for each file in the directory represented by the receiver.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2193
     The block is invoked with a string as argument.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2194
     The enumerations order is undefined - i.e. usually NOT sorted by
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2195
     filenames (but by creation time - on some systems).
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2196
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2197
     An OpenError exception is raised it the directory does not exist or is not readable.
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2198
     So users of this method better test for existing directory before.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2199
     Notice: this enumerates strings; see also
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2200
     #directoryContentsAsFilenamesDo:, which enumerates fileName objects."
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2201
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2202
    |s|
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2203
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2204
    s := DirectoryStream directoryNamed:self osNameForDirectoryContents.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2205
    "check for nil, in order to allow to proceed from an OpenError"
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2206
    s notNil ifTrue:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2207
        [
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2208
            [s atEnd] whileFalse:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2209
                |fn|
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2210
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2211
                fn := s nextLine.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2212
                (fn ~= '.' and:[fn ~= '..']) ifTrue:[        
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2213
                    aBlock value:fn
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2214
                ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2215
            ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2216
        ] ensure:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2217
            s close.
7846
1b0455dbf72d handle openErrors
ca
parents: 7836
diff changeset
  2218
        ].
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2219
    ].
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2220
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2221
    "
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2222
     '.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
7473
5474c91e0aa3 Comments
Stefan Vogel <sv@exept.de>
parents: 7464
diff changeset
  2223
     'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2224
     [
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2225
        'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2226
     ] on:OpenError do:[:ex| ex proceed]
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2227
    "
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2228
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2229
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2230
    "Modified: / 23.12.1999 / 20:56:35 / cg"
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2231
!
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2232
9382
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2233
files
9383
f272fd57d049 category
Claus Gittinger <cg@exept.de>
parents: 9382
diff changeset
  2234
    "return a collection of files contained in the directory represented by the receiver."
9382
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2235
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2236
    |collection|
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2237
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2238
    collection := OrderedCollection new.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2239
    self directoryContentsAsFilenamesDo:[:eachFileName | 
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2240
        eachFileName isRegularFile ifTrue:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2241
            collection add:eachFileName
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2242
        ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2243
    ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2244
    ^ collection.
9382
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2245
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2246
    "
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2247
     '.' asFilename files.
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2248
    "
10557
2288b6652a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10551
diff changeset
  2249
2288b6652a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10551
diff changeset
  2250
    "Modified: / 29-05-2007 / 12:02:15 / cg"
9382
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2251
!
Claus Gittinger <cg@exept.de>
parents: 9376
diff changeset
  2252
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2253
filesDo:aBlock
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2254
    "evaluate aBlock for all files contained in the directory represented by the receiver."
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2255
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2256
    ^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | 
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2257
        eachFileOrDirectory isRegularFile ifTrue:[ aBlock value: eachFileOrDirectory].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2258
    ].
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2259
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2260
    "
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2261
     '.' asFilename filesDo:[:f | Transcript showCR:f].
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2262
    "
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2263
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2264
    "Created: / 29-08-2006 / 11:03:15 / cg"
10557
2288b6652a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10551
diff changeset
  2265
    "Modified: / 29-05-2007 / 12:02:46 / cg"
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2266
!
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2267
13191
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2268
recursiveDirectoryContentsAsFilenamesDo:aBlock 
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2269
    "evaluate aBlock for all files and directories found under the receiver.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2270
     The block is invoked with the filenames as argument.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2271
     The walk is bread-first.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2272
     This excludes any entries for '.' or '..'.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2273
     Subdirectory files are included with a relative pathname.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2274
     Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)."
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2275
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2276
    self recursiveDirectoryContentsDo:[:relFn |
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2277
        aBlock value:(self construct:relFn)
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2278
    ].
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2279
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2280
    "
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2281
     '.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] 
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2282
    "
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2283
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2284
    "Modified: / 12-09-2010 / 15:43:22 / cg"
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2285
!
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2286
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2287
recursiveDirectoryContentsDo:aBlock 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2288
    "evaluate aBlock for all files and directories found under the receiver.
13057
4f7fa62156ac comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 12975
diff changeset
  2289
     The block is invoked with the relative filenames as string-argument.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2290
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2291
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2292
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2293
     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
  2294
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2295
    self recursiveDirectoryContentsDo:aBlock directoryPrefix:''
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2296
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2297
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2298
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2299
    "
13057
4f7fa62156ac comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 12975
diff changeset
  2300
4f7fa62156ac comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 12975
diff changeset
  2301
    "Modified: / 12-09-2010 / 15:43:22 / cg"
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2302
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2303
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2304
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2305
    "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
  2306
     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
  2307
     The walk is breadth-first.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2308
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2309
     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
  2310
     A proceedable exception is raised forn non-accessable directories.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2311
     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
  2312
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2313
    |fileNames dirNames p|
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2314
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2315
    fileNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2316
    dirNames := OrderedCollection new.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2317
    self directoryContentsDo:[:f | |t|
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2318
        t := self construct:f.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2319
        t isDirectory ifTrue:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2320
            t isSymbolicLink ifFalse:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2321
                dirNames add:f
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2322
            ]
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2323
        ] ifFalse:[
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2324
            fileNames add:f
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2325
        ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2326
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2327
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2328
    aPrefix size > 0 ifTrue:[
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  2329
        p := aPrefix , self separator
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2330
    ] ifFalse:[
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2331
        p := ''
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2332
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2333
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2334
    fileNames do:[:aFile | aBlock value:(p , aFile)].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2335
    dirNames do:[:dN |
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2336
        aBlock value:(p , dN).
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2337
        (self construct:dN)
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2338
            recursiveDirectoryContentsDo:aBlock directoryPrefix:(p , dN)
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2339
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2340
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2341
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2342
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2343
     '/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] 
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2344
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2345
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2346
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2347
withAllDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2348
    "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
  2349
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2350
     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
  2351
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2352
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2353
     OpenError is raised if the name I represent does not exist or is not readable.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2354
     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
  2355
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2356
    self isDirectory ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2357
        aBlock value:self.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2358
    ].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2359
    self allDirectoriesDo:aBlock.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2360
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2361
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2362
     '.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2363
     'IdoNOTexist' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2364
     '/etc/hosts' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2365
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2366
! !
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2367
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2368
!Filename methodsFor:'error handling'!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2369
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2370
accessDeniedError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2371
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2372
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2373
    "report an error that access to some file was denied"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2374
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2375
    |errNo errString|
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2376
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2377
    errNo := OperatingSystem lastErrorNumber.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2378
    errString := OperatingSystem lastErrorString.
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2379
    errString size == 0 ifTrue:[
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  2380
        errString := ''.
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2381
    ] ifFalse:[
6662
250ea1d04a4a errorStrings when raising exceptions.
Stefan Vogel <sv@exept.de>
parents: 6556
diff changeset
  2382
        errString := ' (' , errString , ')'
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2383
    ].
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2384
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2385
    ^ OperatingSystem accessDeniedErrorSignal
13139
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2386
        raiseRequestWith:filename ? self
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2387
        errorString:(' : ' , (filename ? self) asString , errString)
4820
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2388
481593067423 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4757
diff changeset
  2389
    "Modified: / 26.9.1999 / 16:11:44 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2390
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2391
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2392
fileCreationError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2393
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2394
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2395
    "report an error that some file could not be created"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2396
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2397
    ^ OperatingSystem accessDeniedErrorSignal
13139
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2398
        raiseRequestWith:filename?self
15455
936632c01c4e class: Filename
Claus Gittinger <cg@exept.de>
parents: 15364
diff changeset
  2399
        errorString:(' - cannot create/write file: "%1"' bindWith:(filename ? self) asString)
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2400
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2401
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2402
fileNotFoundError:filename 
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2403
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2404
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2405
    "report an error that some file was not found"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2406
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2407
    ^ OperatingSystem fileNotFoundErrorSignal
13139
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2408
        raiseRequestWith:filename?self
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2409
        errorString:('file not found: ' , (filename ? self) asString)
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2410
!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2411
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2412
removeError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2413
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2414
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2415
    "report an error that some file could not be removed"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2416
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  2417
    ^ OperatingSystem accessDeniedErrorSignal
13139
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2418
        raiseRequestWith:filename?self
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2419
        errorString:('cannot remove: ' , (filename?self) asString)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2420
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2421
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2422
reportError:string with:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2423
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2424
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2425
    "report an error"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  2426
15192
98d237124310 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15163
diff changeset
  2427
    ^ OsError
13139
288a01786ed5 changed:5 methods
Stefan Vogel <sv@exept.de>
parents: 13109
diff changeset
  2428
        raiseRequestWith:filename?self
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2429
        errorString:string
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2430
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2431
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2432
!Filename methodsFor:'file access'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2433
3015
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2434
appendStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2435
    "return a stream for appending to the file represented by the receiver.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2436
     If the file does not already exist, it is created.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2437
     Same as #appendingWriteStream for ST-80 compatibility."
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2438
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2439
    ^ self appendingWriteStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2440
!
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  2441
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2442
appendingWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2443
    "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
  2444
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2445
     if it does exist, writes are appended at the end."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2446
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2447
    ^ FileStream appendingOldFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2448
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2449
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2450
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2451
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2452
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2453
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2454
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2455
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2456
     s := '/tmp/foo' asFilename appendingWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2457
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2458
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2459
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2460
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2461
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2462
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2463
15490
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2464
existingReadWriteStream
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2465
    "return a stream for read/write the file represented by the receiver.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2466
     If the file does not already exist, an exception is raised."
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2467
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2468
    ^ FileStream oldFileNamed:(self osNameForAccess)
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2469
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2470
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2471
     '/tmp/blaFaselQuall666666' asFilename remove.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2472
     '/tmp/blaFaselQuall666666' asFilename existingReadWriteStream.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2473
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2474
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2475
     |s|
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2476
     s := '/tmp/foo' asFilename readWriteStream.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2477
     s nextPutAll:'1234567890'; close.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2478
     s := '/tmp/foo' asFilename existingReadWriteStream.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2479
     s nextPutAll:'abcdef'; close.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2480
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2481
     '/tmp/foo' asFilename contents inspect.     
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2482
     '/tmp/foo' asFilename remove      
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2483
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2484
!
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  2485
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2486
newReadWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2487
    "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
  2488
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2489
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2490
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2491
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2492
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2493
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2494
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2495
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2496
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2497
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2498
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2499
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2500
     s := '/tmp/foo' asFilename newReadWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2501
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2502
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2503
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2504
     '/tmp/foo' asFilename contents   
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2505
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2506
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2507
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2508
openWithMode:anArrayOrString
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2509
    "return a stream for read/write the file represented by the receiver.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2510
     If the file does not already exist, it is created;
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2511
     if it does exist, it is truncated."
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2512
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2513
    ^ FileStream open:self osNameForAccess withMode:anArrayOrString
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2514
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2515
    "
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2516
     |s|
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2517
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2518
     s := '/tmp/foo' asFilename openWithMode:'r+'.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2519
     s nextPutAll:'1234567890'.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2520
     s close.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2521
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2522
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2523
     '/tmp/foo' asFilename contents   
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2524
    "
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2525
!
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  2526
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2527
readStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2528
    "return a stream for reading from the file represented by the receiver.
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2529
     Raises an error if the file does not exist."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2530
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2531
    ^ FileStream readonlyFileNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2532
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2533
    "
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2534
      '/tmp/foo' asFilename readStream.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2535
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2536
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2537
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2538
readWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2539
    "return a stream for read/write the file represented by the receiver.
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2540
     If the file does not already exist, it is created.
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2541
     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
  2542
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  2543
    ^ FileStream fileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2544
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2545
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2546
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2547
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2548
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2549
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2550
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2551
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2552
     s := '/tmp/foo' asFilename readWriteStream. 
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2553
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2554
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2555
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2556
     '/tmp/foo' asFilename contents      
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  2557
     '/tmp/foo' asFilename remove      
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2558
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2559
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2560
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2561
writeStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2562
    "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
  2563
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2564
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2565
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2566
    ^ FileStream newFileForWritingNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2567
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2568
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2569
     '/tmp/foo' asFilename writeStream 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2570
    "
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2571
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2572
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2573
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2574
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2575
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2576
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2577
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2578
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2579
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2580
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2581
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2582
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2583
     '/tmp/foo' asFilename contents  
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  2584
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2585
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2586
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2587
!Filename methodsFor:'file access - migration'!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2588
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2589
appendingWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2590
    "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
  2591
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2592
     if it does exist, writes are appended at the end.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2593
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2594
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2595
     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
  2596
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2597
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2598
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2599
        FileStream appendingOldFileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2600
      ] on:FileStream openErrorSignal do:[:ex| nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2601
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2602
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2603
newReadWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2604
    "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
  2605
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2606
     if it does exist, it is truncated.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2607
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2608
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2609
     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
  2610
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2611
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2612
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2613
         FileStream newFileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2614
    ] on:FileStream openErrorSignal do:[:ex|nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2615
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2616
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2617
readStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2618
    "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
  2619
     If the file does not already exist, nil is returned.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2620
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2621
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2622
     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
  2623
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2624
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2625
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2626
        FileStream readonlyFileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2627
    ] on:FileStream openErrorSignal do:[:ex|nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2628
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2629
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2630
     '/tmp/foo' asFilename readStreamOrNil 
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2631
     '/tmp/foo' asFilename readStream 
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2632
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2633
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2634
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2635
readWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2636
    "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
  2637
     If the file does not already exist, it is created.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2638
     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
  2639
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2640
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2641
     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
  2642
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2643
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2644
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2645
        FileStream fileNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2646
    ] on:FileStream openErrorSignal do:[:ex|^ nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2647
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2648
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2649
writeStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2650
    "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
  2651
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2652
     if it does exist, it is truncated.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2653
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2654
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2655
     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
  2656
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2657
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2658
    ^ [
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2659
        FileStream newFileForWritingNamed:(self osNameForAccess)
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  2660
    ] on:FileStream openErrorSignal do:[:ex|^ nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2661
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2662
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2663
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2664
     '/etc/foo' asFilename writeStreamOrNil 
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2665
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2666
! !
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  2667
16310
c58c06bf77b6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16272
diff changeset
  2668
!Filename methodsFor:'file access rights'!
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2669
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2670
accessRights
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2671
    "return the access rights of the file as opaque data
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2672
     (SmallInteger in unix/linux)"
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2673
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2674
    ^ OperatingSystem accessModeOf:self osNameForFile.
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2675
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2676
    "
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2677
     'Make.proto' asFilename accessRights
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2678
    "
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2679
!
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2680
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2681
accessRights:opaqueData
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2682
    "set the access rights of the file to opaqueData,
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2683
     which is normally retrieved by Filename>>#accessRights."
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2684
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2685
    (OperatingSystem changeAccessModeOf:self osNameForFile to:opaqueData) ifFalse:[
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2686
        ^ self accessDeniedError:self
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2687
    ].
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2688
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2689
    "
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2690
     |rights|
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2691
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2692
     rights := 'Make.proto' asFilename accessRights. 
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2693
     'Make.proto' asFilename accessRights:rights. 
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2694
    "
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2695
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2696
    "Modified: / 5.5.1999 / 13:41:21 / cg"
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2697
!
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2698
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2699
addAccessRights:aCollection
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2700
    "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
  2701
     by the receiver. The argument must be a collection of symbols,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2702
     such as #readUser, #writeGroup etc."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2703
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2704
    |access osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2705
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  2706
    osName := self osNameForFile.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2707
    access := OperatingSystem accessModeOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2708
    aCollection do:[:accessSymbol |
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2709
        access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2710
    ].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  2711
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2712
        ^ self accessDeniedError:self
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2713
    ]
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2714
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2715
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2716
     'foo' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2717
     'foo' asFilename addAccessRights:#(readUser readGroup readOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2718
     'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2719
     'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers).
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
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2723
makeExecutable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2724
    "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
  2725
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2726
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2727
    ^ self addAccessRights:#(executeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2728
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2729
    "Created: 9.1.1996 / 15:32:47 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2730
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2731
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2732
makeExecutableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2733
    "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
  2734
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2735
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2736
    ^ self addAccessRights:#(executeUser executeGroup executeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2737
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2738
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2739
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2740
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2741
makeExecutableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2742
    "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
  2743
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2744
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2745
    ^ self addAccessRights:#(executeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2746
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2747
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2748
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2749
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2750
makeReadable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2751
    "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
  2752
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2753
    ^ self addAccessRights:#(readUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2754
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2755
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2756
makeReadableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2757
    "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
  2758
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2759
    ^ self addAccessRights:#(readUser readGroup readOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2760
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2761
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2762
makeReadableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2763
    "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
  2764
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2765
    ^ self addAccessRights:#(readGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2766
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2767
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2768
makeUnwritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2769
    "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
  2770
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2771
    ^ self removeAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2772
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2773
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2774
makeWritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2775
    "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
  2776
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2777
    ^ self addAccessRights:#(writeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2778
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2779
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2780
makeWritableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2781
    "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
  2782
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2783
    ^ self addAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2784
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2785
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2786
makeWritableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2787
    "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
  2788
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2789
    ^ self addAccessRights:#(writeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2790
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2791
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2792
removeAccessRights:aCollection
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2793
    "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
  2794
     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
  2795
     such as #readUser, #writeGroup etc.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2796
     Raises an exception if not successful."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2797
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2798
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2799
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2800
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2801
    access := OperatingSystem accessModeOf:osName.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2802
    aCollection do:[:accessSymbol |
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2803
        access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert.
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2804
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2805
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  2806
        ^ self accessDeniedError:self
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2807
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2808
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2809
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2810
     'foo' asFilename writeStream close.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2811
     'foo' asFilename removeAccessRights:#(readUser readGroup readOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2812
     'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2813
     'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2814
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2815
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2816
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2817
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2818
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2819
symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2820
    "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
  2821
     The returned collection consists of symbols like:
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2822
        #readUser, #writeGroup etc."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2823
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2824
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2825
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2826
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2827
    access := OperatingSystem accessModeOf:osName.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2828
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2829
    ^ 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2830
        #(  readUser writeUser executeUser
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2831
            readGroup writeGroup executeGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2832
            readOthers writeOthers executeOthers
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2833
          ) select:[:eachSymbolicAccessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2834
                access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2835
            ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2836
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2837
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2838
     'Makefile' asFilename symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2839
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2840
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2841
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2842
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2843
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2844
symbolicAccessRights:aCollectionOfSymbols
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2845
    "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
  2846
     The collection must consist of symbols like:
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2847
        #readUser, #writeGroup etc."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2848
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2849
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2850
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2851
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2852
    access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol |
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2853
                bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2854
              ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2855
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2856
    (OperatingSystem changeAccessModeOf:osName to:access) ifFalse:[
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2857
        ^ self accessDeniedError:self
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2858
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2859
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2860
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2861
     |rights|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2862
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2863
     rights := 'Makefile' asFilename symbolicAccessRights. 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2864
     'Makefile' asFilename symbolicAccessRights:(rights , #(executeOthers)). 
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2865
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2866
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2867
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2868
! !
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2869
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2870
!Filename methodsFor:'file operations'!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  2871
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2872
appendTo:newNameOrStream
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2873
    "append the file - the argument must be convertable to a filename.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2874
     Raises an exception, if an error occurs."
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2875
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2876
    |inStream outStream outStreamToClose|
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2877
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2878
    inStream := self readStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2879
    [
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2880
        newNameOrStream isStream ifTrue:[
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2881
            outStream := newNameOrStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2882
        ] ifFalse:[
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2883
            outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2884
        ].
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2885
8769
Claus Gittinger <cg@exept.de>
parents: 8754
diff changeset
  2886
        inStream binary.
Claus Gittinger <cg@exept.de>
parents: 8754
diff changeset
  2887
        outStream binary.
Claus Gittinger <cg@exept.de>
parents: 8754
diff changeset
  2888
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2889
        [
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2890
            inStream copyToEndInto:outStream.
15192
98d237124310 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15163
diff changeset
  2891
        ] on:OsError do:[:ex|
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2892
            ^ self fileCreationError:newNameOrStream
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2893
        ]
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2894
    ] ensure:[
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2895
        inStream close.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2896
        outStreamToClose notNil ifTrue:[outStreamToClose close].
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2897
    ].
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2898
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2899
    "
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2900
     '/etc/group' asFilename appendTo:'/tmp/Makefile.foo'.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2901
     'Makefile' asFilename appendTo:'/tmp/Makefile.foo'
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2902
     'Makefile' asFilename copyTo:'/'
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2903
     'smalltalk' asFilename copyTo:'/dev/null'
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2904
    "
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2905
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2906
    "Modified: / 23.12.1999 / 21:52:36 / cg"
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2907
!
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  2908
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2909
basicMakeDirectory
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2910
    "create a directory with the receivers name.
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2911
     Return true if successful, false if not."
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2912
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2913
    ^ OperatingSystem createDirectory:(self osNameForDirectory)
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2914
!
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  2915
10020
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2916
copyTo:newNameArg
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  2917
    "Copy the file's contents into another file.
9235
5f71e9313a01 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9206
diff changeset
  2918
     The argument must be convertable to a filename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2919
     Raises an exception, if an error occurs."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2920
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2921
    |newName inStream outStream newNameAlreadyExists|
10020
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2922
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2923
    newName := newNameArg asFilename.
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2924
8535
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2925
    "Contents is not copied if newName represent same file as me."
10020
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2926
    newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ].
8535
c108815bc276 added enhancements by Jan
Claus Gittinger <cg@exept.de>
parents: 8477
diff changeset
  2927
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2928
    inStream := self readStream.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2929
    inStream isNil ifTrue:[
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2930
        "open failed, but somenone did a proceed for the OpenError.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2931
         Ignore this file but continue in order to copy the rest when
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2932
         doing a recursive copy"
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2933
        ^ self.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2934
    ].
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2935
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2936
    [
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2937
        newNameAlreadyExists := newName exists.
10020
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2938
        outStream := newName writeStream.
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2939
        newNameAlreadyExists ifFalse:[
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  2940
            [
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  2941
                "would be nice to keep the access rights of the original test suite"    
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  2942
                newName accessRights:self accessRights.
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  2943
            ] on:OperatingSystem accessDeniedErrorSignal do:[:ex|
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  2944
                "ignore the error - may occure when copying to a network drive"
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  2945
            ].            
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2946
        ].
16492
0d3a253fe98d class: Filename
Stefan Vogel <sv@exept.de>
parents: 16490
diff changeset
  2947
        inStream binary; buffered:false.
15846
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  2948
        outStream binary; buffered:false.
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  2949
        inStream copyToEndInto:outStream.
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2950
    ] ensure:[
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  2951
        inStream close.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  2952
        outStream notNil ifTrue:[outStream close].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2953
    ].
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
    "
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2956
     'Make.proto' asFilename copyTo:'/tmp/Makefile.foo'
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  2957
     'Make.proto' asFilename copyTo:'/'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2958
     'smalltalk' asFilename copyTo:'/dev/null'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2959
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  2960
10020
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2961
    "Modified: / 10-09-2004 / 09:49:28 / janfrog"
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  2962
    "Modified: / 29-09-2006 / 16:26:32 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2963
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2964
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2965
copyToStream:outStream
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  2966
    "Copy the file's contents into another file.
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2967
     The argument must be convertable to a filename.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2968
     Raises an exception, if an error occurs."
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2969
15858
db1336645839 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15846
diff changeset
  2970
    |inStream resetBinary|
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2971
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2972
    "Contents is not copied if newName represent same file as me."
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2973
    outStream isFileStream ifTrue:[
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2974
        outStream fileName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ].
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2975
    ].
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2976
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2977
    inStream := self readStream.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2978
    [
16485
a3dd0c8d395c class: Filename
Stefan Vogel <sv@exept.de>
parents: 16389
diff changeset
  2979
        inStream binary"; buffered:false".
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2980
        resetBinary := false.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2981
        outStream isBinary ifFalse:[
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2982
            outStream binary.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2983
            resetBinary := true.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2984
        ].
15858
db1336645839 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15846
diff changeset
  2985
        inStream copyToEndInto:outStream.
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2986
    ] ensure:[
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2987
        inStream close.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2988
        resetBinary ifTrue:[
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2989
            outStream text.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2990
        ].
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2991
    ].
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2992
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2993
    "   
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2994
     |out|
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2995
     out := FileStream newTemporary.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2996
     'Make.proto' asFilename copyToStream:out.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2997
     out reset; contents
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2998
    "
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  2999
!
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3000
6983
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3001
createAsEmptyFile
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3002
    "create an empty file with the receivers name.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3003
     Raises an exception if not successful
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3004
    (either already existing or creation not possible)"
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3005
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3006
    |writeStream|
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3007
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3008
    self exists ifTrue:[
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3009
        OperatingSystem accessDeniedErrorSignal
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3010
            raiseRequestWith:self
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3011
            errorString:(' - file exists: ' , self asString).
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3012
        ^ self
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3013
    ].  
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3014
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3015
    FileStream openErrorSignal handle:[:ex|
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3016
        self fileCreationError:self.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3017
        ^ self
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3018
    ] do:[    
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3019
        writeStream := self newReadWriteStream.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3020
    ].
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3021
    writeStream close.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3022
!
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3023
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3024
createAsSymbolicLinkTo:linkFilenameString
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3025
    "create a directory with the receivers name.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3026
     Raises an exception if not successful"
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3027
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3028
    OperatingSystem createSymbolicLinkFrom:linkFilenameString to:self pathName.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3029
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3030
    "
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3031
        '/tmp/link' asFilename makeSymbolicLinkTo:'bla'
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3032
    "
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3033
!
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3034
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3035
delete
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3036
    "remove the file - same as remove, for ST-80 compatibility"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3037
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3038
    self remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3039
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3040
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3041
makeDirectory
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3042
    "create a directory with the receivers name.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3043
     Raises an exception if not successful"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3044
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  3045
    (self basicMakeDirectory) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3046
        "/
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3047
        "/ could have existed before ...
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3048
        "/
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3049
        (self exists and:[self isDirectory]) ifFalse:[
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3050
            self fileCreationError:self.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3051
            ^ false
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3052
        ]
2982
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  3053
    ].
3032a3a7e17a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2978
diff changeset
  3054
    ^ true
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  3055
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3056
    "Modified: / 5.5.1999 / 13:36:33 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3057
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3058
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3059
moveFileTo:newName
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3060
    "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
  3061
     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
  3062
     Raise an exception if not successful.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3063
     (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
  3064
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3065
    [self renameTo:newName] 
15192
98d237124310 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15163
diff changeset
  3066
        on:OsError 
7134
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  3067
        do:[:ex |
15121
9b338c1757de use #creator instead of #signal
Claus Gittinger <cg@exept.de>
parents: 15023
diff changeset
  3068
            ex creator == OperatingSystem fileNotFoundErrorSignal ifTrue:[
7134
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  3069
                ex reject
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  3070
            ].
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3071
            self safeCopyTo:newName. 
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3072
            self remove
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3073
        ].
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3074
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3075
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3076
     |f s|
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3077
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3078
     f := '/tmp/foo' asFilename.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3079
     s := f writeStream.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3080
     s nextPutLine:'hello'.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3081
     s close.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3082
     f renameTo:'./foo'
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3083
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3084
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3085
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3086
     |f s|
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3087
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3088
     f := '/tmp/foo' asFilename.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3089
     s := f writeStream.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3090
     s nextPutLine:'hello'.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3091
     s close.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3092
     f moveTo:'./foo'
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3093
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3094
!
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3095
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3096
moveTo:newNameArg
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3097
    "copy the file represented by the receiver, then delete it.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3098
     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
  3099
     Raise an exception if not successful.
3d801043be3f dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 5577
diff changeset
  3100
     (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
  3101
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3102
    |newName|
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3103
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3104
    newName := newNameArg asFilename.    
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  3105
    [self renameTo:newName] 
12956
f3924bb0cda0 changed:
Stefan Vogel <sv@exept.de>
parents: 12955
diff changeset
  3106
        on:(OSErrorHolder inappropriateReferentSignal) 
7134
764473cb4635 no need to try alternative file-move, if a fileNotFound is raised.
Claus Gittinger <cg@exept.de>
parents: 7122
diff changeset
  3107
        do:[:ex |
12956
f3924bb0cda0 changed:
Stefan Vogel <sv@exept.de>
parents: 12955
diff changeset
  3108
            "handle renames accross device boundaries (Unix. cross device link)"
6995
a7650ef2b1be move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6983
diff changeset
  3109
            self isDirectory ifTrue:[
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3110
                self recursiveMoveDirectoryTo:newName.
6995
a7650ef2b1be move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6983
diff changeset
  3111
            ] ifFalse:[
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3112
                self safeCopyTo:newName.
12956
f3924bb0cda0 changed:
Stefan Vogel <sv@exept.de>
parents: 12955
diff changeset
  3113
                self remove.
6995
a7650ef2b1be move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6983
diff changeset
  3114
            ].
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  3115
        ].
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3116
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3117
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3118
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3119
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3120
     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
  3121
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3122
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3123
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3124
     f renameTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3125
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3126
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3127
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3128
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3129
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3130
     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
  3131
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3132
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3133
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3134
     f moveTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3135
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3136
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3137
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3138
recursiveCopyTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3139
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3140
     Otherwise, copy the directory and recursively
12975
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3141
     all of its subfiles/subdirectories.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3142
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3143
     Raises an exception if not successful.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3144
     Do not resolve symbolic links.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3145
     If a whole directory is to be copied and the destination directory 
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3146
     does not exist, it will be created."
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3147
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3148
    |ok destinationFilename|
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3149
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3150
    destinationFilename := destination asFilename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3151
    self isDirectory ifFalse:[
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3152
        destinationFilename isDirectory ifTrue:[
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3153
            destinationFilename := destinationFilename construct:self baseName.
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3154
        ].
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3155
        self copyTo:destinationFilename.
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3156
        ^ self.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3157
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3158
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3159
    "/ typically, an 'cp -r' is faster;
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3160
    "/ 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
  3161
    "/ fallBack doing a manual directory walk.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3162
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3163
    ok := OperatingSystem 
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3164
            recursiveCopyDirectory:(self osNameForDirectory)
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3165
            to:(destinationFilename osNameForDirectory).
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3166
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3167
    ok ifFalse:[
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3168
        self recursiveCopyWithoutOSCommandTo:destinationFilename
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3169
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3170
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3171
    "
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3172
        '.' asFilename recursiveCopyTo:'/tmp/xxx'.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3173
    "
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3174
12975
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3175
    "Created: / 05-05-1999 / 13:35:01 / cg"
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3176
    "Modified: / 31-05-1999 / 13:11:34 / cg"
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3177
    "Modified: / 29-07-2010 / 12:41:06 / sr"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3178
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3179
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3180
recursiveCopyWithoutOSCommandTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3181
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3182
     Otherwise, copy the directory and all of its subfiles/subdirectories.
11192
828184f29182 recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents: 11004
diff changeset
  3183
     This one walks down the directory hierarchy, not using any OS command to do the copy.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3184
     Raises an exception if not successful.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3185
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3186
     Do not resolve symbolic links.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3187
     If a whole directory is to be copied and the destination directory 
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3188
     does not exist, it will be created."
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3189
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3190
    |destinationFilename|
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3191
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3192
    destinationFilename := destination asFilename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3193
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3194
    self isDirectory ifTrue:[
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3195
        destinationFilename exists ifFalse:[
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3196
            destinationFilename makeDirectory.
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3197
            destinationFilename accessRights:self accessRights.
11192
828184f29182 recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents: 11004
diff changeset
  3198
        ].
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3199
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3200
        self directoryContents do:[:aFilenameString |
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3201
            |src dst|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3202
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3203
            src := self construct:aFilenameString.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3204
            dst := destinationFilename construct:aFilenameString.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3205
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3206
            src isDirectory ifTrue:[
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3207
                src recursiveCopyWithoutOSCommandTo:dst
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3208
            ] ifFalse:[src isSymbolicLink ifTrue:[                    
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3209
                dst
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3210
                    remove;
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3211
                    createAsSymbolicLinkTo:src linkInfo path.
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3212
            ] ifFalse:[
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3213
                src copyTo:dst.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3214
            ]].
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3215
        ].
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3216
    ] ifFalse:[
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3217
        destinationFilename isDirectory ifTrue:[
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3218
            destinationFilename := destinationFilename construct:self baseName.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3219
        ].
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3220
        self copyTo:destinationFilename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3221
    ]
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3222
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3223
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3224
     '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3225
     'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3226
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3227
4246
23a662cb9b05 fixed recursive copying
Claus Gittinger <cg@exept.de>
parents: 4245
diff changeset
  3228
    "Modified: / 31.5.1999 / 18:12:31 / cg"
615
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
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3231
recursiveMakeDirectory
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3232
    "create a directory with the receivers name and all required intermediate
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3233
     directories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3234
     Raises an exception if not successful."
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3235
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3236
    (OperatingSystem recursiveCreateDirectory:(self osNameForDirectory)) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3237
        ^ self fileCreationError:self
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3238
    ]
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3239
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3240
    "Created: / 27.11.1995 / 23:36:40 / cg"
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3241
    "Modified: / 5.5.1999 / 13:38:42 / cg"
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3242
!
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3243
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3244
recursiveMoveDirectoryTo:newName
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3245
    "recursively copy the directory represented by the receiver, then delete it.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3246
     This is different to renaming in case of cross device moves.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3247
     Raise an exception if not successful.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3248
     (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
  3249
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3250
    [self renameTo:newName] 
15192
98d237124310 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15163
diff changeset
  3251
        on:OsError 
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3252
        do:[ 
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3253
            self recursiveCopyTo:newName.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3254
            self recursiveRemove
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3255
        ].
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3256
!
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  3257
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3258
recursiveRemove
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3259
    "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
  3260
     Otherwise, remove the directory and all of its subfiles/subdirectories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3261
     Raise an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3262
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3263
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3264
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3265
    "/ typically, an 'rm -rf' is faster and removes better;
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3266
    "/ 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
  3267
    "/ fallBack doing a manual directory walk.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3268
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3269
    ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory).
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3270
    ok ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3271
        self recursiveRemoveWithoutOSCommand
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3272
    ].
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3273
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3274
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3275
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3276
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3277
     ('foo' asFilename remove) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3278
        Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3279
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3280
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3281
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3282
     'foo' asFilename makeDirectory.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3283
     'foo/bar' asFilename writeStream close.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3284
     ('foo' asFilename recursiveRemove) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3285
        Transcript showCR:'could not remove foo'
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3286
     ]
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3287
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3288
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3289
    "Created: / 14.11.1995 / 11:19:29 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3290
    "Modified: / 5.5.1999 / 13:43:35 / cg"
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3291
!
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3292
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3293
recursiveRemoveAll
13247
9e47a0e73ba4 comment/format in: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13246
diff changeset
  3294
    "Remove all of my subfiles/subdirectories.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3295
     Raise an error if not successful.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  3296
     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
  3297
     command to do the remove."
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3298
4939
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  3299
    |files|
be88a6c986a6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4903
diff changeset
  3300
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  3301
    self isDirectory ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3302
        (files := self directoryContents) size > 0 ifTrue:[
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3303
            files do:[:aFilenameString |
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3304
                |f|
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3305
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3306
                f := self construct:aFilenameString.
10362
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3307
                Error handle:[:ex |
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3308
                    f isDirectory ifFalse:[ ex reject ].
15298
be543b10abba class: Filename
Claus Gittinger <cg@exept.de>
parents: 15296
diff changeset
  3309
13949
b82c0fc2b875 changed:
Claus Gittinger <cg@exept.de>
parents: 13877
diff changeset
  3310
                    f recursiveRemoveAll.
b82c0fc2b875 changed:
Claus Gittinger <cg@exept.de>
parents: 13877
diff changeset
  3311
                    f removeDirectory
10362
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3312
                ] do:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3313
                    f remove
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3314
                ].
10362
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3315
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3316
"/                f isDirectory ifTrue:[
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3317
"/                    f recursiveRemoveWithoutOSCommand
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3318
"/                ] ifFalse:[
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3319
"/                    f remove
ed621d39a311 when removing recursive, first try to remove entry as a file
Claus Gittinger <cg@exept.de>
parents: 10271
diff changeset
  3320
"/                ].
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3321
            ].
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3322
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3323
    ].
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3324
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3325
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3326
     'foo' asFilename makeDirectory.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3327
     'foo/bar' asFilename writeStream close.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3328
     'foo' asFilename remove
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3329
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3330
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3331
     'foo' asFilename makeDirectory.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3332
     'foo/bar' asFilename writeStream close.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3333
     'foo' asFilename recursiveRemove
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3334
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3335
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3336
    "Created: / 25-01-2011 / 16:42:15 / cg"
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3337
!
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3338
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3339
recursiveRemoveWithoutOSCommand
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3340
    "if I represent a regular file, remove it.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3341
     Otherwise, remove the directory and all of its subfiles/subdirectories.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3342
     Raise an error if not successful.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3343
     This one walks down the directory hierarchy, not using any OS
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3344
     command to do the remove."
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3345
15303
a8c170e68277 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15298
diff changeset
  3346
    self 
a8c170e68277 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15298
diff changeset
  3347
        recursiveRemoveAll;
a8c170e68277 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15298
diff changeset
  3348
        remove.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3349
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3350
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3351
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3352
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  3353
     'foo' asFilename remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3354
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3355
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3356
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3357
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  3358
     'foo' asFilename recursiveRemove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3359
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3360
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  3361
    "Created: / 25-02-1998 / 19:50:40 / cg"
13949
b82c0fc2b875 changed:
Claus Gittinger <cg@exept.de>
parents: 13877
diff changeset
  3362
    "Modified: / 19-01-2012 / 17:18:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3363
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3364
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3365
remove
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  3366
    "remove the file/directory.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3367
     Raises an exception if not successful.
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  3368
     Use #recursiveRemove in order to (recursively) remove non empty directories."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3369
8741
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  3370
    |linkInfo osName ok|
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  3371
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  3372
    osName := self osNameForFile.
13793
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3373
    (ok := OperatingSystem removeFile:osName) ifFalse:[
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3374
        linkInfo := self linkInfo.
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3375
        (linkInfo notNil and:[linkInfo isDirectory]) ifTrue:[
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3376
            ok := OperatingSystem removeDirectory:osName
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3377
        ].
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3378
        ok ifFalse:[
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3379
            self exists ifTrue:[
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3380
                self removeError:self
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3381
            ]
6392
f3c2c3edf2c8 do ask for existance (symbolic links)
Claus Gittinger <cg@exept.de>
parents: 6383
diff changeset
  3382
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3383
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3384
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3385
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3386
     (FileStream newFileNamed:'foo') close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3387
     'foo' asFilename remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3388
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3389
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3390
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3391
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3392
     'foo/bar' asFilename writeStream close.
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  3393
     'foo' asFilename remove.   'expect an exception'
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  3394
     'foo' asFilename recursiveRemove.   
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3395
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3396
13793
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3397
    "Modified: / 20-11-1997 / 17:40:22 / stefan"
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  3398
    "Modified: / 11-10-2011 / 10:20:01 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3399
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3400
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3401
removeDirectory
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3402
    "remove the directory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3403
     Raises an exception if not successful (or if its not a directory).
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  3404
     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
  3405
     Use #recursiveRemove in order to (recursively) remove non empty directories."
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3406
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3407
    |ok|
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3408
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3409
    ok := OperatingSystem removeDirectory:(self osNameForFile).
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3410
    ok ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3411
        self exists ifFalse:[ ^ self].
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3412
        self removeError:self
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3413
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3414
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3415
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3416
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3417
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3418
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3419
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3420
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3421
     'foo' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3422
     'foo' asFilename removeDirectory   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3423
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3424
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3425
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3426
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3427
     'foo/bar' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3428
     ('foo' asFilename remove) ifFalse:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3429
        Transcript showCR:'could not remove foo'
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3430
     ]
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3431
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3432
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3433
    "Modified: / 20.11.1997 / 17:40:22 / stefan"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3434
    "Modified: / 5.5.1999 / 13:41:12 / cg"
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3435
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3436
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3437
removeFile
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3438
    "remove the file.
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  3439
     Raises an exception if not successful (or if its not a file).
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  3440
     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
  3441
     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
  3442
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  3443
    (OperatingSystem removeFile:self osNameForFile) ifFalse:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  3444
        self exists ifTrue:[
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  3445
            self removeError:self
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  3446
        ].
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3447
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3448
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3449
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3450
     (FileStream newFileNamed:'foo') close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3451
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3452
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3453
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3454
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3455
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3456
     'foo' asFilename removeFile   
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3457
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3458
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  3459
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3460
renameTo:newNameArg
671
53de87163ad5 spelling
Claus Gittinger <cg@exept.de>
parents: 659
diff changeset
  3461
    "rename the file - the argument must be convertable to a String.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3462
     Raises an exception if not successful.
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3463
     If newName already exists, it will be replaced by myself."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3464
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3465
    |errno newName|
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3466
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3467
    newName := newNameArg asFilename.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3468
    (OperatingSystem 
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3469
        renameFile:(self osNameForFile) 
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3470
        to:(newName osNameForFile)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3471
    ) ifFalse:[
12318
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  3472
        errno := OperatingSystem lastErrorNumber.
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  3473
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3474
        self exists ifFalse:[
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3475
            ^ self fileNotFoundError:self
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3476
        ].
12956
f3924bb0cda0 changed:
Stefan Vogel <sv@exept.de>
parents: 12955
diff changeset
  3477
        (OperatingSystem errorHolderForNumber:errno) 
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3478
            parameter:newName;
12956
f3924bb0cda0 changed:
Stefan Vogel <sv@exept.de>
parents: 12955
diff changeset
  3479
            reportError.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3480
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3481
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3482
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3483
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3484
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3485
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3486
    "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
  3487
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3488
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3489
safeCopyTo:newNameArg
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3490
    "Copy the file's contents into another file.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3491
     Do it safe in an atomic operation shich makes sure that no partially written file appears.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3492
     The argument must be convertable to a filename.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3493
     Raises an exception, if an error occurs."
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3494
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3495
    |newName inStream accessRights tempStream|
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3496
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3497
    newName := newNameArg asFilename.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3498
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3499
    "Contents is not copied if newName represent same file as me."
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3500
    newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ].
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3501
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3502
    inStream := self readStream.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3503
    newName exists ifTrue:[
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3504
        accessRights := newName accessRights.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3505
    ] ifFalse:[
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3506
        accessRights := self accessRights.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3507
    ].
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3508
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3509
    [
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3510
        "let the temp filename start with a ~ to make it invisible"    
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3511
        tempStream := FileStream newTemporaryIn:newName directory osNameForFile nameTemplate:'~%1_%2'.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3512
        [
16676
0055047fdd76 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16648
diff changeset
  3513
            "would be nice to keep the access rights of the original file"    
15824
685e1bb32c31 class: Filename
ca
parents: 15823
diff changeset
  3514
            tempStream fileName accessRights:accessRights.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3515
        ] on:OperatingSystem accessDeniedErrorSignal do:[:ex|
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3516
            "ignore the error - may occure when copying to a network drive"
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3517
        ].            
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3518
16492
0d3a253fe98d class: Filename
Stefan Vogel <sv@exept.de>
parents: 16490
diff changeset
  3519
        inStream binary; buffered:false.
15846
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  3520
        tempStream binary; buffered:false.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3521
        [
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3522
            inStream copyToEndInto:tempStream.
15846
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  3523
        ] ifCurtailed:[
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  3524
            tempStream close.
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  3525
            tempStream fileName remove.
2095d1ca7368 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15824
diff changeset
  3526
            tempStream := nil.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3527
        ].
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3528
        tempStream syncData.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3529
    ] ensure:[
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3530
        inStream close.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  3531
        tempStream notNil ifTrue:[tempStream close].
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3532
    ].
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3533
    tempStream fileName renameTo:newName.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3534
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3535
    "
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3536
     'Make.proto' asFilename safeCopyTo:'/tmp/Makefile.foo'
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3537
     'Make.proto' asFilename safeCopyTo:'/'
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3538
     'smalltalk' asFilename safeCopyTo:'/xxxxxxxxxxxxxxxx/bla'
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3539
    "
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3540
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3541
    "Modified: / 10-09-2004 / 09:49:28 / janfrog"
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3542
    "Modified: / 29-09-2006 / 16:26:32 / cg"
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3543
!
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  3544
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3545
truncateTo:newSize
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3546
    "change the file's size.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3547
     This may not be supported on all operating systems
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3548
     (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
  3549
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  3550
    (OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  3551
        ^ 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
  3552
    ]
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3553
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3554
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3555
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3556
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3557
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3558
     s next:1000 put:$1.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3559
     s close.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  3560
     ('test' asFilename fileSize) printCR.
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3561
     'test' asFilename truncateTo:100.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  3562
     ('test' asFilename fileSize) printCR.
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  3563
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3564
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3565
    "Modified: / 5.5.1999 / 13:41:59 / cg"
615
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
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3568
!Filename methodsFor:'file queries'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3569
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3570
accessTime
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3571
    "return a timeStamp containing the file's last access time."
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3572
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3573
    | i |
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3574
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3575
    (i := self info) isNil ifTrue:[^ nil].
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3576
    ^ i accessTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3577
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3578
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3579
     Filename currentDirectory accessTime 
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3580
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3581
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3582
    "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
  3583
    "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
  3584
    "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
  3585
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3586
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3587
creationTime
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3588
    "return a timeStamp containing the file's creation time.
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3589
     NOTICE: only windoof distinguishes creation from modification;
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3590
     under unix, nil is returned (callers should fall back and use mod-time then"
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3591
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3592
    |i|
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3593
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3594
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3595
    ^ i creationTime
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3596
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3597
    "
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3598
     Filename currentDirectory creationTime 
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3599
    "
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3600
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3601
    "Created: / 9.7.1996 / 10:18:59 / cg"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3602
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3603
    "Modified: / 14.8.1998 / 17:42:50 / cg"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3604
!
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  3605
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3606
dates
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3607
    "return the file's modification and access times as an object (currently a dictionary)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3608
     that responds to the at: message with arguments 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3609
     #modified, #accessed or #statusChanged."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3610
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3611
    |info dates osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3612
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3613
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3614
    info := OperatingSystem infoOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3615
    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
  3616
        "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
  3617
         Answer the dates of the link itself"
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3618
        info := OperatingSystem linkInfoOf:osName.
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3619
        info isNil ifTrue:[
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3620
            ^ nil
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3621
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3622
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3623
    dates := IdentityDictionary new.
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3624
    dates at:#created put:(info creationTime).
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3625
    dates at:#modified put:(info modificationTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3626
    dates at:#accessed put:(info accessTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3627
    dates at:#statusChanged put:(info statusChangeTime).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3628
    ^ dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3629
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3630
    "
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  3631
     Filename currentDirectory dates  
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3632
     '../regression' asFilename dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3633
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3634
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3635
    "Modified: 1.11.1996 / 20:19:24 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3636
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3637
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3638
fileSize
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3639
    "return the size of the file in bytes"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3640
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3641
    |i|
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3642
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3643
    (i := self info) isNil ifTrue:[^ nil].
6794
498d85323172 use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents: 6793
diff changeset
  3644
    ^ i fileSize
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3645
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3646
    "Modified: / 17.8.1998 / 10:23:46 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3647
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3648
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3649
fileType
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3650
    "this returns a string describing the type of contents of
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3651
     the file. This is done using the unix 'file' command,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3652
     (which usually is configurable by /etc/magic).
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3653
     On non-unix systems, this may simply return 'file', 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3654
     not knowning about the contents.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3655
     Warning:
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3656
         Since the returned string differs among systems (and language settings),
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3657
         it is only useful for user-information; 
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3658
         NOT as a tag to be used by a program."
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3659
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3660
    |suffix baseNm info mime|
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3661
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3662
    "/ since we cannot depend on a 'file' command being available,
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3663
    "/ do the most obvious ones here. 
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3664
    "/ (also useful since the 'file' command takes some time, and the code
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3665
    "/  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
  3666
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3667
    info := self linkInfo.
9060
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  3668
    info isNil ifTrue:[
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  3669
        ^ 'removed'         "/ could happen, when coming from a snapshot image
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  3670
    ].
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  3671
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3672
    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
  3673
        ^ 'symbolic link to ' , info path
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3674
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3675
    info isDirectory ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3676
        self isReadable ifFalse:[^ 'directory, unreadable'].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3677
        self isExecutable ifFalse:[^ 'directory, locked'].
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3678
        ^ 'directory'
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  3679
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3680
    info isCharacterSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3681
        ^ 'character device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3682
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3683
    info isBlockSpecial ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3684
        ^ 'block device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3685
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3686
    info isSocket ifTrue:[
6245
90a9f29d8075 fileType & mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6227
diff changeset
  3687
        ^ 'socket'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3688
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3689
    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
  3690
        ^ 'fifo'
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3691
    ].
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3692
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  3693
    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
  3694
    info fileSize == 0 ifTrue:[^ 'empty'].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  3695
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  3696
    "/ suffix := self suffix asLowercase.
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  3697
    "/ baseNm := self withoutSuffix baseName asLowercase.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3698
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3699
    mime := self mimeTypeOfContents.
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3700
    mime notNil ifTrue:[
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3701
        "/ kludge to avoid making libview a prereq. of libbasic
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3702
        (Smalltalk at:#MIMETypes) notNil ifTrue:[
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3703
            info := (Smalltalk at:#MIMETypes) fileInfoForMimeType:mime.
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3704
            info notNil ifTrue:[^ info].
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  3705
        ].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  3706
    ].
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  3707
    ^ 'file'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3708
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3709
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3710
     'Makefile' asFilename fileType 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3711
     '.' asFilename fileType     
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3712
     '/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
  3713
     '/usr/tmp' asFilename fileType 
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3714
     '/tmp/.X11-unix/X0' asFilename fileType 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3715
     'smalltalk.rc' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3716
     'bitmaps/SBrowser.xbm' asFilename fileType    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3717
    "
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  3718
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  3719
    "Modified: / 21.7.1998 / 11:25:56 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3720
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3721
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3722
id
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3723
    "return the file's/directory's file-id (inode number)"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3724
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3725
    ^ OperatingSystem idOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3726
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3727
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3728
     Filename currentDirectory id 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3729
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3730
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3731
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3732
    "Created: 5.8.1997 / 19:26:01 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3733
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3734
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3735
info
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3736
    "return some object filled with the file's info;
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3737
     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
  3738
     the returned object) is:
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3739
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3740
         type  - a symbol giving the files fileType
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3741
         mode  - numeric access mode 
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3742
         uid   - owners user id
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3743
         gid   - owners group id
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3744
         size  - files size
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3745
         id    - files number (i.e. inode number)
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3746
         accessed      - last access time (as osTime-stamp)
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3747
         modified      - last modification time (as osTime-stamp)
16272
e795e4d67993 class: Filename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16255
diff changeset
  3748
         statusChangeTime - last staus change (as osTime-stamp)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3749
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3750
     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
  3751
     all of the information.
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3752
     The minimum returned info (i.e. on all OS's) will consist of at least:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3753
        modified
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3754
        size
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3755
        type
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3756
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3757
     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
  3758
     to either handle nil values,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3759
     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
  3760
     (i.e. instead of:
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3761
        someFilename type == #directory
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3762
      use
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  3763
        someFilename isDirectory
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3764
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3765
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3766
    ^ OperatingSystem infoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3767
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3768
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3769
     Filename currentDirectory info
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3770
     '/dev/null' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3771
     '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
  3772
     '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
  3773
     '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
  3774
     '../../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
  3775
     '.' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3776
     '..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3777
     '..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3778
     '..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3779
     '..\..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  3780
     'c:\' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3781
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  3782
16272
e795e4d67993 class: Filename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16255
diff changeset
  3783
    "Modified: / 17-08-1998 / 10:24:10 / cg"
e795e4d67993 class: Filename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16255
diff changeset
  3784
    "Modified (comment): / 21-03-2014 / 00:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3785
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3786
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3787
linkInfo
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3788
    "return the file's info. If it is a symbolic link return the info of the link itself
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  3789
     instead of the link's target.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3790
     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
  3791
     receiver represents a symbolic link, the links information 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3792
     is returned 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3793
     (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
  3794
      which is accessed via the symbolic link).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3795
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3796
     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
  3797
         path -> the target files pathname
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3798
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3799
     See the comment in #info for more details."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3800
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3801
    ^ OperatingSystem linkInfoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3802
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3803
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3804
     Filename currentDirectory linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3805
     '/dev/null' asFilename linkInfo    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3806
     'Make.proto' asFilename linkInfo   
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  3807
     'Make.proto' asFilename linkInfo path  
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3808
     'source/Point.st' asFilename linkInfo 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3809
     '../../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
  3810
     '/usr/tmp' asFilename linkInfo 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3811
    "
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  3812
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  3813
    "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
  3814
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3815
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3816
modificationTime
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  3817
    "return a timeStamp containing the file's modification time."
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3818
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3819
    |i|
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3820
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3821
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  3822
    ^ i modificationTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3823
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3824
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3825
     Filename currentDirectory modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3826
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  3827
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3828
    "Created: / 9.7.1996 / 10:18:59 / cg"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3829
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  3830
    "Modified: / 14.8.1998 / 17:42:50 / cg"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3831
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3832
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3833
type
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3834
    "return the symbolic type of the file"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3835
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3836
    ^ OperatingSystem typeOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3837
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3838
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3839
     Filename currentDirectory type 
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3840
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3841
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3842
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  3843
    "Created: 5.8.1997 / 19:31:26 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3844
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3845
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3846
!Filename methodsFor:'file utilities'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3847
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3848
edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3849
    "start an editView on the file represented by the receiver"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3850
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3851
    EditTextView openOn:self asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3852
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3853
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3854
     'smalltalk.rc' asFilename edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3855
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3856
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3857
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3858
fileIn
13424
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  3859
    "load source code from the file"
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  3860
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  3861
    ^ (ProgrammingLanguage forFile: self) fileIn: self
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  3862
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  3863
    "Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>"
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  3864
! !
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  3865
2
claus
parents: 1
diff changeset
  3866
!Filename methodsFor:'instance creation'!
claus
parents: 1
diff changeset
  3867
10969
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3868
/ subname
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3869
    "Same as construct: Taking the receiver as a directory name, construct a new
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3870
     filename for an entry within this directory 
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3871
     (i.e. for a file or a subdirectory in that directory).
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3872
     The argument may not specify an absolute path name.
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3873
     Please do not use this to create filenames with suffixes,
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3874
     since some systems require special naming conventions.
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3875
     See also: #withSuffix: (which is different, but often needed).
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3876
     Thanks to Jan Vrany for this idea."
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3877
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3878
    ^ self construct:subname
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3879
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3880
    "
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3881
     '/tmp' asFilename / 'foo'    
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3882
     '/' asFilename / 'foo' / 'bar' / 'baz'        
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3883
     '/foo/bar' asFilename / ('baz' asFilename) 
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3884
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3885
     Bad example; works on UNIX, but may not on others:
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3886
       'foo/bar.baz' / '.suff'
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3887
    "
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3888
!
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  3889
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3890
construct:subname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3891
    "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
  3892
     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
  3893
     (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
  3894
     The argument may not specify an absolute path name.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3895
     Please do not use this to create filenames with suffixes,
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3896
     since some systems require special naming conventions.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3897
     See also: #withSuffix: (which is different, but often needed)."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3898
11784
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  3899
    |constructedName|
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  3900
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  3901
    constructedName := self constructString:subname.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  3902
    ^ self species named:constructedName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3903
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3904
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3905
     '/tmp' asFilename construct:'foo'    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3906
     '/' asFilename construct:'foo'         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3907
     '/usr/tmp' asFilename construct:'foo'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3908
     '/foo/bar' asFilename construct:'baz' 
6670
7792348f31e7 Comments
Stefan Vogel <sv@exept.de>
parents: 6662
diff changeset
  3909
     '/foo/bar' asFilename construct:'baz' asFilename 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3910
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3911
     Bad example; works on UNIX, but may not on others:
11784
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  3912
       'foo/bar.baz' asFilename construct:'.suff'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3913
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3914
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  3915
    "Modified: 29.2.1996 / 20:55:06 / cg"
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3916
!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3917
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3918
constructDirectory:subname
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3919
    "same as #construct: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3920
     (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
  3921
     
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  3922
    ^ self species named:(self constructDirectoryString:subname)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3923
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3924
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3925
constructDirectoryString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3926
    "same as #constructString: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3927
     (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
  3928
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3929
    ^ self constructString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3930
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3931
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3932
constructString:subName
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3933
    "taking the receiver as a directory name, construct a new
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3934
     filename-string for an entry within this directory 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3935
     (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
  3936
     The argument may not specify an absolute path name.
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3937
     The code below works for UNIX & MSDOS; 
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3938
     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
  3939
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3940
    |sepString sub|
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3941
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3942
    sub := subName asString.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  3943
    sepString := self species separatorString.
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  3944
    nameString size == 0 ifTrue:[
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  3945
        ^ sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3946
    ].
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3947
    (nameString endsWith:sepString) ifTrue:[
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  3948
        ^ nameString , sub
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  3949
    ].
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  3950
    ^ nameString , sepString , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3951
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3952
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3953
     '/tmp' asFilename constructString:'foo'   
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3954
     '/' asFilename constructString:'foo'         
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3955
     '/usr/tmp' asFilename constructString:'foo'
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3956
     '/foo/bar' asFilename constructString:'baz' 
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  3957
     '' asFilename constructString:'baz' 
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3958
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  3959
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3960
    "Modified: / 7.9.1995 / 10:15:22 / claus"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3961
    "Created: / 9.9.1997 / 08:57:08 / cg"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3962
    "Modified: / 20.1.1998 / 15:58:23 / md"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  3963
    "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
  3964
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3965
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3966
filenameFor:fileName
6973
c46e1d005ea4 comment
Claus Gittinger <cg@exept.de>
parents: 6943
diff changeset
  3967
    "return a filename representing the argument, fileName
c46e1d005ea4 comment
Claus Gittinger <cg@exept.de>
parents: 6943
diff changeset
  3968
     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
  3969
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3970
    |f|
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3971
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3972
    f := fileName asFilename.
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3973
    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
  3974
    ^ (self construct:fileName)
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3975
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3976
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3977
     '/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
  3978
     '/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
  3979
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3980
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  3981
    "Created: 18.9.1997 / 14:34:14 / stefan"
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3982
!
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3983
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3984
secureConstruct:subname
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3985
    "taking the receiver as a directory name, construct a new
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3986
     filename for an entry within this directory 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3987
     (i.e. for a file or a subdirectory in that directory).
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3988
     The argument may not specify an absolute path name.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3989
     Please do not use this to create filenames with suffixes,
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3990
     since some systems require special naming conventions.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3991
     See also: #withSuffix: (which is different, but often needed).
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3992
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3993
     This method differs from #construct:, by not permitting subName
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3994
     to navigate above (via ..) the current filename."
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3995
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  3996
    ^ self species named:(self secureConstructString:subname)
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3997
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3998
    "
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  3999
     '/tmp' asFilename secureConstruct:'foo'    
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4000
     '/tmp' asFilename secureConstruct:'../foo'    
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4001
     '/tmp' asFilename secureConstruct:'/./foo'    
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4002
     '/tmp' asFilename secureConstruct:'foo/../bar'    
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4003
     '/' asFilename secureConstruct:'foo'         
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4004
     '/usr/tmp' asFilename secureConstruct:'foo'
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4005
     '/foo/bar' asFilename secureConstruct:'baz' 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4006
     '/foo/bar' asFilename secureConstruct:'baz' asFilename 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4007
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4008
     Bad example; works on UNIX, but may not on others:
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4009
       'foo/bar.baz' secureConstruct:'.suff'
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4010
    "
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4011
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4012
    "Modified: 29.2.1996 / 20:55:06 / cg"
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4013
!
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4014
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4015
secureConstructString:subName
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4016
    "taking the receiver as a directory name, construct a new
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4017
     filename-string for an entry within this directory 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4018
     (i.e. for a file or a subdirectory in that directory).
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4019
    
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4020
     This method differs from #constructString, by not permitting subName
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4021
     to navigate above (via ..) the current filename.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4022
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4023
     The code below works for UNIX & MSDOS; 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4024
     other filename classes (i.e. VMS) may want to redefine this method."
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4025
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4026
    |sepString sub normalizedPath pathStream|
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4027
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4028
    sepString := self species separatorString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4029
    sub := subName asString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4030
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4031
    sub := sub asCollectionOfSubstringsSeparatedByAll:sepString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4032
    normalizedPath := OrderedCollection new:sub size.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4033
    sub do:[:eachPathComponent|
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4034
        eachPathComponent = '..' ifTrue:[
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4035
            normalizedPath isEmpty ifTrue:[
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4036
                self error:'secureConstruct: - trying to escape from: ', nameString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4037
            ].
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4038
            normalizedPath removeLast.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4039
        ] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4040
            normalizedPath add:eachPathComponent.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4041
        ]]
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4042
    ].
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  4043
    pathStream := CharacterWriteStream with:nameString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4044
    (nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4045
        pathStream nextPutAll:sepString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4046
    ].
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4047
    normalizedPath do:[:eachPathComponent|
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4048
        pathStream nextPutAll:eachPathComponent.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4049
    ] separatedBy:[
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4050
        pathStream nextPutAll:sepString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4051
    ].
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4052
        
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4053
    ^ pathStream contents.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4054
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4055
    "
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  4056
     '/tmp' asFilename secureConstructString:'fooÅ '   
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4057
     '/tmp' asFilename secureConstructString:'../foo'   
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4058
     '/tmp' asFilename secureConstructString:'foo/../bla'   
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4059
     '/tmp' asFilename secureConstructString:'foo/./bla'   
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4060
     '/tmp' asFilename secureConstructString:'/bla/foo/../../foo'   
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4061
     '/' asFilename secureConstructString:'foo'         
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4062
     '/usr/tmp' asFilename secureConstructString:'foo'
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4063
     '/foo/bar' asFilename secureConstructString:'baz' 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4064
     '' asFilename secureConstructString:'baz' 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4065
     '' asFilename secureConstructString:'/baz' 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4066
    "
2
claus
parents: 1
diff changeset
  4067
! !
claus
parents: 1
diff changeset
  4068
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4069
!Filename methodsFor:'misc'!
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4070
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4071
, aString
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4072
    "this allows filenames to understand how names are concatenated.
14072
b9389ad3cf2c comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13949
diff changeset
  4073
     Returns a string consisting of the receiver's name, concatenated
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4074
     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
  4075
     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
  4076
     See also: #withSuffix: which is new and better."
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4077
5866
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  4078
    <resource:#obsolete>
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  4079
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4080
    self obsoleteMethodWarning:'use #construct:'.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  4081
    ^ (nameString , aString asString)
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4082
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4083
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4084
     'Makefile' asFilename , '.bak'        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4085
     ('Makefile' asFilename , '.bak') asFilename  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4086
     'Makefile' asFilename withSuffix:'bak' 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4087
     'Makefile' asFilename construct:'.bak'     
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4088
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4089
14072
b9389ad3cf2c comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13949
diff changeset
  4090
    "Modified: / 07-09-1997 / 23:45:36 / cg"
b9389ad3cf2c comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13949
diff changeset
  4091
    "Modified (comment): / 01-04-2012 / 13:18:21 / cg"
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4092
!
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4093
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4094
canonicalize
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4095
    "normalize a filename by removing all empty path components or dots,
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4096
     and by resolving parent directory '..' references.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4097
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4098
     The code below works for UNIX & MSDOS; 
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4099
     other filename classes (i.e. VMS) may want to redefine this method."
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4100
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4101
    nameString := self species canonicalize:nameString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4102
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4103
    "
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4104
        '/tmp/bla' asFilename canonicalize.    
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4105
        '/tmp/bla/../fasel' asFilename canonicalize.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4106
        '/tmp/bla/.././/fasel' asFilename canonicalize.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4107
        '..' asFilename canonicalize.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4108
        'bla/../fasel' asFilename canonicalize.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4109
        '//bla/../fasel' asFilename canonicalize.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4110
    "
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4111
! !
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4112
14232
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4113
!Filename methodsFor:'os shell'!
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4114
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4115
openExplorer
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4116
    "open a file-explorer on the directory represented by the receiver.
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4117
     On non-windows systems, an error is raised"
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4118
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4119
    OperatingSystem isMSWINDOWSlike ifFalse:[
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4120
        self warn:'sorry - this operation is only available under windows'.
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4121
    ].
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4122
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4123
    OperatingSystem
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4124
        openApplicationForDocument:self pathName 
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4125
        operation:#explore.
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4126
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4127
    "Created: / 21-07-2012 / 12:28:18 / cg"
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4128
!
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4129
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4130
openFinder
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4131
    "open a finder on the directory represented by the receiver.
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4132
     On non-osx systems, an error is raised"
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4133
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4134
    OperatingSystem isOSXlike ifFalse:[
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4135
        self warn:'sorry - this operation is only available under osx'.
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4136
    ].
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4137
16547
4e02208be705 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16545
diff changeset
  4138
    OperatingSystem executeCommand:'open "',self pathName,'"' 
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4139
!
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4140
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4141
openTerminal
16545
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4142
    "open a terminal window on the directory represented by the receiver;
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4143
     on osx, a terminal app is opened,
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4144
     on windows a cmd.exe window,
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4145
     on unix, an xterm is opened."
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4146
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4147
    OperatingSystem isOSXlike ifTrue:[
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4148
        "/ I dont know yet how to tell the terminal to
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4149
        "/ go to a particular directory.
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4150
        "/ therefore, use the built in terminal
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4151
        VT100TerminalView openShellIn:self pathName.
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4152
        ^ self.
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4153
    ].
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4154
14941
0793160108eb class: Filename
Claus Gittinger <cg@exept.de>
parents: 14932
diff changeset
  4155
    [
16545
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4156
        |cmd|
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4157
14941
0793160108eb class: Filename
Claus Gittinger <cg@exept.de>
parents: 14932
diff changeset
  4158
        OperatingSystem isOSXlike ifTrue:[
16545
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4159
            cmd := '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ' 
14941
0793160108eb class: Filename
Claus Gittinger <cg@exept.de>
parents: 14932
diff changeset
  4160
        ] ifFalse:[
16545
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4161
            OperatingSystem isMSWINDOWSlike ifTrue:[
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4162
                cmd := 'c:\windows\System32\cmd.exe'        
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4163
            ] ifFalse:[
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4164
                "/ VT100TerminalView openShellIn:self pathName
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4165
                cmd := 'xterm' 
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4166
            ]
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4167
        ].
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4168
        OperatingSystem 
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4169
            executeCommand:cmd
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4170
            inDirectory:self pathName. 
14941
0793160108eb class: Filename
Claus Gittinger <cg@exept.de>
parents: 14932
diff changeset
  4171
    ] fork
14232
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4172
! !
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4173
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4174
!Filename methodsFor:'printing & storing'!
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4175
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4176
printOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  4177
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  4178
     The format is suitable for a human - not meant to be read back."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4179
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4180
    aStream nextPutAll:(self class name).
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4181
    aStream nextPutAll:'('''.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4182
    nameString printOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4183
    aStream nextPutAll:''')'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4184
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4185
    "Modified: 7.9.1997 / 23:46:20 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4186
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4187
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4188
storeOn:aStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4189
    "append a printed representation of the receiver to aStream,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4190
     which allows reconstructing it via readFrom:"
328
claus
parents: 326
diff changeset
  4191
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4192
    aStream nextPut:$(.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4193
    nameString storeOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4194
    aStream nextPutAll:' asFilename)'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4195
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4196
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7236
diff changeset
  4197
!Filename methodsFor:'private-accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4198
6227
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  4199
getName
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  4200
    "get the raw filename"
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  4201
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  4202
    ^ nameString 
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  4203
!
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  4204
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4205
setName:aString
38
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  4206
    "set the filename"
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  4207
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  4208
    nameString := aString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  4209
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  4210
    "Modified: / 21.7.1998 / 10:44:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4211
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4212
2
claus
parents: 1
diff changeset
  4213
!Filename methodsFor:'queries'!
claus
parents: 1
diff changeset
  4214
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4215
exists
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4216
    "return true, if such a file exists."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4217
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4218
    ^ OperatingSystem isValidPath:(self osNameForAccess)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  4219
85
claus
parents: 77
diff changeset
  4220
    "
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4221
     '/foo/bar' asFilename exists 
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4222
     '/tmp' asFilename exists  
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  4223
     'Makefile' asFilename exists   
85
claus
parents: 77
diff changeset
  4224
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  4225
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  4226
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4227
filenamesMatching:aPattern
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4228
    "VW compatibility"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4229
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4230
    ^ (self filesMatching:aPattern)
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4231
            collect:[:eachName | self construct:eachName].
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4232
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4233
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4234
     '/etc' asFilename filenamesMatching:'a*;c*' 
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4235
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4236
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4237
    "Created: / 15.4.1997 / 15:40:02 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4238
    "Modified: / 3.8.1998 / 21:22:15 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4239
!
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  4240
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4241
filesMatching:aPattern
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4242
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4243
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4244
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4245
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4246
15737
6977fd775e72 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15574
diff changeset
  4247
    |matchers caseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4248
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4249
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4250
    caseSensitive := self species isCaseSensitive.
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4251
    ^ self directoryContents
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  4252
        select:[:name | 
15737
6977fd775e72 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15574
diff changeset
  4253
                (matchers detect:[:p | p match:name caseSensitive:caseSensitive] ifNone:0) ~~ 0
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  4254
               ]
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4255
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4256
    "
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4257
     '/etc' asFilename filesMatching:'a*;c*' 
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4258
    "
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4259
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  4260
    "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
  4261
    "Modified: / 3.8.1998 / 21:22:15 / cg"
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4262
!
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4263
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4264
filesMatchingWithoutDotDirs:aPattern
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4265
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4266
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4267
     Exclude '.' and '..' from the returned list.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4268
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4269
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4270
15737
6977fd775e72 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15574
diff changeset
  4271
    |matchers caseSensitive|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4272
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4273
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4274
    caseSensitive := self species isCaseSensitive.
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  4275
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4276
    ^ self directoryContents 
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  4277
        select:[:name | 
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  4278
                name ~= '.'
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  4279
                and:[name ~= '..'
15737
6977fd775e72 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15574
diff changeset
  4280
                and:[(matchers detect:[:p | p match:name caseSensitive:caseSensitive] ifNone:0) ~~ 0]]
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4281
      ]
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4282
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4283
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4284
     Filename currentDirectory filesMatching:'M*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4285
     '/etc' asFilename filesMatching:'[a-z]*' 
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4286
     '../../libbasic' asFilename filesMatching:'[A-D]*.st'  
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4287
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  4288
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  4289
    "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
  4290
    "Modified: / 3.8.1998 / 21:22:30 / cg"
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4291
!
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  4292
9206
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  4293
fullAlternativePathName
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  4294
    ^ nameString
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  4295
!
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  4296
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4297
isExecutable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4298
    "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
  4299
     For directories, true is returned if the directory can be entered.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4300
     See isExecutableProgram for a related check."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4301
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4302
    ^ OperatingSystem isExecutable:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4303
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4304
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4305
     '/foo/bar' asFilename isExecutable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4306
     '/tmp' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4307
     'Makefile' asFilename isExecutable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4308
     '/bin/ls' asFilename isExecutable   
356
claus
parents: 328
diff changeset
  4309
    "
claus
parents: 328
diff changeset
  4310
!
claus
parents: 328
diff changeset
  4311
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4312
isExecutableProgram
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4313
    "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
  4314
     (i.e. for directories, false is returned.)"
356
claus
parents: 328
diff changeset
  4315
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4316
    |osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4317
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4318
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4319
    ^ (OperatingSystem isExecutable:osName)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4320
      and:[(OperatingSystem isDirectory:osName) not]
356
claus
parents: 328
diff changeset
  4321
claus
parents: 328
diff changeset
  4322
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4323
     '/tmp' asFilename isExecutable         
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4324
     '/bin/ls' asFilename isExecutable       
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4325
     '/tmp' asFilename isExecutableProgram   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4326
     '/bin/ls' asFilename isExecutableProgram    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4327
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4328
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4329
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4330
isHidden
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4331
    "return true, if the receiver represents a hidden file.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4332
     The definitions of hidden files depends on the OS used;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4333
     on UNIX, a name starting with a period is considered hidden;
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4334
     on MSDOS, the file's hidden attribute is also used.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4335
     VMS has no concept of hidden files."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4336
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4337
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4338
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4339
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4340
isMountPoint:aPathName
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4341
    "return true, if I represent a mount-point.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4342
     Warning: 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4343
        the receiver must be an absolute pathname, 
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4344
        because a realPath is not used/generated for the query (to avoid automounting).
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4345
        Aka: do not ask: '../../' asFilename isMountPoint;
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4346
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4347
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4348
    self isAbsolute ifFalse:[
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4349
        self error:'this query must be done on an absolute pathname'.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4350
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4351
    ^ OperatingSystem isMountPoint:(self name)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4352
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4353
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4354
isReadable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4355
    "return true, if such a file exists and is readable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4356
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4357
    ^ OperatingSystem isReadable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4358
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4359
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4360
     '/foo/bar' asFilename isReadable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4361
     '/tmp' asFilename isReadable      
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4362
     'Makefile' asFilename isReadable   
328
claus
parents: 326
diff changeset
  4363
    "
claus
parents: 326
diff changeset
  4364
!
claus
parents: 326
diff changeset
  4365
11529
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4366
isSharedLibrary
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4367
    "return true, if such a file exists and is a shared library."
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4368
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4369
    ObjectFileLoader isNil ifTrue:[
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4370
        "we cannot handle shared libraries, so there are no shared libraries"
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4371
        ^ false.
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4372
    ].
14932
6c3cb9809126 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14804
diff changeset
  4373
    ^ (ObjectFileLoader validBinaryExtensions includes:self suffix) 
6c3cb9809126 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14804
diff changeset
  4374
        and:[self isRegularFile].
11529
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4375
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4376
    "
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4377
     'libstx_libbasic.so' asFilename isSharedLibrary         
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4378
     'libstx_libbasic.dll' asFilename isSharedLibrary         
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4379
     '/tmp' asFilename isSharedLibrary         
14932
6c3cb9809126 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14804
diff changeset
  4380
     '/tmp.dll' asFilename isSharedLibrary         
11529
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4381
    "
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4382
!
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  4383
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4384
isWritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4385
    "return true, if such a file exists and is writable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4386
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4387
    ^ OperatingSystem isWritable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4388
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4389
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4390
     '/foo/bar' asFilename isWritable 
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4391
     '/tmp' asFilename isWritable   
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4392
     'Makefile' asFilename isWritable   
328
claus
parents: 326
diff changeset
  4393
    "
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4394
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4395
15574
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4396
isWritableDirectory
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4397
    "return true, if such a directory exists and is writable.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4398
     Don't believe #isWritable, since on an NFS mounted filesystem
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4399
     with UID mapping and attribute cache enabled, there may be false negatives."
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4400
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4401
    self isDirectory ifFalse:[
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4402
        ^ false.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4403
    ].
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4404
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4405
    self isWritable ifFalse:[
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4406
        "/ on an NFS mounted filesystem with UID mapping and
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4407
        "/ attribute cache enabled,
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4408
        "/ this query may fail, but creation may work actually. 
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4409
        "/ check again...
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4410
        [
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4411
            |tempFile|
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4412
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4413
            tempFile := FileStream newTemporaryIn:self.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4414
            tempFile close.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4415
            tempFile fileName remove.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4416
        ] on:OpenError do:[:ex|
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4417
            ^ false.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4418
        ].
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4419
    ].
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4420
    ^ true.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4421
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4422
    "
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4423
     '/foo/bar' asFilename isWritableDirectory 
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4424
     '/tmp' asFilename isWritableDirectory   
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4425
     '/etc' asFilename isWritableDirectory   
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4426
     'Makefile' asFilename isWritableDirectory
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4427
     '/net/exeptn/home2/office' asFilename isWritable
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4428
     '/net/exeptn/home2/office' asFilename isWritableDirectory
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4429
    "
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4430
!
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  4431
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4432
separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4433
    "return the directory-separator character"
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4434
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4435
    ^ self species separator
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4436
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4437
    "Modified: 29.2.1996 / 20:52:01 / cg"
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4438
!
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4439
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  4440
species
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4441
    "create only new instances of the concrete OS specific class.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4442
     Redefined in AutoDeletedFilename, to not create AutoDeleted instances
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4443
     per default (from directories etc.)"
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4444
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4445
    self == Filename ifTrue:[
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4446
        ^ ConcreteClass.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4447
    ] ifFalse:[
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4448
        ^ self class.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4449
    ].
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  4450
!
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  4451
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4452
withSpecialExpansions
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4453
    "return a new filename, expanding any OS specific macros. 
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4454
     Here, a ~/ prefix is expanded to the users home dir (as in bash)"
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4455
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4456
    |newName|
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4457
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4458
    newName := self species nameWithSpecialExpansions:nameString.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4459
    newName = nameString ifTrue:[
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4460
        ^ self.
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4461
    ].
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4462
    ^ self species named:newName.
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4463
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4464
    "
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4465
     '~' asFilename withSpecialExpansions       
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4466
     '~/Desktop' asFilename withSpecialExpansions  
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4467
     '~stefan' asFilename withSpecialExpansions     
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4468
     '~stefan/Desktop' asFilename withSpecialExpansions
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  4469
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4470
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4471
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4472
!Filename methodsFor:'queries-contents'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4473
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4474
mimeTypeFromName
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4475
    "return the mimeType as guessed from the file's name/and or extension.
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4476
     This could be less accurate than mimeTypeOfContents, but avoids
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4477
     reading the file (is therefore much faster).
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4478
     Also it works with non-existing files.
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4479
     Returns nil for directories and other non-regular files."
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4480
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4481
    |mimeTypes|
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4482
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4483
    "/ kludge to avoid making libview a prereq. of libbasic
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4484
    (mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4485
        ^ mimeTypes mimeTypeForFilename:(self name)
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4486
    ].
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4487
    ^ nil
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4488
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4489
    "
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4490
     'Makefile' asFilename mimeTypeFromName     
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4491
     '.' asFilename mimeTypeFromName            
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4492
     '/dev/null' asFilename mimeTypeFromName   
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4493
     '/tmp/.X11-unix/X0' asFilename mimeTypeFromName  
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4494
     'smalltalk.rc' asFilename mimeTypeFromName     
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4495
     'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName    
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4496
     '../../rules/stmkmf' asFilename mimeTypeFromName  
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  4497
     '/bläh' asFilename mimeTypeFromName               
10902
c640c9325439 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10850
diff changeset
  4498
     '/x.zip' asFilename mimeTypeFromName               
c640c9325439 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10850
diff changeset
  4499
     '/x.gz' asFilename mimeTypeFromName               
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4500
    "
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4501
!
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  4502
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4503
mimeTypeOfContents
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4504
    "this tries to guess the mime type of contents of
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4505
     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
  4506
     or the contents is unknown.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4507
     This is done using some heuristics, and may need some improvement"
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4508
17111
748d567580b5 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17048
diff changeset
  4509
    |type buffer s size mimeTypes|
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4510
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4511
    type := self type.
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4512
    type isNil ifTrue:[ ^ nil ].
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4513
    type == #directory ifTrue:[ ^ nil ].                                                              
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4514
    type == #characterSpecial ifTrue:[ ^ nil ].
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4515
    type == #blockSpecial ifTrue:[ ^ nil ].
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4516
    type == #socket ifTrue:[ ^ nil ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4517
    self fileSize == 0 ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4518
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4519
    s := self readStreamOrNil.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4520
    s isNil ifTrue:[^ nil].
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4521
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4522
    "/ read some data from the file ...
7685
535a69a7cd69 String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents: 7680
diff changeset
  4523
    buffer := String new:2048.
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4524
6943
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  4525
    s errorSignal handle:[:ex |
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  4526
        size := 0.
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  4527
    ] do:[
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  4528
        size := s nextBytes:buffer size into:buffer.
910f4b17c342 care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents: 6908
diff changeset
  4529
    ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4530
    s close.
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4531
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4532
    "/ kludge to avoid making libview a prereq. of libbasic
17111
748d567580b5 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17048
diff changeset
  4533
    (mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4534
        ^ mimeTypes mimeTypeOfData:buffer suffix:self suffix.
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4535
    ].
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4536
    ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4537
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4538
    "
6753
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  4539
     'Makefile' asFilename mimeTypeOfContents     
1a4a541850f2 add search for unprintable characters on mimeTypeContents
penk
parents: 6729
diff changeset
  4540
     '.' asFilename mimeTypeOfContents            
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4541
     '/dev/null' asFilename mimeTypeOfContents  
10153
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  4542
     '/tmp/.X11-unix/X0' asFilename mimeTypeOfContents   
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4543
     'smalltalk.rc' asFilename mimeTypeOfContents      
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  4544
     'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents    
10153
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  4545
     '../../rules/stmkmf' asFilename mimeTypeOfContents 
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  4546
     '/bläh' asFilename mimeTypeOfContents              
10153
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  4547
     'C:\Dokumente und Einstellungen\cg\Favoriten\languages.lnk' asFilename mimeTypeOfContents
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  4548
     'G:\A\A01.TOP' asFilename mimeTypeOfContents       
10153
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  4549
    "
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  4550
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  4551
    "Modified: / 06-11-2006 / 11:44:58 / cg"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4552
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4553
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4554
!Filename methodsFor:'queries-path & name'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4555
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4556
baseName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4557
    "return my baseName as a string.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4558
     - thats the file/directory name without leading parent-dirs.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4559
     (i.e. '/usr/lib/st/file' asFilename baseName -> 'file'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4560
       and '/usr/lib'         asFilename baseName -> lib).
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  4561
     This method does not check if the path is valid.
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  4562
     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
  4563
     for VMS (and maybe others as well).
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4564
     See also: #pathName, #directoryName and #directoryPathName.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4565
     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
  4566
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4567
    |len index sep endIdx|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4568
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4569
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4570
    len := nameString size.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4571
    ((len == 1) and:[(nameString at:1) == sep]) ifTrue:[
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  4572
        ^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4573
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4574
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4575
    endIdx := len.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4576
    len > 1 ifTrue:[
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  4577
        (nameString at:len) == sep ifTrue:[endIdx := endIdx - 1].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4578
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4579
    index := nameString lastIndexOf:sep startingAt:len-1.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4580
    ^ 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
  4581
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4582
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4583
     '/foo/bar' asFilename baseName  
4903
1487c740eaba comment
Claus Gittinger <cg@exept.de>
parents: 4901
diff changeset
  4584
     '/foo/bar.cc' asFilename baseName  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4585
     '.' asFilename baseName          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4586
     '..' asFilename baseName         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4587
     '../..' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4588
     '../../libbasic' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4589
     '../../libpr' asFilename baseName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4590
     '../../libbasic/Object.st' asFilename baseName        
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  4591
     '/' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  4592
     '\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  4593
     'c:\' asFilename baseName        
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  4594
     '\\idefix' asFilename baseName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4595
    "
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4596
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  4597
    "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
  4598
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4599
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4600
directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4601
    "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
  4602
     - 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
  4603
       the receiver is contained in.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4604
     (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
  4605
      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
  4606
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4607
    ^ self species named:(self directoryName)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4608
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4609
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4610
     '/foo/bar' asFilename directory      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4611
     '/foo/bar' asFilename directoryName  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4612
     '/foo/bar' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4613
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4614
     '.' asFilename directory        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4615
     '..' asFilename directory       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4616
     '../..' asFilename directory     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4617
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4618
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4619
    "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
  4620
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4621
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4622
directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4623
    "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
  4624
     - 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
  4625
       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
  4626
     This method does not check if the path is valid.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4627
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4628
     (i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4629
       and '/usr/lib' asFilename directoryName         -> /usr').
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4630
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4631
     (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
  4632
      a string instead of a Filename instance).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4633
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4634
     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
  4635
     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
  4636
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4637
    |index sep sepString p rest parentDirectoryString|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4638
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4639
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4640
    sepString := sep asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4641
    (nameString = sepString) ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4642
        "/
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4643
        "/ the trivial '/' case
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4644
        "/
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4645
        ^ sepString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4646
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4647
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4648
    "/
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  4649
    "/ strip off multiple trailing slashes
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4650
    "/
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4651
    p := nameString.
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4652
    [p endsWith:sep] whileTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4653
        (p = sepString) ifTrue:[
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4654
            ^ sepString
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4655
        ].
15163
7862c37d3947 Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 15121
diff changeset
  4656
        p := p copyButLast:1
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4657
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4658
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4659
    parentDirectoryString := self class parentDirectoryName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4660
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  4661
    "/ strip off trailing components
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  4662
    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
  4663
    index == 0 ifTrue:[
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4664
        "/ no separator found
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4665
        p = '.' ifTrue:[
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4666
            ^ parentDirectoryString
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4667
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4668
        p = '..' ifTrue:[
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4669
            ^ parentDirectoryString, sepString, parentDirectoryString
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4670
        ].
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4671
        ^ '.'
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4672
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  4673
    rest := p copyFrom:(index+1).
7342
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  4674
    (rest = '.') ifTrue:[
7519
0cfe202e7e3e #directoryName returned a Filename
Stefan Vogel <sv@exept.de>
parents: 7473
diff changeset
  4675
        ^ p copyTo:index-1.
7342
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  4676
    ].
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4677
    (rest = parentDirectoryString) ifTrue:[
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4678
        ^ (self species 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
  4679
    ].
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  4680
    index == 1 ifTrue:[
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4681
        ^ sepString
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  4682
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  4683
    ^ p copyTo:(index - 1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4684
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4685
    "
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  4686
     '/home' asFilename directoryName          
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4687
     '/foo/bar/' asFilename directoryName    
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  4688
     '/foo/bar/' asFilename directory      
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4689
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4690
     '/foo/bar' asFilename directoryName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4691
     'bitmaps' asFilename directoryName        
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4692
     'bitmaps' asFilename directoryPathName        
6402
23ddc6a6573e directoryName - care for trailing /..
Claus Gittinger <cg@exept.de>
parents: 6392
diff changeset
  4693
     '.' asFilename directoryName           
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  4694
     '.' asFilename directoryPathName        
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4695
     '..' asFilename directoryName       
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  4696
     '..' asFilename directoryPathName       
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4697
     '../..' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4698
     '../..' asFilename directoryPathName     
7343
Claus Gittinger <cg@exept.de>
parents: 7342
diff changeset
  4699
     '/foo/bar/baz/..' asFilename directoryName     
Claus Gittinger <cg@exept.de>
parents: 7342
diff changeset
  4700
     '/foo/bar/baz/.' asFilename directoryName     
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4701
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4702
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  4703
    "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
  4704
    "Modified: / 21.10.1998 / 22:52:25 / cg"
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  4705
    "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
  4706
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4707
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4708
directoryPathName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4709
    "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
  4710
     - 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
  4711
       the receiver is contained in.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4712
     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
  4713
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4714
    ^ (self species named:self pathName) directoryName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4715
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4716
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4717
     '/foo/bar/' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4718
     '/foo/bar' asFilename directoryPathName    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4719
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4720
     '.' asFilename directoryPathName      
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4721
     '.' asFilename directoryName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4722
     '.' asFilename directory          
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4723
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4724
     '..' asFilename directoryPathName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4725
     '..' asFilename directoryName       
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4726
     '..' asFilename directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4727
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4728
     '../..' asFilename directoryPathName     
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4729
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4730
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4731
    "Modified: 7.9.1995 / 10:42:13 / claus"
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  4732
    "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
  4733
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4734
14567
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  4735
encodedNameString
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  4736
    "answer the name as passed to OS system calls"
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  4737
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  4738
    ^ OperatingSystem encodePath:nameString
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  4739
!
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  4740
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4741
filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4742
    "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
  4743
     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
  4744
     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
  4745
       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
  4746
       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
  4747
       match.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4748
     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
  4749
     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
  4750
     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
  4751
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4752
    ^ self filenameCompletionIn:nil
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4753
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4754
    " 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4755
     'mak' asFilename filenameCompletion  
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4756
     'Make' asFilename filenameCompletion  
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4757
     'Makef' asFilename filenameCompletion;yourself  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4758
     '/u' asFilename filenameCompletion             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4759
     '../../libpr' asFilename inspect filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4760
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4761
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  4762
    "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
  4763
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4764
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4765
filenameCompletionIn:aDirectory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4766
    "try to complete the receiver filename.
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4767
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4768
     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
  4769
     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
  4770
       it returns a collection of matching filename objects,
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4771
       and changes the receiver's filename-string to the longest common match.
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4772
     If none matches, the returned collection is empty and the receiver is unchanged.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4773
     If there is only one match, the size of the returned collection is exactly 1,
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4774
     containing the fully expanded filename and the receiver's name is changed to it.
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4775
     An empty baseName pattern (i.e. giving the name of a directory) will also return an empty matchset."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4776
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4777
    |mySpecies 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
  4778
     sepString parentString prefix nMatch nm caseless lcBaseName|
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  4779
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4780
    mySpecies := self species.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4781
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4782
    caseless := mySpecies isCaseSensitive not.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4783
    matching := OrderedCollection new.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4784
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4785
    nm := mySpecies nameWithSpecialExpansions:nameString.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4786
    nm := mySpecies canonicalize:nm.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4787
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4788
    sepString := mySpecies separatorString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  4789
    (nm endsWith:sepString) ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4790
        "/ two exceptions here: 
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4791
        "/   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
  4792
        "/   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
  4793
        self isDirectory ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4794
            |first longest|
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4795
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4796
            first := nil.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4797
            OpenError catch:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4798
                self directoryContentsDo:[:fileName |
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4799
                    ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4800
                        matching add:fileName.    
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4801
                        first isNil ifTrue:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4802
                            first := longest := fileName.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4803
                        ] ifFalse:[
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4804
                            "/ more than one file
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4805
                            longest := longest commonPrefixWith:fileName ignoreCase:caseless.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4806
                            longest isEmpty ifTrue:[ 
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4807
                                ^ #() 
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4808
                            ].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4809
                        ]
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4810
                    ]
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  4811
                ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4812
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4813
            longest notNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4814
                nameString := (self constructString:longest).
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4815
                 ^ matching
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4816
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4817
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4818
        ^ #()
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4819
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4820
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4821
    parentString := mySpecies parentDirectoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4822
    baseName := self baseName.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  4823
    baseName ~= nm ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4824
        prefix := self directoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4825
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4826
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4827
    self isAbsolute ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4828
        dir := self directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4829
    ] ifFalse:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4830
        aDirectory isNil ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4831
            dir := self directory
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4832
        ] ifFalse:[
10793
0475c364e80a care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents: 10780
diff changeset
  4833
            dir := (aDirectory asFilename construct:nm) directory
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4834
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4835
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4836
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  4837
    caseless ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4838
        lcBaseName := baseName asLowercase
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  4839
    ].
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  4840
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4841
    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
  4842
        ^ #().
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  4843
    ] do:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4844
        dir directoryContents do:[:fileName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4845
            ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4846
                ((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
  4847
                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
  4848
                    matching add:fileName
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4849
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4850
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4851
        ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4852
    ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4853
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4854
    (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
  4855
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4856
         find the longest common prefix
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4857
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4858
        matchLen := baseName size.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4859
        matchLen > matching first size ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4860
            try := baseName.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4861
            allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4862
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4863
            try := matching first copyTo:matchLen.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4864
            allMatching := true.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4865
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4866
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4867
        [allMatching] whileTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4868
            matching do:[:aName |
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4869
                ((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
  4870
                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
  4871
                    allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4872
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4873
            ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4874
            allMatching ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4875
                matchLen <  matching first size ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4876
                    matchLen := matchLen + 1.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4877
                    try := matching first copyTo:matchLen.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4878
                ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4879
                    allMatching := false
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4880
                ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4881
            ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4882
                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
  4883
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4884
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4885
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4886
         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
  4887
        "
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4888
        nameString := nm := try
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4889
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4890
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4891
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4892
     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
  4893
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4894
    prefix notNil ifTrue:[
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4895
        (prefix endsWith:sepString) ifTrue:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4896
            "/ avoid introducing double slashes
15163
7862c37d3947 Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 15121
diff changeset
  4897
            prefix := prefix copyButLast:(sepString size).
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4898
        ].
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4899
        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
  4900
        nMatch == 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4901
            nameString := nm := matching first
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4902
        ] ifFalse:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4903
            nMatch > 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4904
                nameString := nm := prefix , sepString , nm
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4905
            ]
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4906
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4907
    ] ifFalse:[
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4908
        nMatch == 1 ifTrue:[
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4909
            nameString := nm := matching first
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  4910
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4911
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4912
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
     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
  4915
     (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
  4916
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4917
    ^ matching
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
    " trivial cases:
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4920
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4921
     '../' asFilename filenameCompletion     -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4922
     '/' asFilename filenameCompletion       -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4923
     '/usr/' asFilename filenameCompletion   -> empty
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4924
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4925
     'mak' asFilename filenameCompletion   
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4926
     'Make' asFilename filenameCompletion    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4927
     'Makef' asFilename filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4928
     '/u' asFilename filenameCompletion             
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4929
     '../../libpr' asFilename filenameCompletion
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  4930
     '/etc/mail/auth/xx' asFilename filenameCompletion
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4931
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4932
     'c:\pr' asFilename filenameCompletion             -> matching names
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4933
     'c:\pr' asFilename filenameCompletion; yourself   -> side effect: name changed to longest match
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4934
     'c:\p' asFilename filenameCompletion 
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4935
     'c:\' asFilename filenameCompletion  -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4936
     'c:' asFilename filenameCompletion   -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  4937
     '\' asFilename filenameCompletion    -> empty
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4938
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4939
10793
0475c364e80a care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents: 10780
diff changeset
  4940
    "Modified: / 22-09-1997 / 18:03:33 / stefan"
0475c364e80a care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents: 10780
diff changeset
  4941
    "Modified: / 17-11-2007 / 14:31:08 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  4942
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  4943
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4944
head 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4945
    "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
  4946
     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
  4947
     (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
  4948
      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
  4949
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4950
    ^ self directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4951
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4952
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4953
     Filename currentDirectory head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4954
     'Makefile' asFilename head    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4955
     '/foo/bar/baz.st' asFilename head  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4956
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4957
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4958
    "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
  4959
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4960
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4961
isAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4962
    "return true, if the receiver represents an absolute pathname
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4963
     (in contrast to one relative to the current directory)."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4964
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4965
    ((nameString startsWith:self species separator) or:[nameString startsWith:'~']) ifTrue:[^ true].
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4966
    ^ self isVolumeAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4967
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4968
    "
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  4969
     '/foo/bar' asFilename isAbsolute 
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  4970
     '~/bla' asFilename isAbsolute
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4971
     '..' asFilename isAbsolute         
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4972
     '..' asAbsoluteFilename isAbsolute         
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4973
     'source/SBrowser.st' asFilename isAbsolute  
12437
704dc2f7a1d0 comment/format in: #isAbsolute
Claus Gittinger <cg@exept.de>
parents: 12388
diff changeset
  4974
     'source/SBrowser.st' asFilename isRelative  
704dc2f7a1d0 comment/format in: #isAbsolute
Claus Gittinger <cg@exept.de>
parents: 12388
diff changeset
  4975
     'SBrowser.st' asFilename isRelative    
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4976
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4977
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4978
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4979
isExplicitRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4980
    "return true, if this name is an explicit relative name
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4981
     (i.e. starts with './' or '../', to avoid path-prepending)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4982
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4983
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4984
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4985
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4986
isImplicit
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4987
    "return true, if the receiver represents a builtin file.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4988
     The definitions of builtin files depends on the OS used;
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4989
     on UNIX, '.' and '..' are builtin names."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4990
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4991
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4992
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4993
    "Created: 18.9.1997 / 18:04:51 / stefan"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4994
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  4995
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  4996
isParentDirectoryOf:aFilenameOrString
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4997
    "Answer true, if myself is a parent directory of aFilenameOrString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4998
     Unexpected results may be returned, if one of myself or aFilenameOrString does
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  4999
     not exist and relative and absolute path names are mixed 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5000
     ('/' asFilename isParentDirectoryOf:'../noExistant' -> false) 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5001
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5002
     Warning: maybe symbolic links must be resolved which could lead to automounting"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5003
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5004
    |filenameArg otherNames myNames myName|
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5005
7236
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  5006
    filenameArg := aFilenameOrString asFilename.
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5007
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5008
    "first do a simple comparison"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5009
    otherNames := self class canonicalizedNameComponents:filenameArg name.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5010
    myNames := self class canonicalizedNameComponents:self name.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5011
    ((otherNames startsWith:myNames) and:[myNames first ~= self class parentDirectoryName]) ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5012
        ^ otherNames ~= myNames
7236
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  5013
    ].
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5014
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5015
    "fall back - try it again with ~ substitution and symbolic links resolved"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5016
    otherNames := self class canonicalizedNameComponents:filenameArg pathName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5017
    myNames := self class canonicalizedNameComponents:self pathName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5018
    (otherNames startsWith:myNames) ifTrue:[
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5019
        ^ otherNames ~= myNames
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5020
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5021
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5022
    myName := self class nameFromComponents:myNames.
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5023
    filenameArg allParentDirectoriesDo:[:parent |
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5024
        parent pathName = myName ifTrue:[^ true].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5025
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5026
    ^ false.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5027
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5028
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5029
     '/etc' asFilename isParentDirectoryOf:'/etc/passwd' 
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5030
     'etc' asFilename isParentDirectoryOf:'etc/passwd' 
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5031
     '/etc' asFilename isParentDirectoryOf:'/etc/'   
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5032
     '/etc' asFilename isParentDirectoryOf:'/etc'   
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5033
     '/et' asFilename isParentDirectoryOf:'/etc'   
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5034
     '/home' asFilename isParentDirectoryOf:Filename currentDirectory 
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5035
     '~' asFilename isParentDirectoryOf:Filename currentDirectory 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5036
     '~' asFilename isParentDirectoryOf:'.' 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5037
     '~' asFilename isParentDirectoryOf:'..' 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5038
     '~' asFilename isParentDirectoryOf:'../smalltalk' 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5039
     '../..' asFilename isParentDirectoryOf:'../nonExistant' 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5040
     '..' asFilename isParentDirectoryOf:'../../nonExistant' 
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5041
     '/' asFilename isParentDirectoryOf:'../nonExistant' 
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5042
     '/' asFilename isParentDirectoryOf:'/phys/qnx'      
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5043
    "       
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5044
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5045
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5046
isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5047
    "return true, if this name is interpreted relative to some
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5048
     directory (opposite of absolute)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5049
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5050
    ^ self isAbsolute not
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5051
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5052
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5053
     './foo/bar' asFilename isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5054
     '../../foo/bar' asFilename isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5055
     '/foo/bar' asFilename isRelative     
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5056
     'bar' asFilename isRelative          
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5057
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5058
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5059
    "Modified: 16.1.1997 / 01:19:14 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5060
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5061
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5062
isRootDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5063
    "return true, if I represent the root directory 
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5064
     (i.e. I have no parentDir)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5065
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5066
    "/ mhmh - should we use:
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5067
    "/
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5068
    "/ parentDir := self construct:'..'.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5069
    "/ (parentDir exists
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5070
    "/ and:[parentDir isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5071
    "/ and:[parentDir id ~= self id]]) ifTrue:[
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5072
    "/    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5073
    "/ ].
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5074
    "/ ^ true
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5075
    "/
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5076
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5077
    ^ self pathName = Filename rootDirectory pathName
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5078
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5079
    "Modified: 23.10.1997 / 00:38:35 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5080
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5081
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5082
isVolumeAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5083
    "return true, if the receiver represents an absolute pathname
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5084
     on some disk volume (MSDOS only)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5085
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5086
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5087
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5088
    "Modified: 7.9.1997 / 23:54:33 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5089
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5090
2987
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5091
localPathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5092
    "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
  5093
     but without any volume information.
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5094
     Only makes a difference on MSDOS & VMS systems."
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5095
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5096
    ^ self pathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5097
!
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  5098
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5099
name
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5100
    "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
  5101
     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
  5102
     See also: pathName"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5103
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5104
"/    self isAbsolute ifTrue:[^ self pathName].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5105
    ^ nameString
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5106
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5107
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5108
     '/foo/bar' asFilename name        
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5109
     '/foo/bar' asFilename pathName    
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5110
     '.' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5111
     '.' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5112
     '../..' asFilename name             
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5113
     '../..' asFilename pathName 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5114
     'bitmaps' asFilename name                
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5115
     'bitmaps' asFilename pathName             
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5116
     '/tmp/../usr' asFilename name       
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5117
     '/tmp/../usr' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5118
     'source/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5119
     'source/..' asFilename pathName    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5120
     '/tmp/..' asFilename name    
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5121
     '/tmp/..' asFilename pathName    
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  5122
    "
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5123
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  5124
    "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
  5125
!
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5126
7308
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5127
nameString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5128
    "raw access to nameString - req'd for xml-store/reload"
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5129
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5130
    ^ nameString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5131
!
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5132
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5133
nameString:aString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5134
    "raw access to nameString - req'd for xml-store/reload"
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5135
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5136
    nameString := aString
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5137
!
fd2026414339 *** empty log message ***
martin
parents: 7307
diff changeset
  5138
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5139
pathName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5140
    "return the full pathname of the file represented by the receiver,
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5141
     as a string. This will not include ..'s. 
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5142
     If the path represented by the receiver does NOT represent a valid path,
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5143
     no compression will be done (for now; this may change).
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5144
     See also: name"
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5145
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  5146
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5147
"/    sep := self class separator.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5148
"/    (nameString startsWith:sep) ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5149
"/        parentName := self class parentDirectoryName.
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5150
"/        (nameString findString:parentName) == 0 ifTrue:[
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5151
"/            ^ nameString
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5152
"/        ]
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5153
"/    ].
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5154
    ^ OperatingSystem pathNameOf:(self species nameWithSpecialExpansions:nameString).
2
claus
parents: 1
diff changeset
  5155
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  5156
    "
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5157
     '/foo/bar' asFilename pathName  
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5158
     '.' asFilename pathName         
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5159
     '../..' asFilename pathName     
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5160
     '../..' asFilename name           
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5161
     '/tmp/../usr' asFilename pathName   
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5162
     '/././usr' asFilename pathName     
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5163
     '~/..' asFilename pathName     
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  5164
    "
159
514c749165c3 *** empty log message ***
claus
parents: 132
diff changeset
  5165
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  5166
    "Modified: 27.4.1996 / 18:19:52 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5167
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5168
11658
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5169
physicalFilename
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5170
    "return the fileName representing the physical file as represented by the receiver,
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5171
     If the receiver represents a symbolic link, thats the fileName of the
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5172
     final target. Otherwise, its the receivers pathName itself.
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5173
     If any file along the symbolic path does not exist (i.e. is a broken link),
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5174
     nil is returned."
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5175
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5176
    |pathOrNil|
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5177
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5178
    pathOrNil := self physicalPathName.
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5179
    pathOrNil isNil ifTrue:[
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5180
        ^ nil
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5181
    ].
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5182
    ^ pathOrNil asFilename
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5183
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5184
    "
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5185
     '/foo/bar' asFilename physicalFileName  
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5186
    "
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5187
!
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  5188
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5189
physicalPathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5190
    "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
  5191
     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
  5192
     final target. Otherwise, its the receivers pathName itself.
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5193
     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
  5194
     nil is returned."
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5195
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5196
    |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
  5197
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5198
    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
  5199
    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
  5200
        " 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
  5201
        ^ nil.
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5202
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5203
    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
  5204
        ^ 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
  5205
    ].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5206
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5207
    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
  5208
    [
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5209
        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
  5210
        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
  5211
            "/ 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
  5212
            ^ nil
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5213
        ].
11657
96890b622c6a changed #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 11529
diff changeset
  5214
        path asFilename isAbsolute ifTrue:[
96890b622c6a changed #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 11529
diff changeset
  5215
            t := path asFilename
96890b622c6a changed #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 11529
diff changeset
  5216
        ] ifFalse:[
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5217
            t := (self species named:t directoryName) construct:path.
11657
96890b622c6a changed #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 11529
diff changeset
  5218
        ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5219
        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
  5220
        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
  5221
            "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
  5222
             ^ nil
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5223
        ].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  5224
    ] 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
  5225
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5226
    ^ t pathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5227
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5228
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5229
     '/foo/bar' asFilename physicalPathName  
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5230
     '.' asFilename physicalPathName         
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5231
     '../..' 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
  5232
     '/usr/tmp' asFilename physicalPathName           
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5233
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5234
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5235
    "Modified: 21.12.1996 / 15:29:50 / cg"
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5236
!
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  5237
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5238
tail
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  5239
    "the file's name without directory prefix as a string. 
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5240
     An alias for baseName, for ST-80 compatiblity."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5241
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5242
    ^ self baseName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5243
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5244
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5245
     Filename currentDirectory tail 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5246
     'Makefile' asFilename tail    
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5247
     '/foo/bar/baz.st' asFilename tail  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5248
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5249
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5250
    "Modified: 29.2.1996 / 20:19:50 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  5251
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  5252
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5253
tail:nComponents
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5254
    "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
  5255
     - 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
  5256
     (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
  5257
       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
  5258
     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
  5259
     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
  5260
     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
  5261
     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
  5262
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5263
    |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
  5264
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5265
    sep := self species separator.
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5266
    components := self components.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5267
    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
  5268
    start < 1 ifTrue:[
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5269
        start := 1.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5270
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5271
    start = 1 ifTrue:[
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5272
        tail := ''
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5273
    ] ifFalse:[
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5274
        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
  5275
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5276
    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
  5277
        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
  5278
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5279
    ^ tail.    
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5280
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5281
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5282
    "
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5283
     '/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
  5284
     '/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
  5285
     '/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
  5286
     '/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
  5287
     '.' asFilename tail:3          
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5288
     '..' asFilename tail:3         
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5289
     '../..' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5290
     '../../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
  5291
     '../../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
  5292
     '../../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
  5293
     '../../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
  5294
     '/' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5295
     '\' asFilename tail:2        
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5296
     '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
  5297
     '\\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
  5298
    "
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5299
!
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  5300
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  5301
volume
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  5302
    "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
  5303
     This is only used with MSDOS and VMS filenames 
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5304
     - by default (and on unix), an empty string is returned"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5305
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  5306
    ^ ''
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5307
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5308
    "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
  5309
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5310
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5311
!Filename methodsFor:'queries-type'!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5312
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5313
isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5314
    "return true, if the receiver represents an existing,
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5315
     readable directories pathname."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5316
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5317
    ^ OperatingSystem isDirectory:(self osNameForAccess)
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5318
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5319
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5320
     '/foo/bar' asFilename isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5321
     '/tmp' asFilename isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5322
     'Makefile' asFilename isDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5323
     'c:\' asFilename isDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5324
     'd:\' asFilename isDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5325
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5326
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5327
    "Modified: / 21.9.1998 / 15:53:10 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5328
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5329
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5330
isNonEmptyDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5331
    "return true, if the receiver represents an existing,
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5332
     readable directories pathname, and the directory is not empty."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5333
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  5334
    FileStream openErrorSignal
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  5335
        handle:[:ex| ]
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  5336
        do:[
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  5337
            self directoryContentsDo:[:pathString|^ true].
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5338
        ].
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5339
    ^ false.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5340
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5341
    "
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  5342
     '/foo/bar' asFilename isNonEmptyDirectory 
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5343
     '/tmp' asFilename isNonEmptyDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5344
     '/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5345
     '/tmp/empty' asFilename removeDirectory.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5346
     'Makefile' asFilename isNonEmptyDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5347
     'c:\' asFilename isNonEmptyDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5348
     'd:\' asFilename isNonEmptyDirectory   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5349
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5350
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5351
    "Modified: / 21.9.1998 / 15:53:10 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5352
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5353
8836
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5354
isRegularFile
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5355
    "return true, if the receiver represents a plain, regular file"
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5356
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5357
    ^ self type == #regular
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5358
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5359
    "
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5360
     '/foo/bar' asFilename isRegularFile
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5361
     '/tmp' asFilename isRegularFile
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5362
     'Makefile' asFilename isRegularFile   
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5363
     'c:\' asFilename isRegularFile   
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5364
     'd:\' asFilename isRegularFile   
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5365
     '/dev/null' asFilename isRegularFile   
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5366
    "
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5367
!
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  5368
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5369
isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5370
    "return true, if the receiver represents a socket, named pipe, fifo
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5371
     or device special file (i.e. anything non regular and non-directory)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5372
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5373
    |t|
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5374
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5375
    t := self type.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5376
    ^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]])
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5377
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5378
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5379
     '/foo/bar' asFilename isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5380
     '/tmp' asFilename isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5381
     'Makefile' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5382
     'c:\' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5383
     'd:\' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5384
     '/dev/null' asFilename isSpecialFile   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5385
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5386
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5387
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5388
isSymbolicLink
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5389
    "return true, if the file represented by the receiver is a symbolic
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5390
     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
  5391
     not will always return false."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5392
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5393
    ^ OperatingSystem isSymbolicLink:(self osNameForFile)
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5394
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5395
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5396
     'Make.proto' asFilename isSymbolicLink  
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5397
     'Makefile' asFilename isSymbolicLink   
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5398
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5399
! !
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5400
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5401
!Filename methodsFor:'reading-directories'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5402
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5403
directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5404
    "return the contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5405
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5406
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5407
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5408
     So users of this method better test for existing directory before.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5409
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5410
        this returns the file-names as strings; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5411
        see also #directoryContentsAsFilenames, which returns fileName instances."
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5412
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5413
    |directoryStream contents|
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5414
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5415
    contents := OrderedCollection new.
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5416
    directoryStream := DirectoryStream directoryNamed:(self osNameForDirectoryContents).
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5417
    directoryStream isNil ifTrue:[^ nil].
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5418
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5419
    [
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5420
        [directoryStream atEnd] whileFalse:[  
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5421
            |entry|
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5422
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5423
            entry := directoryStream nextLine.
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5424
            (entry notNil and:[entry ~= '.' and:[entry ~= '..']]) ifTrue:[
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5425
                contents add:entry
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5426
            ].
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5427
        ].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5428
    ] ensure:[
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5429
        directoryStream close
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5430
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5431
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5432
    ^ contents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5433
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5434
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5435
     '.' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5436
     '/XXXdoesNotExist' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5437
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5438
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5439
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5440
    "Modified: / 3.8.1998 / 21:36:21 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5441
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5442
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5443
directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5444
    "return the contents of the directory as a collection of filenames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5445
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5446
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5447
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5448
     So users of this method better test for existing directory before.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5449
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5450
        this returns the file-names as fileName instances; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5451
        see also #directoryContents, which returns strings."
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5452
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5453
    |names|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5454
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5455
    names := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5456
    names isNil ifTrue:[^ nil].
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5457
    ^ names collect:[:entry | self construct:entry].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5458
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5459
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5460
     '.' asFilename directoryContentsAsFilenames   
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5461
     '/XXXdoesNotExist' asFilename directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5462
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5463
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5464
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5465
fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5466
    "return the full contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5467
     This is much like #directoryContents, but includes an entry for the
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5468
     parent directory, if there is one.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5469
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5470
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5471
     So users of this method better test for existing directory before."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5472
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5473
    |files|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5474
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5475
    "here we get the files without '.' and '..'"
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5476
    files := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5477
    files isNil ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5478
        "/ mhmh - that one does not exist
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5479
        ^ files
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5480
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5481
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5482
    files addFirst:'..'.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5483
    ^ files
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5484
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5485
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5486
     '.' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5487
     '/XXXdoesNotExist' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5488
     'd:\FET' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5489
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5490
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5491
    "Modified: / 21.9.1998 / 15:33:07 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5492
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5493
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5494
recursiveDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5495
    "return the contents of the directory and all subdirectories
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5496
     as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5497
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5498
     Subdirectory files are included with a relative pathname.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5499
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5500
        this returns the file-names as strings; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5501
        see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5502
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5503
     Warning: this may take a long time to execute."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5504
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5505
    |fileNames dirNames|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5506
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5507
    fileNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5508
    dirNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5509
    self directoryContents do:[:f |
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5510
        (self construct:f) isDirectory ifTrue:[
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5511
            dirNames add:f
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5512
        ] ifFalse:[
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5513
            fileNames add:f
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5514
        ]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5515
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5516
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5517
    dirNames do:[:dN |
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5518
        |dd subFiles|
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5519
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5520
        dd := dN asFilename.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5521
        subFiles := (self construct:dN) recursiveDirectoryContents.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5522
        fileNames addAll:(subFiles collect:[:f | dd constructString:f])
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5523
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5524
    ^ fileNames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5525
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5526
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5527
     '.' asFilename recursiveDirectoryContents 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5528
     '../../clients' asFilename recursiveDirectoryContents 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5529
    "
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5530
!
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5531
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5532
recursiveDirectoryContentsAsFilenames
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5533
    "return the contents of the directory and all subdirectories
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5534
     as a collection of filenames.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5535
     This excludes any entries for '.' or '..'.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5536
     Returns nil for non-existing directories; however, this behavior
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5537
     may be changed in the near future, to raise an exception instead.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5538
     So users of this method better test for existing directory before.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5539
     Notice: 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5540
        this returns the file-names as fileName instances; 
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5541
        see also #recursiveDirectoryContents, which returns strings.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5542
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5543
     Warning: this may take a long time to execute."
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5544
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5545
    |names|
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5546
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5547
    names := self recursiveDirectoryContents.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5548
    names isNil ifTrue:[^ nil].
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  5549
    ^ names collect:[:entry | self construct:entry].
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5550
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5551
    "
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5552
     '.' asFilename recursiveDirectoryContentsAsFilenames   
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5553
     '/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  5554
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5555
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5556
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5557
!Filename methodsFor:'reading-files'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5558
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5559
binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5560
    "return the binary contents of the file (as a byteArray);
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  5561
     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
  5562
    
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  5563
    ^ self 
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5564
        readingFileDo:[:s | 
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5565
            |nBytes bytes n result|
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5566
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5567
            s binary.
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5568
            nBytes := self fileSize.
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5569
            (nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5570
                bytes := ByteArray uninitializedNew:nBytes.
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5571
                n := s nextBytes:nBytes into:bytes startingAt:1.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5572
                n == nBytes ifTrue:[
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5573
                    result := bytes
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5574
                ] ifFalse:[
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5575
                    result := bytes copyTo:n
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5576
                ]
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5577
            ] ifFalse:[
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5578
                result := s contentsOfEntireFile
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5579
            ].
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5580
            result
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5581
        ]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5582
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5583
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5584
     'Makefile' asFilename binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5585
     'foobar' asFilename binaryContentsOfEntireFile   
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5586
    "
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5587
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  5588
    "Modified: / 27-10-2012 / 19:42:07 / cg"
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5589
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5590
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5591
contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5592
    "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
  5593
     Raises an error, if the file is unreadable/non-existing.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5594
     See also #contentsOfEntireFile, which returns a string for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5595
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5596
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5597
    ^ self readingFileDo:[:s | s contents].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5598
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5599
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5600
     'Makefile' asFilename contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5601
     'foobar' asFilename contents            
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5602
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5603
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5604
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5605
    "Created: / 11.7.1996 / 14:09:11 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5606
    "Modified: / 15.10.1998 / 11:41:45 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5607
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5608
10780
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5609
contentsAsString
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5610
    "to compensate for the bad naming, use this to make things explicit.
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5611
     See also #contents, which returns the lines as stringCollection for textFiles."
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5612
11397
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  5613
    ^ self contentsOfEntireFile
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  5614
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  5615
    "
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  5616
     'Makefile' asFilename contentsAsString
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  5617
     'foobar' asFilename contentsAsString
10780
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5618
    "
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5619
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5620
    "Modified: / 02-07-1996 / 12:49:45 / stefan"
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5621
    "Created: / 08-11-2007 / 13:29:59 / cg"
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5622
!
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  5623
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5624
contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5625
    "return the contents of the file as a string;
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  5626
     Raises an error, if the file is unreadable/non-existing.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5627
     See also #contents, which returns the lines as stringCollection for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5628
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5629
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  5630
    ^ self readingFileDo:[:s | s contentsOfEntireFile].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5631
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5632
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5633
     'Makefile' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5634
     'foobar' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5635
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5636
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5637
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5638
    "Modified: / 15.10.1998 / 11:42:05 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5639
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5640
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5641
readingFileDo:aBlock
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5642
    "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
  5643
     and return the blocks value. 
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  5644
     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
  5645
     (old behavior, will vanish:)the block is evaluated with a nil argument.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5646
     Ensures that the stream is closed."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5647
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5648
    |stream result|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5649
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5650
    stream := self readStream.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5651
    [
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5652
        result := aBlock value:stream
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5653
    ] ensure:[
14628
d6bf1fd719f6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14567
diff changeset
  5654
        stream notNil ifTrue:[stream close]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5655
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5656
    ^ result
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5657
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5658
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5659
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5660
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5661
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5662
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5663
     rslt := 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5664
        '/etc/passwd' asFilename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5665
            readingFileDo:[:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5666
                s nextLine
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5667
            ]. 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5668
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5669
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5670
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5671
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5672
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5673
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5674
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5675
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5676
     rslt :=
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5677
        '/etc/passwd' asFilename 
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5678
            readingFileDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5679
                [:s |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5680
                    |shells|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5681
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5682
                    shells := Bag new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5683
                    s linesDo:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5684
                        [:line |
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5685
                            |parts|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5686
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5687
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5688
                            shells add:(parts seventh).
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5689
                        ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5690
                    shells contents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5691
                ].           
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5692
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5693
    "
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5694
!
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5695
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5696
readingLinesDo:aBlock
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5697
    "create a read-stream on the receiver file,
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5698
     evaluate aBlock for each line read from the stream.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5699
     If the file cannot be opened, an error is raised.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5700
     Ensures that the stream is closed."
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5701
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5702
    self readingFileDo:[:stream |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5703
        stream linesDo:aBlock
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5704
    ].
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5705
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5706
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5707
    '/etc/passwd' asFilename 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5708
        readingLinesDo:[:eachLine |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5709
            Transcript showCR:eachLine.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5710
        ]. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5711
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5712
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5713
    "
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5714
    '/etc/xxxxx' asFilename 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5715
        readingLinesDo:[:eachLine |
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5716
            Transcript showCR:eachLine.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5717
        ]. 
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  5718
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5719
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  5720
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5721
!Filename methodsFor:'special accessing'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5722
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5723
osName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5724
    "special - return the OS's name for the receiver."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5725
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5726
    self isDirectory ifTrue:[
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5727
        ^ self osNameForDirectory
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5728
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5729
    ^ self osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5730
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5731
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  5732
osNameForAccess
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  5733
    "internal - return the OS's name for the receiver to
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  5734
     access its fileInfo.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  5735
     This may be redefined for systems, where a special suffix must be
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  5736
     added in order to access directories (or others) as a file.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  5737
     (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
  5738
7064
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
  5739
    ^ self osNameForFile
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  5740
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  5741
    "Modified: / 21.7.1998 / 10:40:40 / cg"
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  5742
!
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  5743
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5744
osNameForDirectory
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  5745
    "internal - return the OS's name for the receiver to
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5746
     access it as a directory."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5747
14218
c87235c8bc2b changed:
Stefan Vogel <sv@exept.de>
parents: 14072
diff changeset
  5748
    ^ self osNameForFile
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  5749
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  5750
    "Modified: / 12.8.1998 / 14:44:32 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5751
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5752
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  5753
osNameForDirectoryContents
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  5754
    "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
  5755
     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
  5756
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  5757
    ^ self osNameForDirectory
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  5758
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  5759
    "Created: / 3.8.1998 / 21:36:06 / cg"
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  5760
    "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
  5761
!
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  5762
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5763
osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5764
    "internal - return the OS's name for the receiver to
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5765
     access it as a file."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5766
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5767
    (nameString startsWith:'~') ifFalse:[
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5768
        ^ nameString.
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5769
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5770
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5771
    ^ self species nameWithSpecialExpansions:nameString. 
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5772
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5773
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5774
!Filename methodsFor:'suffixes'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5775
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5776
addSuffix:aSuffix
14306
f41ca29d9b54 comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 14232
diff changeset
  5777
    "return a new filename for the receivers name with a additional suffix.
f41ca29d9b54 comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 14232
diff changeset
  5778
     The new suffix is simply appended to the name, 
f41ca29d9b54 comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 14232
diff changeset
  5779
     regardless whether there is already an existing suffix.
f41ca29d9b54 comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 14232
diff changeset
  5780
     See also #withSuffix:"
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5781
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5782
    |prefixName|
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5783
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5784
    prefixName := self name.
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5785
    aSuffix isEmptyOrNil ifTrue:[
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5786
        ^ self species named:prefixName
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5787
    ].
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5788
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5789
    ^ self species named:
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5790
        (prefixName 
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5791
         , self species suffixSeparator asString 
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5792
         , aSuffix asString)
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5793
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5794
    "
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5795
     'abc.st' asFilename addSuffix:nil         
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5796
     'a.b.c' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5797
     '.b.c.' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5798
     '.b.c' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5799
     '.c.' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5800
     '.c' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5801
     'c.' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5802
     '.' asFilename addSuffix:nil            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5803
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5804
     'abc.st' asFilename addSuffix:'o'         
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5805
     'abc' asFilename addSuffix:'o'             
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5806
     'a.b.c' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5807
     'a.b.c.' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5808
     '.b.c.' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5809
     '.c.' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5810
     '.c' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5811
     'c.' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5812
     '.' asFilename addSuffix:'o'            
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5813
     '/foo/bar/baz.st' asFilename addSuffix:'c'   
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5814
     '/foo/bar/baz.c' asFilename addSuffix:'st'   
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5815
     '/foo/bar.c/baz.c' asFilename addSuffix:'st'   
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5816
     '/foo/bar.c/baz' asFilename addSuffix:'st'   
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5817
    "
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5818
!
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  5819
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5820
hasSuffix:aSuffixString
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5821
    "return true if my suffix is the same as aString.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5822
     This cares for systems, where case is ignored in filenames"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5823
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5824
    |mySuffix|
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5825
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5826
    mySuffix := self suffix.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5827
    self species isCaseSensitive ifTrue:[
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5828
        ^ mySuffix = aSuffixString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5829
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5830
    ^ mySuffix asLowercase = aSuffixString asLowercase
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5831
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5832
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5833
     'abc.st' asFilename hasSuffix:'st'   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5834
     'abc.ST' asFilename hasSuffix:'st'   
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5835
     '.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
  5836
     '.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
  5837
     '.foorc.sav' asFilename hasSuffix:'sav'   
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5838
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5839
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5840
    "Modified: 7.9.1997 / 02:55:25 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5841
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5842
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5843
nameWithoutSuffix
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5844
    "return the receivers name without the suffix.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5845
     If the name has no suffix, the original name is returned."
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5846
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5847
    |nm idx idxFromEnd|
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5848
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5849
    nm := self baseName.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5850
    idx := nm lastIndexOf:(self species suffixSeparator).
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5851
    (idx == 0) ifTrue:[^ nameString].
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5852
    "/ be careful: if the name consists only of suffix (i.e '.foo'),
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5853
    "/ the suffix is considered empty.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5854
    (idx == 1) ifTrue:[^ nameString].
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5855
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5856
    idxFromEnd := nm size - idx.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5857
    idx := nameString size - idxFromEnd.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5858
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5859
    ^ nameString copyTo:(idx - 1)
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5860
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5861
    "
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5862
     'abc.st' asFilename nameWithoutSuffix         
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5863
     'abc' asFilename nameWithoutSuffix            
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5864
     '/abc' asFilename nameWithoutSuffix            
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5865
     '/abc.d' asFilename nameWithoutSuffix            
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5866
     './abc' asFilename nameWithoutSuffix            
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5867
     './abc.d' asFilename nameWithoutSuffix            
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5868
     './.abc' asFilename nameWithoutSuffix            
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5869
     'a.b.c' asFilename nameWithoutSuffix           
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5870
     'a.b.' asFilename nameWithoutSuffix           
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5871
     '.b.c' asFilename nameWithoutSuffix           
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5872
     '.b.' asFilename nameWithoutSuffix           
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5873
     '.b' asFilename nameWithoutSuffix           
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5874
     '/foo/bar/baz.c' asFilename nameWithoutSuffix     
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5875
     '/foo/bar.x/baz.c' asFilename nameWithoutSuffix     
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5876
     '/foo/bar.x/baz' asFilename nameWithoutSuffix     
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5877
     '/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix   
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5878
     '/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix   
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5879
    "
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5880
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5881
    "Modified: / 07-09-1995 / 11:15:42 / claus"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5882
    "Created: / 07-11-2006 / 13:55:18 / cg"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5883
!
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5884
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5885
prefix
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5886
    "return my prefix.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5887
     The suffix is the namepart after the final period character,
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5888
     or the empty string, if the name does not contain a period."
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5889
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5890
    ^ self prefixAndSuffix at:1
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5891
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5892
    "
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5893
     'abc.st' asFilename prefix   
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5894
     'abc' asFilename prefix      
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5895
     'a.b.c' asFilename prefix    
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5896
     'a.b.c' asFilename prefix    
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5897
     'a.' asFilename prefix    
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5898
     '.a' asFilename prefix    
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5899
    "
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5900
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5901
    "Modified: / 07-09-1995 / 11:09:03 / claus"
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5902
    "Created: / 13-07-2006 / 10:27:19 / fm"
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5903
!
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  5904
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5905
prefixAndSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5906
    "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
  5907
     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
  5908
     the prefix everything before, except for the period.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5909
     The directory name part is stripped off (i.e. the returned prefix
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  5910
     will consist of the file's basename only.)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5911
     (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
  5912
     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
  5913
     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
  5914
     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
  5915
     '.foorc'.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5916
     See also: #withoutSuffix and #withSuffix
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5917
     Notice: 
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5918
        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
  5919
        the period character as suffixCharacter."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5920
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5921
    |nm idx|
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5922
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5923
    nm := self baseName.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5924
    idx := nm lastIndexOf:(self species suffixSeparator).
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5925
    "/ 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
  5926
    "/ the suffix is considered empty.
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5927
    ((idx == 1) or:[ idx == 0 ]) ifTrue:[
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5928
        ^ Array with:nm with:''
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5929
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5930
    ^ Array 
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5931
        with:(nm copyTo:idx-1)
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5932
        with:(nm copyFrom:idx+1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5933
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5934
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5935
     'abc.st' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5936
     'abc' asFilename prefixAndSuffix  
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5937
     'a.b.c' asFilename prefixAndSuffix 
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5938
     '/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
  5939
     'a.' asFilename prefixAndSuffix    
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5940
     '.a' asFilename prefixAndSuffix    
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5941
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5942
     |parts| 
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5943
     parts := 'Object.st' asFilename prefixAndSuffix.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5944
     ((parts at:1) , '.o') asFilename   
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5945
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5946
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5947
    "Modified: 7.9.1995 / 11:15:42 / claus"
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5948
    "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
  5949
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5950
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5951
suffix
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5952
    "return my suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5953
     The suffix is the namepart after the final period character,
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5954
     or the empty string, if the name does not contain a period."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5955
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5956
    ^ self prefixAndSuffix at:2
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5957
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5958
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5959
     'abc.st' asFilename suffix   
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5960
     'abc' asFilename suffix      
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5961
     'a.b.c' asFilename suffix    
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5962
     'a.b.c' asFilename suffix    
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5963
     'a.' asFilename suffix    
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5964
     '.a' asFilename suffix    
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5965
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5966
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5967
    "Modified: 7.9.1995 / 11:09:03 / claus"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5968
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  5969
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5970
withSuffix:aSuffix
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5971
    "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
  5972
     If the name already has a suffix, the new suffix replaces it;
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  5973
     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
  5974
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5975
    |prefixName|
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5976
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  5977
    prefixName := self nameWithoutSuffix.
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5978
    aSuffix isEmptyOrNil ifTrue:[
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5979
        ^ self species named:prefixName
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  5980
    ].
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  5981
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5982
    ^ self species named:
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5983
        (prefixName 
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  5984
         , self class suffixSeparator asString 
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  5985
         , aSuffix asString)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5986
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5987
    "
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  5988
     'abc.st' asFilename withSuffix:nil         
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5989
     'a.b.c' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5990
     '.b.c.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5991
     '.b.c' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5992
     '.c.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5993
     '.c' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5994
     'c.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5995
     '.' asFilename withSuffix:nil            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  5996
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5997
     'abc.st' asFilename withSuffix:'o'         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5998
     'abc' asFilename withSuffix:'o'             
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5999
     '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
  6000
     'a.b.c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6001
     '.b.c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6002
     '.c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6003
     '.c' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6004
     'c.' asFilename withSuffix:'o'            
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6005
     '.' asFilename withSuffix:'o'            
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6006
     '/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
  6007
     '/foo/bar/baz.c' asFilename withSuffix:'st'   
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  6008
     '/foo/bar.c/baz.c' asFilename withSuffix:'st'   
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  6009
     '/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
  6010
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6011
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6012
    "Modified: / 07-09-1995 / 11:15:42 / claus"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6013
    "Modified: / 07-11-2006 / 13:58:45 / cg"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6014
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6015
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6016
withoutSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6017
    "return a new filename for the receivers name without the suffix.
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6018
     If the name has no suffix, a filename representing the same file as the receiver is returned."
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6019
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6020
    |n|
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6021
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6022
    n := self nameWithoutSuffix.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6023
    n = nameString ifTrue:[^ self].
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  6024
    ^ self species named:n
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6025
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6026
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6027
     'abc.st' asFilename withoutSuffix         
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6028
     '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
  6029
     '/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
  6030
     '/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
  6031
     './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
  6032
     './abc.d' asFilename withoutSuffix            
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6033
     './.abc' asFilename withoutSuffix            
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6034
     'a.b.c' asFilename withoutSuffix           
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6035
     'a.b.' asFilename withoutSuffix           
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6036
     '.b.c' asFilename withoutSuffix           
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6037
     '.b.' asFilename withoutSuffix           
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6038
     '.b' asFilename withoutSuffix           
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  6039
     '/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
  6040
     '/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
  6041
     '/foo/bar.x/baz' asFilename withoutSuffix     
1516
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  6042
     '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix   
25c8437ba876 fixed #withoutSuffix
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
  6043
     '/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
  6044
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6045
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6046
    "Modified: / 07-09-1995 / 11:15:42 / claus"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6047
    "Modified: / 07-11-2006 / 13:57:45 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6048
! !
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6049
5597
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6050
!Filename methodsFor:'testing'!
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6051
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6052
isFilename
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6053
    "return true, if the receiver is some kind of filename;
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6054
     false is returned here - the method is redefined from Object."
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6055
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6056
    ^true
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6057
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6058
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6059
! !
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  6060
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6061
!Filename methodsFor:'writing-files'!
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6062
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6063
appendingFileDo:aBlock
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6064
    "create a append-stream on the receiver file, evaluate aBlock, passing that stream as arg,
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6065
     and return the blocks value. 
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6066
     If the file cannot be opened, an exception is raised.
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6067
     Ensures that the stream is closed."
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6068
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6069
    |stream result|
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6070
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6071
    stream := self appendStream.
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6072
    [
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6073
        result := aBlock value:stream
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6074
    ] ensure:[
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6075
        stream close
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6076
    ].
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6077
    ^ result
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6078
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6079
    "
14513
c0a090b81917 comment/format in: #appendingFileDo:
sr
parents: 14512
diff changeset
  6080
     'ttt' asFilename appendingFileDo:[:s |
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6081
        s nextPutLine:'hello'.
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6082
        s nextPutLine:'world'.
14513
c0a090b81917 comment/format in: #appendingFileDo:
sr
parents: 14512
diff changeset
  6083
     ]           
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6084
    "
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6085
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6086
    "Created: / 09-11-2012 / 10:07:41 / sr"
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6087
!
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  6088
10779
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6089
contents:aStringOrCollectionOfLines
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6090
    "create (or overwrite) a file given its contents as a collection of lines.
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6091
     Raises an error, if the file is unwritable."
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6092
10779
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6093
    ^ self 
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6094
        writingFileDo:[:s |
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6095
            aStringOrCollectionOfLines isNonByteCollection ifTrue:[
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6096
                "a StringCollection or a collection of lines"
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6097
                aStringOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')]
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6098
            ] ifFalse:[
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6099
                "something string-like"
11877
aa347ed8ce60 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 11784
diff changeset
  6100
                aStringOrCollectionOfLines isString ifFalse:[
aa347ed8ce60 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 11784
diff changeset
  6101
                    s binary
aa347ed8ce60 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 11784
diff changeset
  6102
                ].
10779
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6103
                s nextPutAll:aStringOrCollectionOfLines
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6104
            ]
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6105
        ].
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6106
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6107
    "
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6108
     'foo1' asFilename contents:#('one' 'two' 'three')            
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6109
     'foo2' asFilename contents:'Hello world'            
15023
ccc1572f4629 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15001
diff changeset
  6110
     'foo3' asFilename contents:#[1 2 3 4 5]          
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6111
    "
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6112
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6113
    "Created: / 11-12-2006 / 14:11:21 / cg"
10779
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  6114
    "Modified: / 08-11-2007 / 13:28:41 / cg"
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6115
!
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6116
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6117
writingFileDo:aBlock
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6118
    "create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg,
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6119
     and return the blocks value. 
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6120
     If the file cannot be opened, an exception is raised.
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6121
     Ensures that the stream is closed."
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6122
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6123
    |stream result|
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6124
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6125
    stream := self writeStream.
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6126
    [
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6127
        result := aBlock value:stream
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6128
    ] ensure:[
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6129
        stream close
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6130
    ].
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6131
    ^ result
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6132
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6133
    "
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6134
     'ttt' asFilename writingFileDo:[:s |
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6135
        s nextPutLine:'hello'.
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6136
        s nextPutLine:'world'.
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6137
     ]
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6138
    "
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6139
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6140
    "Created: / 11-12-2006 / 14:09:39 / cg"
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6141
! !
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  6142
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  6143
!Filename class methodsFor:'documentation'!
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  6144
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  6145
version
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  6146
    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.435 2015-04-22 17:59:59 stefan Exp $'
12318
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  6147
!
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  6148
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  6149
version_CVS
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  6150
    ^ '$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.435 2015-04-22 17:59:59 stefan Exp $'
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  6151
! !
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6152
14628
d6bf1fd719f6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14567
diff changeset
  6153
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6154
Filename initialize!