Filename.st
author Claus Gittinger <cg@exept.de>
Tue, 09 Jul 2019 20:55:17 +0200
changeset 24417 03b083548da2
parent 24403 2381ea8610f7
child 24454 9b9e7d371d89
permissions -rw-r--r--
#REFACTORING by exept class: Smalltalk class changed: #recursiveInstallAutoloadedClassesFrom:rememberIn:maxLevels:noAutoload:packageTop:showSplashInLevels: Transcript showCR:(... bindWith:...) -> Transcript showCR:... with:...
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
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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
24101
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
diff changeset
    19
	instanceVariableNames:'nameString'
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
diff changeset
    20
	classVariableNames:'ConcreteClass DefaultTempDirectory TempDirectory'
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
diff changeset
    21
	poolDictionaries:''
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
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
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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
21778
23a7d326887c #OTHER by mawalch
mawalch
parents: 21693
diff changeset
    46
    Instances of Filename do not necessarily represent valid or existing
92
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
20293
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    52
        '/fee/foo/foe' asFilename exists
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    53
        '/not_existing' asFilename isDirectory
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
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
20293
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    60
        'Makefile' asFilename readStream
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    61
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    62
        'newFile' asFilename writeStream
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    63
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    64
        Filename newTemporary writeStream
276
3b6d97620494 *** empty log message ***
claus
parents: 249
diff changeset
    65
21779
1033ac050886 #DOCUMENTATION by mawalch
mawalch
parents: 21778
diff changeset
    66
    Beside lots of protocol to query for a file's attributes, the class
20293
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    67
    protocol offers methods for filename completion, to construct paths
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
    68
    (in an OS-independent way) and to create temporary files.
21779
1033ac050886 #DOCUMENTATION by mawalch
mawalch
parents: 21778
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
21779
1033ac050886 #DOCUMENTATION by mawalch
mawalch
parents: 21778
diff changeset
    71
    being slash or backslash) spread in your application.
1318
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
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
    77
    specific OS Filenames might be used, even if ST/X is currently running
8738
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:]
20293
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
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:]
20293
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    84
        String
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    85
        FileStream DirectoryStream PipeStream Socket
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
diff changeset
    86
        OperatingSystem
0f6fb5392f70 #OTHER by mawalch
mawalch
parents: 20252
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 ?:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
    94
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
    95
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
    96
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
    97
        f := 'foobar' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
    98
        ^ f exists
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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 ?:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   103
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   104
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   105
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   106
        f := '/tmp' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   107
        ^ f isDirectory.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   108
                                                                        [exEnd]
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   109
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   110
360
claus
parents: 359
diff changeset
   111
    get the working directory:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   112
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   113
        ^ Filename defaultDirectory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   114
                                                                        [exEnd]
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   115
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   116
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   117
    get a files full pathname
360
claus
parents: 359
diff changeset
   118
    (caring for relative names or symbolic links):
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   119
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   120
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   121
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   122
        f := '..' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   123
        ^ f pathName
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   128
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   129
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   130
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   131
        f := Filename defaultDirectory.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   132
        ^ f directory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   137
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   138
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   139
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   140
        f := './smalltalk' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   141
        ^ f directory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   146
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   147
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   148
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   149
        f := '/tmp' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   150
        ^ f dates
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   151
                                                                        [exEnd]
360
claus
parents: 359
diff changeset
   152
claus
parents: 359
diff changeset
   153
    access time only:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   154
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   155
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   156
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   157
        f := '/tmp' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   158
        ^ f dates at:#accessed
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   159
                                                                        [exEnd]
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   160
360
claus
parents: 359
diff changeset
   161
claus
parents: 359
diff changeset
   162
    getting all information on a file/directory:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   163
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   164
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   165
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   166
        f := '/tmp' asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   167
        ^ f info
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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):
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   172
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   173
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   174
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   175
        f := Filename newTemporary.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   176
        ^ f
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   180
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   181
        |f writeStream readStream|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   182
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   183
        f := Filename newTemporary.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   184
        writeStream := f writeStream.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   185
        writeStream nextPutAll:'hello world'.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   186
        writeStream cr.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   187
        writeStream close.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   188
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   189
        'contents (as seen by unix''s cat command:' printNL.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   190
        OperatingSystem executeCommand:('cat ' , f pathName).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   191
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   192
        readStream := f readStream.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   193
        Transcript showCR:'contents as seen by smalltalk:'.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   194
        Transcript showCR:(readStream upToEnd).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   195
        readStream close.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   196
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   197
        f delete.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   198
                                                                        [exEnd]
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   199
360
claus
parents: 359
diff changeset
   200
claus
parents: 359
diff changeset
   201
    getting a directories contents:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   202
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   203
        |f files|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   204
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   205
        f := Filename currentDirectory.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   206
        files := f directoryContents.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   207
        Transcript showCR:'the files are:'.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   208
        Transcript showCR:(files printString).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   213
                                                                        [exBegin]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   214
        |f|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   215
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   216
        f := Filename newTemporary.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   217
        (f writeStream) nextPutAll:'hello world'; close.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   218
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   219
        f edit
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
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:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   230
        self initializeConcreteClass
7702
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:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   244
        ConcreteClass := UnixFilename
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   245
    ] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   246
        ConcreteClass := PCFilename
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   247
    ] ifFalse:[OperatingSystem isVMSlike ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   248
        ConcreteClass := OpenVMSFilename
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   249
    ] ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   250
        self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'.
8754
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:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   254
        self error:'Filename: Missing concrete Filename class'.
8754
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:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   291
        exeName := OperatingSystem nameOfSTXExecutable.
17227
c75e790d86f1 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17143
diff changeset
   292
    ] ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   293
        exeName := 'smalltalk'
17227
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
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   297
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   298
     Filename applicationDataDirectory
17227
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
23606
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   309
    |s dir firstTime|
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:[
23605
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   313
        ^ self homeDirectory
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   314
    ].
12974
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   315
    dir := self named:s.
23605
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   316
    dir isWritableDirectory ifFalse:[
23606
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   317
        firstTime := true.
23605
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   318
        [
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   319
            dir makeDirectory.
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   320
        ] on:OsError do:[:ex|
23606
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   321
            firstTime ifTrue:[
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   322
                firstTime := false.
23605
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   323
                dir := self tempDirectory / appName.
23606
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   324
                dir isWritableDirectory ifFalse:[
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   325
                    ex restart.
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   326
                ].
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   327
            ] ifFalse:[
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   328
                ex reject.
23605
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   329
            ].
d6a0ad740e83 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23601
diff changeset
   330
        ].
12974
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   331
    ].
031ee43e9a1e changed: #applicationDataDirectoryFor:
sr
parents: 12973
diff changeset
   332
    ^ dir
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   333
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   334
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   335
     Filename applicationDataDirectoryFor:'smalltalk'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   336
     Filename applicationDataDirectoryFor:'expecco'
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   337
    "
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   338
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   339
    "Created: / 29-07-2010 / 12:05:35 / sr"
23606
50300ff0d56b #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23605
diff changeset
   340
    "Modified: / 16-01-2019 / 14:29:59 / Stefan Vogel"
12972
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   341
!
1fb37a018fb2 added: #applicationDataDirectoryFor:
sr
parents: 12956
diff changeset
   342
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   343
currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   344
    "return a filename for the current directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   345
13109
89476863464e getCurrentDirectory
Stefan Vogel <sv@exept.de>
parents: 13057
diff changeset
   346
    ^ self named:(OperatingSystem getCurrentDirectory).
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   347
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   348
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   349
     Filename currentDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   350
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   351
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   352
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   353
defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   354
    "ST80 compatibility: same as currentDirectory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   355
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   356
    ^ self currentDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   357
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   358
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   359
     Filename defaultDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   360
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   361
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   362
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   363
defaultTempDirectory
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   364
    "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
   365
     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
   366
     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
   367
     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
   368
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   369
    DefaultTempDirectory isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   370
        self tempDirectory.  "/ actually sets DefaultTempDirectory as side effect
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   371
        DefaultTempDirectory isNil ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   372
            DefaultTempDirectory := TempDirectory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   373
        ].
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   374
    ].
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   375
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   376
    DefaultTempDirectory exists ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   377
        DefaultTempDirectory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   378
            makeDirectory;
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   379
            addAccessRights:#(readUser readGroup readOthers
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   380
                              writeUser writeGroup writeOthers
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   381
                              executeUser executeGroup executeOthers
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   382
                              removeOnlyByOwner).
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   383
    ].
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   384
    ^ DefaultTempDirectory
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   385
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   386
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   387
     Filename tempDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   388
     Filename defaultTempDirectory
12336
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   389
    "
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   390
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   391
    "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
   392
    "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
   393
!
7610de9a7e4b provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents: 12318
diff changeset
   394
10546
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   395
desktopDirectory
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   396
    "return your desktop directory.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
   397
     Under windows, that's the real desktop directory;
10546
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   398
     under other OperatingSystems, the home directory is returned."
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   399
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   400
    |s|
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   401
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   402
    s := OperatingSystem getDesktopDirectory.
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   403
    s isNil ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
   404
        ^ self homeDirectory
10546
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   405
    ].
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   406
    ^ self named:s
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   407
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   408
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   409
     Filename desktopDirectory
10546
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   410
    "
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   411
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   412
    "Created: / 16-05-2007 / 13:18:34 / cg"
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   413
!
0b4c5dc2ecd3 +desktopDirectory
Claus Gittinger <cg@exept.de>
parents: 10390
diff changeset
   414
11763
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   415
documentsDirectory
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   416
    "return your documents directory.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
   417
     Under windows, that's the real 'Documents' or 'My Documents';
11763
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   418
     under other OperatingSystems, the home directory is returned."
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   419
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   420
    |s|
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   421
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   422
    s := OperatingSystem getDocumentsDirectory.
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   423
    s isNil ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
   424
        ^ self homeDirectory
11763
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   425
    ].
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   426
    ^ self named:s
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   427
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   428
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   429
     Filename documentsDirectory
11763
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   430
    "
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   431
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   432
    "Created: / 16-05-2007 / 13:18:34 / cg"
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   433
!
78e389d28c00 new: #documentsDirectory
Stefan Vogel <sv@exept.de>
parents: 11757
diff changeset
   434
22676
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   435
downloadsDirectory
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   436
    "return the downloads directory.
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   437
     Some OperatingSystems do not support this - on those, 
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   438
     the documentsDirectory is returned.
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   439
     Notice: services under windows do not have a user/home and therefore
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   440
     no downloads directory."
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   441
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   442
    |home dir|
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   443
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   444
    home := self homeDirectory.
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   445
    home isNil ifTrue:[^ nil].
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   446
    #(
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   447
        'Downloads'
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   448
        'downloads'
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   449
        'Download'
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   450
        'download'
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   451
    ) do:[:eachTry |
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   452
        (dir := home / eachTry) exists ifTrue:[
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   453
            ^ dir
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   454
        ].
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   455
    ].
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   456
    ^ nil
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   457
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   458
    "
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   459
     Filename downloadsDirectory
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   460
    "
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   461
!
69e0924c2205 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22656
diff changeset
   462
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   463
findDefaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   464
    "same as #defaultDirectory for ST80 compatibility"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   465
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   466
    ^ self defaultDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   467
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   468
    "Created: 20.6.1997 / 17:00:29 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   469
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   470
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   471
fromComponents:aCollectionOfDirectoryNames
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   472
    "create & return a new filename from components given in
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   473
     aCollectionOfDirectoryNames. If the first component is the name of the
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   474
     root directory (i.e. '/') an absolute path-filename is returned."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   475
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   476
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   477
        ^ ConcreteClass fromComponents:aCollectionOfDirectoryNames
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   478
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   479
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
   480
    ^ self named:(self nameFromComponents:aCollectionOfDirectoryNames)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   481
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   482
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   483
     Filename fromComponents:#('/' 'foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   484
     PCFilename fromComponents:#('/' 'foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   485
     UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz')
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   486
     OpenVMSFilename fromComponents:#('foo' 'bar' 'baz')
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   487
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   488
     Filename fromComponents:#('foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   489
     Filename fromComponents:#('/')
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   490
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   491
     Filename fromComponents:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   492
         (Filename components:('.' asFilename pathName))
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   493
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   494
     Filename fromComponents:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   495
         (Filename components:('.' asFilename name))
3959
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
    "Modified: 8.9.1997 / 00:23:16 / cg"
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
fromUser
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   502
    "show a box to enter a filename.
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   503
     Return a filename instance or nil (if cancel was pressed)."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   504
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   505
    |name|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   506
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   507
    name := Dialog
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   508
        requestFileName:'filename:'
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   509
        default:nil
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   510
        fromDirectory:(FileSelectionBox lastFileSelectionDirectory).
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   511
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   512
    name notEmptyOrNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   513
        ^ self named:name
3978
b2babde0857b use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents: 3959
diff changeset
   514
    ].
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   515
    ^ nil
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   516
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   517
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   518
     Filename fromUser
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   519
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   520
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   521
    "Modified: 19.4.1996 / 13:57:44 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   522
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   523
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   524
homeDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   525
    "return your homeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   526
     Some OperatingSystems do not support this - on those, the defaultDirectory
17113
a521179b677c class: Filename
Claus Gittinger <cg@exept.de>
parents: 17112
diff changeset
   527
     (which is the currentDirectory) is returned.
a521179b677c class: Filename
Claus Gittinger <cg@exept.de>
parents: 17112
diff changeset
   528
     Notice: services under windows also do not have a home directory."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   529
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   530
    |s|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   531
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   532
    s := OperatingSystem getHomeDirectory.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   533
    s isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   534
        ^ self defaultDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   535
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   536
    ^ self named:s
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   537
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   538
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   539
     Filename homeDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   540
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   541
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   542
    "Modified: 8.9.1997 / 00:25:23 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   543
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   544
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   545
named:aString
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   546
    "return a filename for a directory named aString.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   547
     This is the same as 'aString asFilename'."
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   548
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   549
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   550
        ^ ConcreteClass named:aString
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   551
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   552
    ^ self basicNew setName:aString
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   553
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   554
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   555
     Filename named:'/tmp/fooBar'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   556
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   557
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   558
    "Modified: 7.9.1997 / 23:30:06 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   559
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   560
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   561
newTemporary
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   562
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   563
     The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   564
     unix process id, and nn is a unique number, incremented with every
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   565
     call to this method.
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   566
     If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set,
4757
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   567
     its value defines the temp directory.
ee9b538ba42c comment
Claus Gittinger <cg@exept.de>
parents: 4392
diff changeset
   568
     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
   569
     is generated.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   570
16787
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   571
     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
   572
     (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
   573
      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
   574
      is reasonably random - but for security relevant applications, this may be relevant)
c73dd3d9a002 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16762
diff changeset
   575
    "
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   576
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   577
    ^ self newTemporaryIn:(self tempDirectory)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   578
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   579
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   580
     Filename newTemporary
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   581
     Filename newTemporary
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   582
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   583
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   584
    "Modified: / 07-09-1995 / 10:48:31 / claus"
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   585
    "Modified: / 07-03-1996 / 14:51:33 / cg"
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   586
    "Modified (comment): / 31-05-2018 / 09:57:58 / Claus Gittinger"
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   587
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   588
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   589
newTemporaryDirectory
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   590
    "return a new unique temporary directory - use this for temporary files.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   591
     The directories returned are '/tmp/stxtmp_xx_nn' where xx is our
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   592
     unix process id, and nn is a unique number, incremented with every
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   593
     call to this method.
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   594
     If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set,
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   595
     its value defines the temp directory."
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   596
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   597
    ^ self newTemporaryDirectoryIn:(self tempDirectory)
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   598
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   599
    "Modified (comment): / 31-05-2018 / 09:57:54 / Claus Gittinger"
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   600
!
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   601
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   602
newTemporaryDirectoryIn:aDirectoryOrNil
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   603
    "return a new unique temporary directory in another directory, or the current dir.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   604
     Use this for temporary files.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   605
     The directories returned are '/tmp/stxtmp_xx_nn' where xx is our
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   606
     unix process id, and nn is a unique number, incremented with every
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   607
     call to this method.
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   608
     If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR... is set,
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   609
     its value defines the temp directory."
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   610
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   611
    |tempdir|
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   612
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
   613
    tempdir := self newTemporaryIn:aDirectoryOrNil.
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   614
    tempdir exists ifTrue:[
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   615
        tempdir recursiveRemove.
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   616
    ].
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   617
    tempdir makeDirectory.
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   618
    ^ tempdir
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   619
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   620
    "Modified (comment): / 31-05-2018 / 09:57:49 / Claus Gittinger"
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   621
!
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   622
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   623
newTemporaryIn:aDirectoryOrNil
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   624
    "return a new unique filename - use this for temporary files.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   625
     The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn',
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   626
     where xx is our unix process id, and nn is a unique number, incremented
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   627
     with every call to this method.
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   628
     Notice: only a unique filename object is created and returned - no physical
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   629
     file is created by this method (i.e. you have to send #writeStream or
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   630
     whatever to it in order to really create something).
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   631
     See also: #newTemporary which looks for a good temp directory.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   632
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   633
     DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:"
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   634
12617
7c826d99119a comment/format in:
Claus Gittinger <cg@exept.de>
parents: 12529
diff changeset
   635
    ^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(self tempFileNameTemplate)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   636
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   637
    "temp files in '/tmp':
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   638
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   639
     Filename newTemporary
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   640
     Filename newTemporaryIn:(Filename tempDirectory)
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   641
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   642
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   643
    "temp files somewhere
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   644
     (not recommended - use above since it can be controlled via shell variables):
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   645
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   646
     UnixFilename newTemporaryIn:'/tmp'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   647
     UnixFilename newTemporaryIn:'/tmp'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   648
     UnixFilename newTemporaryIn:'/usr/tmp'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   649
     UnixFilename newTemporaryIn:'/'
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   650
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   651
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   652
    "a local temp file:
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   653
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   654
     Filename newTemporaryIn:''
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   655
     Filename newTemporaryIn:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   656
     Filename newTemporaryIn:'.'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   657
     Filename newTemporaryIn:('source' asFilename)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   658
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   659
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   660
    "Modified: / 7.9.1995 / 10:48:31 / claus"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   661
    "Modified: / 11.8.1998 / 22:51:43 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   662
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   663
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   664
newTemporaryIn:aDirectoryOrNil nameTemplate:template
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   665
    "return a new unique filename - use this for temporary files.
9912
40aace1c3411 +newTemporaryDirectory
Claus Gittinger <cg@exept.de>
parents: 9806
diff changeset
   666
     The filenames returned are in aDirectoryOrNil and named after the given template,
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   667
     in which %1 and %2 are expanded to the unix process id, and a unique number, incremented
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   668
     with every call to this method respectively.
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   669
     If the template does not contain %-meta characters, and the file already exists,
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   670
     a sequence of _1, _2,... is appended to the name. This is dangerous, as it does not prevent race
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   671
     conditions (if two such files are created at the same time).
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   672
     
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   673
     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
   674
     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
   675
     whatever to it in order to really create something).
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   676
     See also: #newTemporary which looks for a good temp directory.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   677
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
   678
     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
   679
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   680
    |newTempFilename oldNameString nextSeqNr|
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   681
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   682
    self isAbstract ifTrue:[
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   683
        ^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   684
    ].
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   685
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   686
    "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
   687
     the following should work on all systems ..."
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   688
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   689
    [
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   690
        |nameString fn|
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   691
        
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   692
        "Use random numbers in order to improve the security
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   693
         by making the generated names less predictable"
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   694
        nameString := template bindWith:(OperatingSystem getProcessId) with:(RandomGenerator nextLettersOrDigits:4).
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   695
        (oldNameString = nameString) ifTrue:[
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   696
            "/ ouch - the given template seems to not generate unique file names.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   697
            "/ append a sequence number
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   698
            nextSeqNr := (nextSeqNr ? 0) + 1.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   699
            fn := nameString asFilename.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   700
            nameString := fn withoutSuffix name,'_',nextSeqNr asString,'.' , fn suffix.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   701
        ].    
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   702
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   703
        aDirectoryOrNil isNil ifTrue:[
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   704
            newTempFilename := self named:nameString
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   705
        ] ifFalse:[
23664
30d61920d972 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23655
diff changeset
   706
            "do not use #construct - I might be an AutoDeletedFilename!!"    
30d61920d972 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23655
diff changeset
   707
            newTempFilename := aDirectoryOrNil asFilename constructString:nameString.
30d61920d972 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23655
diff changeset
   708
            newTempFilename := self named:newTempFilename.    
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   709
        ].
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   710
        oldNameString := nameString.
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   711
    ] doWhile:[
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   712
        "care for existing leftOver tempFiles
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   713
         from a previous boot of the OS
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   714
         i.e. my pid could be the same as when executed
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   715
         the last time before system reboot ...)"
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   716
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   717
        newTempFilename exists
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   718
    ].
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
   719
    ^ newTempFilename
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   720
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   721
    "temp files in '/tmp':
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   722
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   723
     Filename newTemporary
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   724
     Filename newTemporaryIn:nil nameTemplate:'out_%1_%2.txt'
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
   725
     Filename newTemporaryIn:(Filename tempDirectory) nameTemplate:'out_%1_%2.txt'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   726
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   727
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   728
    "temp files somewhere
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   729
     (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
   730
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   731
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   732
     UnixFilename newTemporaryIn:'/tmp'     nameTemplate:'foo%1_%2'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   733
     UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   734
     UnixFilename newTemporaryIn:'/'        nameTemplate:'foo%1_%2'
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   735
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   736
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   737
    "a local temp file:
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   738
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   739
     Filename newTemporaryIn:''             nameTemplate:'foo%1_%2'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   740
     Filename newTemporaryIn:nil            nameTemplate:'foo%1_%2'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   741
     Filename newTemporaryIn:'.'            nameTemplate:'foo%1_%2'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   742
     Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2'
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   743
    "
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   744
12918
a9de9243a951 changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents: 12910
diff changeset
   745
    "Modified: / 07-09-1995 / 10:48:31 / claus"
a9de9243a951 changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents: 12910
diff changeset
   746
    "Modified: / 07-05-2010 / 11:46:05 / cg"
23664
30d61920d972 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23655
diff changeset
   747
    "Modified: / 06-02-2019 / 10:44:21 / Stefan Vogel"
6893
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   748
!
9aa286d3a644 added newTemporary with template
Claus Gittinger <cg@exept.de>
parents: 6839
diff changeset
   749
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   750
nullDevice
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   751
    "return the filename of the nullDevice (if available).
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   752
     returns nil, if the OperatingSystem does not support this."
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   753
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   754
    |s|
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   755
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   756
    s := self nullFilename.
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   757
    s isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   758
        ^ nil
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   759
    ].
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   760
    ^ self named:s
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   761
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   762
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   763
     Filename nullDevice
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   764
     UnixFilename nullDevice
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   765
     PCFilename nullDevice
4199
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   766
    "
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   767
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   768
    "Created: / 19.5.1999 / 12:24:26 / cg"
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   769
!
9f7e67c14465 added nullDevice
Claus Gittinger <cg@exept.de>
parents: 4148
diff changeset
   770
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   771
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   772
    "create & return a new filename from components given in
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   773
     aCollectionOfDirectoryNames on a host named remoteHostString.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   774
     An absolute network-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   775
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   776
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   777
        ^ ConcreteClass remoteHost:remoteHostString
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   778
                        rootComponents:aCollectionOfDirectoryNames
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   779
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   780
10390
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   781
    remoteHostString notEmptyOrNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   782
        self error:'remote hosts are not supported by OS'
10390
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   783
    ].
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   784
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   785
    ^ self rootComponents:aCollectionOfDirectoryNames
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   786
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   787
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   788
      'file:///tmp/test' asURI asFilename
10390
04cd8eb52a98 Bug 575:
Stefan Vogel <sv@exept.de>
parents: 10362
diff changeset
   789
    "
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   790
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   791
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   792
rootComponents:aCollectionOfDirectoryNames
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   793
    "create & return a new filename from components given in
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   794
     aCollectionOfDirectoryNames.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   795
     An absolute path-filename is returned."
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   796
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   797
    |sep s|
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   798
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   799
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   800
        ^ ConcreteClass rootComponents:aCollectionOfDirectoryNames
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   801
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   802
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   803
    "/ fallBack - works on Unix & MSDOS
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   804
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   805
    sep := self separatorString.
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
   806
    s := CharacterWriteStream new.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   807
    aCollectionOfDirectoryNames do:[:component |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   808
        component ~= sep ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   809
            s nextPutAll:sep; nextPutAll:component
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   810
        ]
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   811
    ].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   812
    s := s contents.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   813
    s size == 0 ifTrue:[s := sep].
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   814
    ^ self named:s
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   815
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   816
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   817
     Filename rootComponents:#('/' 'foo' 'bar' 'baz')
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
   818
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   819
     Filename rootComponents:#('foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   820
     PCFilename rootComponents:#('foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   821
     UnixFilename rootComponents:#('foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   822
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   823
     Filename rootComponents:#('/')
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   824
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   825
     Filename rootComponents:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   826
         (Filename components:('.' asFilename pathName))
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   827
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   828
     Filename rootComponents:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   829
         (Filename components:('.' asFilename name))
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   830
    "
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   831
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   832
    "Modified: 8.9.1997 / 00:23:16 / cg"
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   833
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   834
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   835
rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   836
    "return a filename for the root directory"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   837
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   838
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   839
        ^ ConcreteClass rootDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   840
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   841
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   842
    "/ fallBack - works on Unix & MSDOS (but not on VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   843
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
   844
    ^ self named:(self separatorString)
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   845
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   846
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   847
     Filename rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   848
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   849
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   850
    "Modified: 8.9.1997 / 00:24:15 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   851
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   852
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   853
rootDirectoryOnVolume:aVolumeName
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   854
    "return a filename for the root directory on some volume"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   855
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   856
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   857
        ^ ConcreteClass rootDirectoryOnVolume:aVolumeName
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   858
    ].
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   859
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   860
    "/ fallBack - works on Unix (not on MSDOS or VMS)
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   861
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   862
    ^ self rootDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   863
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   864
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   865
     Filename rootDirectoryOnVolume:'/phys/idefix'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   866
     Filename rootDirectoryOnVolume:'d:'
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   867
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   868
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   869
    "Modified: / 5.10.1998 / 12:45:39 / cg"
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   870
!
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   871
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   872
tempDirectory
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   873
    "return the temp directory as a filename.
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   874
     If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR,...
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   875
     is set, its value defines the name,
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   876
     otherwise, '/tmp' is used. (at least on unix ...).
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   877
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   878
     Notice: do not hardcode '/tmp' into your programs - things may be
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   879
             different on other operating systems. Also, the user may want to set the
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   880
             TMPDIR environment variable to have her temp files somewhere else."
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   881
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   882
    |tempDir|
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   883
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   884
    TempDirectory isNil ifTrue:[
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   885
        tempDir := self named:(self defaultTempDirectoryName pathName).
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   886
        tempDir exists ifFalse:[
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   887
            tempDir
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   888
                makeDirectory;
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   889
                addAccessRights:#(readUser readGroup readOthers
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   890
                                  writeUser writeGroup writeOthers
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   891
                                  executeUser executeGroup executeOthers
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   892
                                  removeOnlyByOwner).
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   893
        ].
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   894
        TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'.
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   895
    ].
10551
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   896
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   897
    "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
   898
     by a cleanup (cron) job.
19114
mawalch
parents: 19088
diff changeset
   899
     Since it is shared between users, it must be accessible by all users."
10551
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   900
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   901
    TempDirectory exists ifFalse:[
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   902
        TempDirectory
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   903
            makeDirectory;
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   904
            addAccessRights:#(readUser readGroup readOthers
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   905
                              writeUser writeGroup writeOthers
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   906
                              executeUser executeGroup executeOthers
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   907
                              removeOnlyByOwner).
10551
4924bf1ce2e3 #tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents: 10546
diff changeset
   908
    ].
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   909
    ^ TempDirectory
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   910
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   911
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   912
     Filename tempDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   913
     Filename tempDirectory pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   914
     Filename tempDirectory exists
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   915
     Filename tempDirectory isWritable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   916
     (Filename tempDirectory construct:'foo') makeDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
   917
     (Filename tempDirectory construct:'foo') remove
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   918
    "
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   919
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
   920
    "Created: / 07-03-1996 / 14:51:18 / cg"
13781
c691e88e1900 changed: #tempDirectory
Claus Gittinger <cg@exept.de>
parents: 13779
diff changeset
   921
    "Modified: / 07-10-2011 / 18:39:25 / cg"
23043
8c186d78776f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22943
diff changeset
   922
    "Modified (comment): / 31-05-2018 / 09:58:23 / Claus Gittinger"
11757
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   923
!
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   924
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   925
tempDirectory:aFilename
17048
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   926
    "set the default temporary directory.
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   927
     This allows overwriting the automatically determined tmpDirectory
89053971191b class: Filename
Claus Gittinger <cg@exept.de>
parents: 16999
diff changeset
   928
     by a knowledgable stand alone startup program.
19114
mawalch
parents: 19088
diff changeset
   929
     Do not use elsewhere (and only if absolutely required)"
11757
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   930
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   931
    |temp|
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   932
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   933
    aFilename isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   934
        TempDirectory := nil.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   935
        ^ self.
11757
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   936
    ].
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   937
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   938
    temp := aFilename asFilename.
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   939
    self assert:temp isDirectory.
a2ce2d0ab680 new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents: 11748
diff changeset
   940
    TempDirectory := temp.
16382
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   941
!
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   942
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   943
trashDirectoryOrNil
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   944
    "if the underlying OS uses/supports a trash folder,
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   945
     return it. Otherwise return nil.
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   946
     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
   947
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   948
    |s|
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   949
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   950
    s := OperatingSystem getTrashDirectory.
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   951
    s isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   952
        ^ nil
16382
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   953
    ].
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   954
    ^ self named:s
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   955
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   956
    "
24049
b1cce9185f57 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24017
diff changeset
   957
     Filename trashDirectoryOrNil
16382
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   958
    "
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   959
65553247d728 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16310
diff changeset
   960
    "Created: / 16-05-2007 / 13:18:34 / cg"
24049
b1cce9185f57 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24017
diff changeset
   961
    "Modified (comment): / 10-04-2019 / 05:51:00 / Claus Gittinger"
16648
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   962
!
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   963
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   964
usersPrivateSmalltalkDirectory
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   965
    ^ Filename homeDirectory / '.smalltalk'
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   966
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   967
    "
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   968
     Filename usersPrivateSmalltalkDirectory
95e2cf0814c8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16578
diff changeset
   969
    "
3959
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   970
! !
Claus Gittinger <cg@exept.de>
parents: 3958
diff changeset
   971
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   972
!Filename class methodsFor:'defaults'!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   973
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   974
concreteClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   975
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   976
     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
   977
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   978
    ^ ConcreteClass ? self
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   979
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   980
    "Created: 14.2.1997 / 16:36:13 / cg"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   981
    "Modified: 7.9.1997 / 23:29:20 / cg"
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   982
!
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   983
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
   984
defaultClass
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   985
    "different subclasses of Filename are used for different
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
   986
     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
   987
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   988
    ^ ConcreteClass
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   989
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
   990
    "Modified: 8.9.1997 / 00:36:01 / cg"
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   991
!
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   992
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   993
defaultTempDirectoryName
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   994
    "return the default temp directory as a filename.
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   995
     This is used, if no special preferences were defined in
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   996
     any of the TEMP-environment variables (see tempDirectory)."
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
   997
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
   998
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
   999
        ^ ConcreteClass defaultTempDirectoryName
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1000
    ].
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1001
10994
1a3776d0b845 always return a fileName from defaultTempDirectoryName
fm
parents: 10969
diff changeset
  1002
    ^ '/tmp' asFilename
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1003
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1004
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1005
     Filename defaultTempDirectoryName
7836
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1006
    "
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1007
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1008
    "Modified: 7.9.1995 / 10:48:31 / claus"
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1009
    "Created: 7.3.1996 / 14:51:18 / cg"
37309c372a91 comment
Claus Gittinger <cg@exept.de>
parents: 7828
diff changeset
  1010
    "Modified: 8.9.1997 / 00:24:53 / cg"
19599
04c6b041e116 added defaultVolumeName
Claus Gittinger <cg@exept.de>
parents: 19440
diff changeset
  1011
!
04c6b041e116 added defaultVolumeName
Claus Gittinger <cg@exept.de>
parents: 19440
diff changeset
  1012
04c6b041e116 added defaultVolumeName
Claus Gittinger <cg@exept.de>
parents: 19440
diff changeset
  1013
defaultVolumeName
04c6b041e116 added defaultVolumeName
Claus Gittinger <cg@exept.de>
parents: 19440
diff changeset
  1014
    ^ '/'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1015
! !
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1016
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1017
!Filename class methodsFor:'misc'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1018
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1019
filterSeps:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1020
    "ST80 compatibility:
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1021
     filter out (invalid) separators in aFilenameString.
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1022
     We recommend using #makeLegalFilename"
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1023
16762
32497763707a class: Filename
Claus Gittinger <cg@exept.de>
parents: 16761
diff changeset
  1024
    ^ aFilenameString copyReplaceAll:(Character space) with:$_ ifNone:aFilenameString.
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1025
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1026
    "Created: / 1.11.1997 / 12:39:50 / cg"
3658
5f9d3649da8c use #copyReplaceAll:with:
Claus Gittinger <cg@exept.de>
parents: 3504
diff changeset
  1027
    "Modified: / 18.7.1998 / 22:53:24 / cg"
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1028
!
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1029
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1030
nameWithSpecialExpansions:aString
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1031
    "return the nameString, expanding any OS specific macros.
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1032
     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
  1033
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1034
    |dir user cutIdx idx userInfo|
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1035
23623
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1036
    self isAbstract ifTrue:[
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1037
        ^ ConcreteClass nameWithSpecialExpansions:aString
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1038
    ].
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1039
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1040
19670
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1041
    (aString startsWith:$~) ifFalse:[
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1042
        ^ aString.
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1043
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1044
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1045
    aString size > 1 ifTrue:[
19670
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1046
        idx := aString indexOf:self separator.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1047
        idx == 0 ifTrue:[
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1048
            "aString is '~user'"
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1049
            user := aString copyFrom:2.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1050
            cutIdx := aString size + 1.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1051
        ] ifFalse:[
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1052
            "aString is '~user/something'"
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1053
            user := aString copyFrom:2 to:(idx - 1).
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1054
            cutIdx := idx.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1055
        ].
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1056
        user notEmpty ifTrue:[
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1057
            userInfo := OperatingSystem userInfoOf:user.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1058
            userInfo notNil ifTrue:[
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1059
                dir := userInfo at:#dir ifAbsent:nil.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1060
            ].
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1061
            dir isNil ifTrue:[
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1062
"/                 ('Filename [info]: unknown user: ' , user) infoPrintCR.
19670
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1063
                ^ aString
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1064
            ].
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1065
        ].
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1066
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1067
    dir isNil ifTrue:[
19670
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1068
        "aString is '~' or '~/'"
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1069
        dir := OperatingSystem getHomeDirectory.
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  1070
        cutIdx := 2.
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1071
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1072
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1073
    ^ dir , (aString copyFrom:cutIdx)
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1074
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1075
    "
20709
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1076
     Filename nameWithSpecialExpansions:'~'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1077
     Filename nameWithSpecialExpansions:'~\work'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1078
     Filename nameWithSpecialExpansions:'~stefan'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1079
     Filename nameWithSpecialExpansions:'~stefan\work'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1080
     Filename nameWithSpecialExpansions:'~foo'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1081
     Filename nameWithSpecialExpansions:'~foo\bar'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1082
    "
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1083
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1084
    "
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1085
     UnixFilename nameWithSpecialExpansions:'~'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1086
     UnixFilename nameWithSpecialExpansions:'~/work'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1087
     UnixFilename nameWithSpecialExpansions:'~stefan'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1088
     UnixFilename nameWithSpecialExpansions:'~stefan/work'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1089
     UnixFilename nameWithSpecialExpansions:'~foo'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1090
     UnixFilename nameWithSpecialExpansions:'~foo/bar'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1091
    "
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1092
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1093
    "
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1094
     PCFilename nameWithSpecialExpansions:'~'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1095
     PCFilename nameWithSpecialExpansions:'~\work'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1096
     PCFilename nameWithSpecialExpansions:'~stefan'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1097
     PCFilename nameWithSpecialExpansions:'~stefan\work'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1098
     PCFilename nameWithSpecialExpansions:'~foo'
77d27f4b0482 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20708
diff changeset
  1099
     PCFilename nameWithSpecialExpansions:'~foo\bar'
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1100
    "
23623
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1101
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  1102
    "Modified: / 21-01-2019 / 16:26:56 / Stefan Vogel"
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1103
!
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  1104
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1105
suggest:aFilenameString
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1106
    "return a fileNamestring based on the argument,
3077
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1107
     which is legal on the current platform."
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1108
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1109
    ^ self canonicalize:aFilenameString
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1110
c13ed6652dcf checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3059
diff changeset
  1111
    "Created: / 1.11.1997 / 12:42:39 / cg"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1112
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  1113
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  1114
!Filename class methodsFor:'queries'!
2
claus
parents: 1
diff changeset
  1115
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1116
currentDirectoryName
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1117
    "return a filename for the current directory"
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1118
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1119
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1120
        ^ ConcreteClass currentDirectoryName
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1121
    ].
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1122
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1123
    "/ 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
  1124
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1125
    ^ '.'
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1126
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1127
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1128
     Filename currentDirectoryName
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1129
    "
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1130
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1131
    "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
  1132
    "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
  1133
!
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1134
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1135
defaultDirectoryName
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1136
    "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
  1137
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1138
    ^ self defaultDirectory name
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1139
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1140
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1141
     Filename defaultDirectoryName
10663
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1142
    "
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1143
!
b95f903be43e Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents: 10583
diff changeset
  1144
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1145
directorySuffix
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1146
    "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
  1147
     The default is nil here, redefined for VMS"
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1148
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1149
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1150
        ^ ConcreteClass directorySuffix
2963
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1151
    ].
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1152
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1153
    ^ nil
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1154
!
17bd9be72f9b lots of VMS changes
Claus Gittinger <cg@exept.de>
parents: 2960
diff changeset
  1155
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1156
errorReporter
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1157
    "who knows the signals to report errors?"
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1158
1523
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1159
    ^ FileStream
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1160
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1161
    "Created: 2.7.1996 / 12:30:25 / stefan"
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1162
!
55f1dca97c58 Define #errorReporter.
Stefan Vogel <sv@exept.de>
parents: 1517
diff changeset
  1163
440
claus
parents: 422
diff changeset
  1164
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock
claus
parents: 422
diff changeset
  1165
    "perform filename completion on aString in some directory;
claus
parents: 422
diff changeset
  1166
     return the longest matching filename prefix as a string.
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1167
     The boolean directoriesOnly and filesOnly control respectively,
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1168
     if only directories or only regular files are to be considered for completion.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1169
     If multiple files match, the exception block aBlock is evaluated with a
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1170
     filename representing the directory (where the match was done) as argument.
440
claus
parents: 422
diff changeset
  1171
     (this may be different from the inDirectory argument, if aString is absolute
claus
parents: 422
diff changeset
  1172
      or starts with ../)"
claus
parents: 422
diff changeset
  1173
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1174
    self isAbstract ifTrue:[
23837
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1175
        ^ ConcreteClass
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1176
            filenameCompletionFor:aString
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1177
            directory:inDirectory
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1178
            directoriesOnly:directoriesOnly
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1179
            filesOnly:filesOnly
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1180
            ifMultiple:aBlock
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1181
    ].
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1182
    ^ self 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1183
        filenameCompletionFor:aString 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1184
        directory:inDirectory 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1185
        directoriesOnly:directoriesOnly 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1186
        filesOnly:filesOnly 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1187
        ifMultiple:aBlock 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1188
        forMultipleDo:nil
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1189
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1190
    "
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1191
     self 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1192
        filenameCompletionFor:'/tm' 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1193
        directory:nil 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1194
        directoriesOnly:true 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1195
        filesOnly:false 
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1196
        ifMultiple:[]
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1197
    "
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1198
219d06bf9d6d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23740
diff changeset
  1199
    "Modified (comment): / 04-03-2019 / 15:43:52 / Claus Gittinger"
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1200
!
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1201
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1202
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
  1203
    "perform filename completion on aString in some directory;
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1204
     return the longest matching filename prefix as a string.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1205
     The boolean directoriesOnly and filesOnly control respectively,
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1206
     if only directories or only regular files are to be considered for completion.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1207
     If multiple files match, the exception block aBlock is evaluated with a
6839
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1208
     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
  1209
     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
  1210
     (list of matched filenames)  as arguments.
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1211
     (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
  1212
      or starts with ../)"
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1213
d5bc53f68bab can evaluate block for matchList on filename completition
penk
parents: 6826
diff changeset
  1214
    |s f matchSet nMatch name dir isAbsolute sep|
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1215
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1216
    aString size == 0 ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1217
        aBlock value:(self named:'.').
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1218
        ^ ''
440
claus
parents: 422
diff changeset
  1219
    ].
claus
parents: 422
diff changeset
  1220
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1221
    sep := self separator.
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1222
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1223
    "/ 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
  1224
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1225
    f := self named:aString.
3854
a13d0d489365 care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents: 3852
diff changeset
  1226
    isAbsolute := f isAbsolute.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  1227
    matchSet := f filenameCompletionIn:inDirectory.  "/ BAD DESIGN: has side effect on f
440
claus
parents: 422
diff changeset
  1228
    dir := f directory.
claus
parents: 422
diff changeset
  1229
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1230
    matchSet := matchSet select:[:aFilename |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1231
        |f isDir|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1232
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1233
        isAbsolute ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1234
            f := aFilename asFilename
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1235
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1236
            f := (dir construct:aFilename).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1237
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1238
        isDir := f isDirectory.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1239
        directoriesOnly ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1240
            isDir
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1241
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1242
            filesOnly ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1243
                isDir not
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1244
            ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1245
                true
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1246
            ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1247
        ]
440
claus
parents: 422
diff changeset
  1248
    ].
claus
parents: 422
diff changeset
  1249
6803
2fd6e3ec3c8a completion fixes
Claus Gittinger <cg@exept.de>
parents: 6802
diff changeset
  1250
    f := f asCanonicalizedFilename.
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1251
        (nMatch := matchSet size) ~~ 1 ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1252
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1253
         more than one possible completion -
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1254
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1255
        aMultipleBlock notNil ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1256
            aMultipleBlock value:f value:matchSet.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1257
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1258
        aBlock value:f
440
claus
parents: 422
diff changeset
  1259
    ].
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1260
440
claus
parents: 422
diff changeset
  1261
    "
claus
parents: 422
diff changeset
  1262
     even with more than one possible completion,
claus
parents: 422
diff changeset
  1263
     f's name is now the common prefix
claus
parents: 422
diff changeset
  1264
    "
claus
parents: 422
diff changeset
  1265
    name := f asString.
4323
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
  1266
8b3752e1b060 add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents: 4246
diff changeset
  1267
    nMatch <= 1 ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1268
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1269
         exactly one possible completion -
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1270
        "
3752
cbf9fa32eb28 fixed completion.
Claus Gittinger <cg@exept.de>
parents: 3720
diff changeset
  1271
"/        f := dir construct:matchSet first.
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1272
        false "directoriesOnly" ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1273
            (f exists and:[f isDirectory]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1274
                (name endsWith:sep) ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1275
                    name := name , sep asString
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1276
                ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1277
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1278
        ]
440
claus
parents: 422
diff changeset
  1279
    ].
claus
parents: 422
diff changeset
  1280
5642
87ad71e66acb fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents: 5602
diff changeset
  1281
    s := name.
440
claus
parents: 422
diff changeset
  1282
claus
parents: 422
diff changeset
  1283
    "/ special: if there was no change, and the string represented
claus
parents: 422
diff changeset
  1284
    "/ 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
  1285
    ((nMatch == 1) or:[s = aString]) ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1286
        (s endsWith:sep) ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1287
            (self named:s) isDirectory ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1288
                ^ s , sep asString
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1289
            ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1290
        ].
440
claus
parents: 422
diff changeset
  1291
    ].
claus
parents: 422
diff changeset
  1292
claus
parents: 422
diff changeset
  1293
    ^ s
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1294
4131
f370ebc75bf9 fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents: 3978
diff changeset
  1295
    "Modified: / 30.4.1999 / 09:40:13 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1296
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1297
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1298
filesMatching:aPattern
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1299
    "return a collection of strings, representing the names
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1300
     of files matching aPattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1301
     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
  1302
     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
  1303
     The returned strings are the expanded names, in the same form
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1304
     as given in pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  1305
     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
  1306
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1307
    |basePattern dir d files|
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1308
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1309
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1310
        ^ ConcreteClass filesMatching:aPattern
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1311
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1312
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1313
    "/ the following works on Unix & MSDOS (but not on openVMS)
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1314
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1315
    dir := aPattern asFilename directoryName.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1316
    basePattern := aPattern asFilename baseName.
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1317
    d := dir asFilename.
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  1318
    files := dir asFilename filesMatchingWithoutDotDirs:basePattern.
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1319
    dir = '.' ifTrue:[^ files].
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1320
    ^ files collect:[:base | d constructString:base].
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1321
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1322
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1323
     Filename filesMatching:'*'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1324
     Filename filesMatching:'/*'
2547
4467d25fe057 filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents: 2503
diff changeset
  1325
     Filename filesMatching:'/usr/local/*'
2168
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1326
    "
649e90de1312 added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents: 2013
diff changeset
  1327
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1328
    "Modified: 8.9.1997 / 00:32:31 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1329
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1330
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1331
isAbstract
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1332
    "return true, if this is not a concrete class"
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1333
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1334
    ^ self == Filename
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1335
!
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1336
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1337
isBadCharacter:aCharacter
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1338
    "return true, if aCharacter is unallowed in a filename."
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1339
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  1340
    self isAbstract ifTrue:[
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  1341
        ^ ConcreteClass isBadCharacter:aCharacter
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1342
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1343
8095
bfbd1309a4a6 Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents: 8036
diff changeset
  1344
    ^ aCharacter isControlCharacter
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  1345
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  1346
    "Modified (format): / 27-07-2017 / 14:25:01 / stefan"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1347
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1348
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1349
isCaseSensitive
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1350
    "return true, if filenames are case sensitive.
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1351
     We ask the OS about this, to be independent here.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1352
     This is not really correct, as the sensitivity may depend on
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1353
     the paricular mounted file system (NFS, for example).
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1354
     So we need a query on the instance side"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1355
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1356
    self isAbstract ifTrue:[
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1357
        ^ ConcreteClass isCaseSensitive
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1358
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1359
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1360
    ^ OperatingSystem caseSensitiveFilenames
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1361
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1362
    "Modified: 8.9.1997 / 00:33:32 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1363
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  1364
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1365
localNameStringFrom:aString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1366
    "ST-80 compatibility.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1367
     what does this do ? (used in FileNavigator-goody).
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1368
     GUESS:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1369
        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
  1370
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1371
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1372
        ^ ConcreteClass localNameStringFrom:aString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1373
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1374
15227
c05949447505 refactored
Claus Gittinger <cg@exept.de>
parents: 15192
diff changeset
  1375
    ^ aString withoutPrefix:self separatorString
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1376
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1377
    "Modified: 7.9.1995 / 10:44:56 / claus"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1378
    "Modified: 8.9.1997 / 00:33:51 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1379
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1380
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1381
maxComponentLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1382
    "return the maximum number of characters a filename component may
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1383
     be in size. This depends on the OperatingSystem."
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1384
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1385
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1386
        ^ ConcreteClass maxComponentLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1387
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1388
    ^ OperatingSystem maxFileNameLength
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1389
!
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1390
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1391
maxLength
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1392
    "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
  1393
     This depends on the OperatingSystem."
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1394
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1395
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1396
        ^ ConcreteClass maxLength
2908
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1397
    ].
b3be3629fcb1 vms stuff
Claus Gittinger <cg@exept.de>
parents: 2906
diff changeset
  1398
    ^ OperatingSystem maxPathLength
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1399
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1400
    "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
  1401
    "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
  1402
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  1403
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1404
nullFilename
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1405
    "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
  1406
     The default is nil here"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1407
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1408
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1409
        ^ ConcreteClass nullFilename
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1410
    ].
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1411
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1412
    ^ OperatingSystem getNullDevice
3171
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1413
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1414
    "Created: / 12.1.1998 / 12:15:30 / stefan"
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1415
!
02ef7b6cc664 Add #nullFilename
Stefan Vogel <sv@exept.de>
parents: 3113
diff changeset
  1416
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1417
parentDirectoryName
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1418
    "return the name used for the parent directory.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1419
     This is '..' for unix and dos-like systems.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1420
     (there may be more in the future."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1421
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1422
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1423
        ^ ConcreteClass parentDirectoryName
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1424
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1425
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1426
    ^ OperatingSystem parentDirectoryName
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1427
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1428
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1429
     Filename parentDirectoryName
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1430
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1431
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1432
    "Modified: 8.9.1997 / 00:34:39 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1433
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1434
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1435
separator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1436
    "return the file/directory separator.
15246
a621e4f1fcc4 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15227
diff changeset
  1437
     This is to be redefined in concrete classes."
a621e4f1fcc4 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15227
diff changeset
  1438
a621e4f1fcc4 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15227
diff changeset
  1439
   ^ ConcreteClass separator
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1440
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1441
    "
8754
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1442
     Filename separator
1efa34b61e9b Simpler delegation.
Stefan Vogel <sv@exept.de>
parents: 8741
diff changeset
  1443
     PCFilename separator
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1444
    "
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1445
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1446
    "Modified: 8.9.1997 / 00:20:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1447
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1448
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1449
separatorString
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1450
    "return the file/directory separator as a string."
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1451
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1452
    ^ self separator asString
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1453
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1454
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1455
     Filename separatorString
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1456
    "
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1457
!
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1458
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1459
suffixSeparator
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1460
    "return the filename suffix separator.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1461
     Usually, this is $. for unix-like and msdos systems
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1462
     (there is currently no known system, where this differs)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1463
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1464
     ^ $.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1465
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1466
     "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1467
      Filename suffixSeparator
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1468
     "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1469
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1470
    "Modified: 7.9.1995 / 11:10:43 / claus"
1318
25b5f52aa644 commentary
Claus Gittinger <cg@exept.de>
parents: 1317
diff changeset
  1471
    "Modified: 30.4.1996 / 12:14:25 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1472
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1473
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1474
tempFileNameTemplate
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1475
    "return a template for temporary files.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1476
     This is expanded with the current processID and a sequenceNumber
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1477
     to generate a unique filename."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1478
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1479
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1480
        ^ ConcreteClass tempFileNameTemplate
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1481
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1482
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1483
    ^ 'stxtmp_%1_%2'
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1484
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1485
    "Created: 8.9.1997 / 00:01:46 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1486
    "Modified: 8.9.1997 / 00:35:02 / cg"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1487
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1488
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1489
volumes
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1490
    "ST-80 compatibility.
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1491
     GUESS: does it return the available drives on MSDOS systems ?
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1492
     Q: what does this do on Unix systems ? (used in FileNavigator-goody)."
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1493
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1494
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1495
        ^ ConcreteClass volumes
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1496
    ].
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  1497
2896
be30640b9012 VMS stuff
Claus Gittinger <cg@exept.de>
parents: 2836
diff changeset
  1498
    ^ OperatingSystem getDriveList
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1499
8679
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1500
    "
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1501
     Filename volumes
16cab2229405 comment
Claus Gittinger <cg@exept.de>
parents: 8668
diff changeset
  1502
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1503
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1504
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1505
!Filename class methodsFor:'utilities'!
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1506
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1507
canonicalize:aPathString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1508
    "convert the argument, aPathString to a good format.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1509
     This should eliminate useless directory components (i.e. '././')
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1510
     and useless tree walks (i.e. '../foo/..')."
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1511
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1512
    ^ self nameFromComponents:(self canonicalizedNameComponents:aPathString)
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1513
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1514
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1515
     Filename canonicalize:'/etc/../etc'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1516
     Filename canonicalize:'/home/cg/../'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1517
     Filename canonicalize:'/home/cg/../././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1518
     Filename canonicalize:'./home/cg/../././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1519
     Filename canonicalize:'/home/././cg/../././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1520
     Filename canonicalize:'/home/././cg/././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1521
     Filename canonicalize:'/home/cg/../../..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1522
     Filename canonicalize:'cg/../../..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1523
     Filename canonicalize:'./'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1524
     Filename canonicalize:'/home/.'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1525
     Filename canonicalize:'/home/../..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1526
     Filename canonicalize:'//foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1527
     Filename canonicalize:'///foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1528
     Filename canonicalize:'//foo//bar'
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1529
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1530
!
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1531
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1532
canonicalizedNameComponents:aPathString
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1533
    "convert the argument, aPathString to a good format.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1534
     This should eliminate useless directory components (i.e. '././')
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1535
     and useless tree walks (i.e. '../foo/..').
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1536
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1537
     Answer a sequenceable collection of name components."
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1538
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1539
    |comps newComps rootName dotDot dot|
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1540
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1541
    dotDot := self parentDirectoryName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1542
    dot := self currentDirectoryName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1543
    rootName := self separatorString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1544
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1545
    comps := self components:aPathString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1546
    newComps := OrderedCollection new:comps size.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1547
    comps do:[:eachComponent |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1548
        eachComponent ~= dot ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1549
            eachComponent = dotDot ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1550
               (newComps isEmpty
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1551
                or:[(newComps size == 1 and:[newComps first startsWith:rootName])
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1552
                or:[newComps last = dotDot]]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1553
                   newComps add:eachComponent
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1554
               ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1555
                   newComps removeLast
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1556
               ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1557
            ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1558
                newComps add:eachComponent
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1559
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1560
        ]
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1561
    ].
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1562
    "/ add current Directory if empty
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1563
    newComps isEmpty ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1564
        newComps add:dot.
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1565
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1566
    ^ newComps
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1567
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1568
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1569
     Filename canonicalizedNameComponents:'/etc/../etc'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1570
     Filename canonicalizedNameComponents:'/home/cg/../'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1571
     Filename canonicalizedNameComponents:'/home/cg/../././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1572
     Filename canonicalizedNameComponents:'./home/cg/../././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1573
     Filename canonicalizedNameComponents:'/home/././cg/../././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1574
     Filename canonicalizedNameComponents:'/home/././cg/././'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1575
     Filename canonicalizedNameComponents:'/home/cg/../../..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1576
     Filename canonicalizedNameComponents:'cg/../../..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1577
     Filename canonicalizedNameComponents:'/'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1578
     Filename canonicalizedNameComponents:'./'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1579
     Filename canonicalizedNameComponents:'/.'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1580
     Filename canonicalizedNameComponents:'/home/.'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1581
     Filename canonicalizedNameComponents:'/home'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1582
     Filename canonicalizedNameComponents:'/home/../..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1583
     Filename canonicalizedNameComponents:'//foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1584
     Filename canonicalizedNameComponents:'///foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1585
     Filename canonicalizedNameComponents:'//foo//bar'
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1586
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1587
!
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1588
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1589
components:aString
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1590
    "separate the pathName given by aString into
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  1591
     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
  1592
     the final component.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1593
     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
  1594
     name of the root directory (i.e. '/')."
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1595
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1596
    |sep f vol rest components|
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1597
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1598
    self isAbstract ifTrue:[
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1599
        ^ ConcreteClass components:aString
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1600
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1601
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1602
    "/ the following works on Unix & MSDOS (but not on openVMS)
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1603
    "/ However, MSDOS drive-letters and network drives are
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1604
    "/ not correctly handled here.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1605
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1606
    sep := self separator.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1607
    f := aString asFilename.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1608
    vol := f volume.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1609
    vol size ~~ 0 ifTrue:[
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1610
        rest := f localPathName.
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1611
    ] ifFalse:[
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1612
        rest := aString
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1613
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1614
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1615
    components := rest asCollectionOfSubstringsSeparatedBy:sep.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1616
    (rest startsWith:sep) ifTrue:[
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1617
        "first was a separator - root directory - restore"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1618
        (rest size > 1 and:[rest second = sep and:[vol isEmptyOrNil]]) ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1619
            "keep \\ for windows network paths"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1620
            components at:1 put:(String with:sep with:sep).
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1621
        ] ifFalse:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1622
            components at:1 put:sep asString.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1623
        ].
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1624
    ].
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1625
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1626
    "/ prepend volume to first component (the root directory)
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1627
    vol size ~~ 0 ifTrue:[
20694
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1628
        vol last = $: ifTrue:[
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1629
           vol := vol, (components at:1).
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1630
        ].
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1631
        components at:1 put:vol.
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1632
    ].
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1633
    components := components select:[:each| each notEmpty].
b3547771ae36 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 20686
diff changeset
  1634
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1635
    ^ components
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1636
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1637
    "
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1638
     Unix:
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1639
     UnixFilename components:'/foo/bar/baz'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1640
     UnixFilename components:'/'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1641
     UnixFilename components:'//'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1642
     UnixFilename components:'foo/bar/baz'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1643
     UnixFilename components:'foo/bar'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1644
     UnixFilename components:'foo'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1645
     UnixFilename components:'/foo'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1646
     UnixFilename components:'//foo'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1647
     UnixFilename components:''
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1648
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1649
     Windows:
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1650
     PCFilename components:'\'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1651
     PCFilename components:'\foo'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1652
     PCFilename components:'\foo\'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1653
     PCFilename components:'\foo\bar'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1654
     PCFilename components:'\foo\bar\'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1655
     PCFilename components:'c:'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1656
     PCFilename components:'c:\'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1657
     PCFilename components:'c:\foo'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1658
     PCFilename components:'c:\foo\'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1659
     PCFilename components:'c:\foo\bar'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1660
     PCFilename components:'c:\foo\bar\'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1661
     PCFilename components:'\\idefix'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1662
     PCFilename components:'\\idefix\home'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1663
     PCFilename components:'\\idefix\home\bar'
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1664
    "
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1665
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1666
    "Modified: / 24.9.1998 / 19:10:52 / cg"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1667
!
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  1668
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1669
filesMatchingGLOB:pattern
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1670
    "does a GLOB filename expansion.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1671
     Generates and returns a possibly empty list of files which match
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1672
     the given glob pattern"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1673
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1674
    ^ OrderedCollection withCollectedContents:[:coll |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1675
        pattern asFilename filesMatchingGLOBDo:[:each | coll add:each]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1676
      ]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1677
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1678
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1679
     Filename filesMatchingGLOB:'./A*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1680
     Filename filesMatchingGLOB:'/etc/A*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1681
     Filename filesMatchingGLOB:'/*/A*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1682
     '.' asFilename filesMatchingGLOB:'A*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1683
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1684
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  1685
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1686
nameFromComponents:aCollectionOfDirectoryNames
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1687
    "return a filenameString from components given in aCollectionOfDirectoryNames.
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1688
     If the first component is the name of the root directory (i.e. '/'),
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1689
     an absolute path-string is returned."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1690
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1691
    |sep s|
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1692
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  1693
    self isAbstract ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1694
        ^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1695
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1696
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1697
    "/ fallBack - works on Unix & MSDOS
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1698
8243
91aa4aa5386d +separatorString
Claus Gittinger <cg@exept.de>
parents: 8240
diff changeset
  1699
    sep := self separatorString.
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1700
    s := ''.
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1701
    aCollectionOfDirectoryNames keysAndValuesDo:[:index :component |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1702
        index == 1 ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1703
            s := component.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1704
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1705
            (index == 2 and:[ (s endsWith:sep) ]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1706
                s := s , component
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1707
            ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1708
                s := s , sep , component
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1709
            ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1710
        ].
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1711
    ].
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1712
    ^ s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1713
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1714
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1715
     Filename nameFromComponents:#('/' 'foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1716
     Filename nameFromComponents:#('foo' 'bar' 'baz')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1717
     Filename nameFromComponents:#('/')
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1718
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1719
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1720
     comps := Filename components:'/foo/bar/baz'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1721
     Filename nameFromComponents:comps
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1722
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1723
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1724
     comps := Filename components:'\foo\bar\baz'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1725
     Filename nameFromComponents:comps
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1726
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1727
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1728
     comps := Filename components:'c:\foo\bar\baz'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1729
     Filename nameFromComponents:comps
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1730
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1731
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1732
     comps := Filename components:'foo\bar\baz'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1733
     Filename nameFromComponents:comps
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1734
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1735
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1736
     comps := Filename components:'foo'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1737
     Filename nameFromComponents:comps
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1738
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1739
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1740
     comps := Filename components:'\'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1741
     Filename nameFromComponents:comps
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1742
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1743
     |comps|
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  1744
     comps := Filename components:'c:\'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1745
     Filename nameFromComponents:comps
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1746
    "
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1747
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1748
    "Modified: 8.9.1997 / 00:23:16 / cg"
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1749
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  1750
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1751
possiblyQuotedPathname:aPath
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1752
    "return a filename path usable as command line argument,
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1753
     by quoting in double quotes if there are any embedded special characters.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1754
     On Unix systems, special characters might also be prefixed by a backslash character."
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1755
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1756
    (aPath startsWith:$") ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1757
        (aPath includes:Character space) ifTrue:[
24016
71594012e33c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24013
diff changeset
  1758
            ^ '"',aPath,'"'
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1759
        ].
24016
71594012e33c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24013
diff changeset
  1760
    ].
71594012e33c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24013
diff changeset
  1761
    ^ aPath
71594012e33c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24013
diff changeset
  1762
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1763
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1764
    "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1765
     Filename possiblyQuotedPathname:'/tmp/bla'
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1766
     Filename possiblyQuotedPathname:'/tmp directory/bla'
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1767
     Filename possiblyQuotedPathname:'/tmp directory/bla file'
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1768
    "
24016
71594012e33c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24013
diff changeset
  1769
!
71594012e33c #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24013
diff changeset
  1770
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1771
readingFile:aPathName do:aBlock
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1772
    "Create a read stream on a file, evaluate aBlock, passing that stream,
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1773
     and return the block's value.
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1774
     Ensures that the stream is closed."
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1775
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1776
    ^ aPathName asFilename readingFileDo:aBlock.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1777
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1778
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1779
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1780
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1781
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1782
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1783
     rslt :=
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1784
        Filename
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1785
            readingFile:'/etc/passwd'
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1786
            do:[:s |
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1787
                s nextLine
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1788
            ].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1789
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1790
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1791
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1792
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1793
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1794
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1795
     |rslt|
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1796
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1797
     rslt :=
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1798
        Filename
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1799
            readingFile:'/etc/passwd'
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1800
            do:
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1801
                [:s |
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1802
                    |shells|
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1803
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1804
                    shells := Bag new.
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1805
                    s linesDo:
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1806
                        [:line |
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1807
                            |parts|
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1808
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1809
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1810
                            shells add:(parts seventh).
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1811
                        ].
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1812
                    shells contents
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  1813
                ].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1814
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  1815
    "
6383
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1816
! !
1197f9507ad2 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6382
diff changeset
  1817
7261
f35fc9cee675 method category rename
Claus Gittinger <cg@exept.de>
parents: 7258
diff changeset
  1818
!Filename methodsFor:'Compatibility-VW5.4'!
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1819
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1820
asLogicalFileSpecification
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1821
    ^ self
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1822
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1823
    "Created: / 30.10.2001 / 17:31:10 / cg"
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1824
!
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1825
10583
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1826
canBeWritten
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1827
    "same as isWritable - for ST-80 compatibility"
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1828
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1829
    ^ self isWritable
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1830
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1831
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1832
     '/foo/bar' asFilename canBeWritten
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1833
     '/tmp' asFilename canBeWritten
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1834
     'Makefile' asFilename canBeWritten
10583
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1835
    "
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1836
!
71c4724f0b29 category change
Stefan Vogel <sv@exept.de>
parents: 10557
diff changeset
  1837
7596
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1838
definitelyExists
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1839
    "for now - a kludge"
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1840
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1841
    ^ self exists
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1842
!
33ba33b38a6d *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7519
diff changeset
  1843
22943
4cb0b0ada1ff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22939
diff changeset
  1844
delete
4cb0b0ada1ff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22939
diff changeset
  1845
    "remove the file - same as remove, for ST-80 compatibility"
4cb0b0ada1ff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22939
diff changeset
  1846
4cb0b0ada1ff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22939
diff changeset
  1847
    self remove
4cb0b0ada1ff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22939
diff changeset
  1848
!
4cb0b0ada1ff #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22939
diff changeset
  1849
6447
7674534c81d7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6422
diff changeset
  1850
extension
6454
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1851
    "return the receiver's extension;
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1852
     that is the characters from and including
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1853
     the last period or nil, if there is none."
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1854
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1855
    |string idx|
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1856
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1857
    string := self asString.
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1858
    idx := string lastIndexOf:$..
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1859
    idx > 1 ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1860
        ^ string copyFrom:idx
6454
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1861
    ].
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1862
    ^ nil
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1863
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1864
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1865
     'foo.html' asFilename extension
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1866
     'foo.bar' asFilename extension
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1867
     'foo.bar.baz' asFilename extension
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1868
     'foo.' asFilename extension
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1869
     'foo' asFilename extension
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  1870
     '.login' asFilename extension
6454
ea54a667f131 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6447
diff changeset
  1871
    "
6139
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1872
! !
1b86d43f8eb7 VW compatibility
Claus Gittinger <cg@exept.de>
parents: 6085
diff changeset
  1873
23719
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1874
!Filename methodsFor:'attribute setter'!
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1875
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1876
clearHidden
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1877
    "ignored here 
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1878
     - redefined for windows to clear the file's hidden flag"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1879
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1880
    ^ false    "nothing changed"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1881
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1882
    "Modified: / 12-02-2019 / 12:43:37 / Stefan Vogel"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1883
!
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1884
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1885
setHidden
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1886
    "ignored here 
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1887
     - redefined for windows to set the file's hidden flag"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1888
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1889
    ^ false     "nothing changed"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1890
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1891
    "Created: / 22-12-2018 / 18:03:43 / Claus Gittinger"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1892
    "Modified: / 12-02-2019 / 12:37:25 / Stefan Vogel"
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1893
! !
b0f496b3b72b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23667
diff changeset
  1894
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1895
!Filename methodsFor:'comparing'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1896
16255
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1897
< aFilename
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1898
    "compare file names - used for sorting"
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1899
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1900
    ^ self asString < aFilename asString
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1901
!
1c5caf18b1d1 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15858
diff changeset
  1902
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1903
= aFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1904
    "return true, if the argument represents the same filename"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1905
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1906
    |str|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1907
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1908
    self species == aFilename species ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1909
        str := aFilename asString.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1910
        self species isCaseSensitive ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1911
            ^ nameString = str
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1912
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  1913
        ^ nameString sameAs:str
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1914
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1915
    ^ false
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1916
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  1917
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1918
contentsIsPrefixOf:aFilename
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1919
    "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
  1920
     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
  1921
     This compares the files' actual contents; not the filenames."
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1922
8771
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1923
    |f2 s1 s2 bufferSize buffer1 buffer2 n|
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1924
d1c2b9cc1d8a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8769
diff changeset
  1925
    bufferSize := 8192 * 4.
4979
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1926
9d24293ca0dc checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4940
diff changeset
  1927
    f2 := aFilename asFilename.
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1928
    self fileSize > f2 fileSize ifTrue:[^ false].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1929
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1930
    [
22401
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1931
        s1 := self readStream.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1932
        s2 := f2 readStream.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1933
        s1 binary.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1934
        s2 binary.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1935
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1936
        buffer1 := ByteArray new:bufferSize.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1937
        buffer2 := ByteArray new:bufferSize.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1938
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1939
        [s1 atEnd] whileFalse:[
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1940
            n := s1 nextBytes:bufferSize into:buffer1 startingAt:1.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1941
            n == 0 ifTrue:[
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1942
                "/ receiver at end.
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1943
                ^ true
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1944
            ].
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1945
            (s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1946
                "/ aFilename shorter (cannot happen as mySize is <= argument file's size)
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1947
                ^ false
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1948
            ].
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1949
            buffer1 ~= buffer2 ifTrue:[
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1950
                ^ false
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1951
            ]
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1952
        ].
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1953
        "/ receiver shorter or same size and no difference encountered.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  1954
    ] ensure:[
22401
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1955
        s1 notNil ifTrue:[s1 close].
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  1956
        s2 notNil ifTrue:[s2 close].
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  1957
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1958
    ^ true
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
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1961
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1962
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1963
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1964
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1965
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1966
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1967
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1968
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1969
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1970
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1971
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1972
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1973
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1974
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1975
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1976
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1977
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1978
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1979
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1980
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1981
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1982
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1983
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1984
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifFalse:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1985
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1986
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1987
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1988
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1989
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1990
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1991
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1992
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1993
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1994
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1995
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1996
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1997
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  1998
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  1999
     ('testFile1' asFilename contentsIsPrefixOf:'testFile2'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2000
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2001
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2002
!
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2003
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2004
contentsStartsWithContentsOf:aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2005
    "return true if the contents of the file represented by aFilename
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2006
     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
  2007
     This compares the files' actual contents; not the filenames."
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2008
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2009
    ^ aFilename asFilename contentsIsPrefixOf:self
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2010
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2011
    "
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2012
     |s|
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2013
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2014
     s := 'testFile1' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2015
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2016
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2017
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2018
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2019
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2020
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2021
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2022
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2023
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2024
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2025
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2026
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2027
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2028
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2029
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2030
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2031
     s nextPutAll:'33333'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2032
     s nextPutAll:'44444'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2033
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2034
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2035
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifFalse:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2036
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2037
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2038
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2039
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2040
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2041
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2042
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2043
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2044
     s := 'testFile2' asFilename writeStream.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2045
     s nextPutAll:'11111'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2046
     s nextPutAll:'22222'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2047
     s nextPutAll:'33334'.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2048
     s close.
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2049
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2050
     ('testFile2' asFilename contentsStartsWithContentsOf:'testFile1'  ) ifTrue:[self halt].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2051
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2052
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2053
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2054
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2055
hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2056
    "return an integer useful as a hash-key"
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2057
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  2058
    self species isCaseSensitive ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2059
        "/ asLowercase is slightly better:
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2060
        "/ it never converts single-byte strings to double one's,
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2061
        "/ whereas asUppercase might (for umlaut-y)
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2062
        ^ nameString asUppercase hash
11424
c169cc34afe9 fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents: 11406
diff changeset
  2063
    ].
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2064
    ^ nameString hash
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2065
!
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2066
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2067
sameContentsAs:aFilename
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2068
    "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
  2069
     same contents as the file represented by the argument, aFilename.
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  2070
     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
  2071
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2072
    |f2|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2073
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2074
    f2 := aFilename asFilename.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2075
    f2 fileSize = self fileSize ifFalse:[^ false].
5877
ff4ebbdbacd6 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 5876
diff changeset
  2076
    ^ self contentsIsPrefixOf:f2.
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  2077
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  2078
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2079
     'Make.proto' asFilename sameContentsAs:'Makefile'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2080
     'Make.proto' asFilename sameContentsAs:'Make.proto'
3868
24acb1228e12 added #sameContentsAs:
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
  2081
    "
5876
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2082
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2083
    "
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2084
     |s|
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2085
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2086
     s := 'testFile1' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2087
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2088
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2089
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2090
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2091
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2092
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2093
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2094
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2095
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2096
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2097
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2098
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifFalse:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2099
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2100
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2101
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2102
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2103
     s nextPutAll:'33333'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2104
     s nextPutAll:'44444'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2105
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2106
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2107
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2108
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2109
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2110
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2111
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2112
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2113
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2114
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2115
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2116
     s := 'testFile2' asFilename writeStream.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2117
     s nextPutAll:'11111'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2118
     s nextPutAll:'22222'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2119
     s nextPutAll:'33334'.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2120
     s close.
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2121
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2122
     ('testFile1' asFilename sameContentsAs:'testFile2'  ) ifTrue:[self halt].
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2123
e38638bad111 added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents: 5866
diff changeset
  2124
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2125
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2126
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2127
!Filename methodsFor:'converting'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2128
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2129
asAbsoluteFilename
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2130
    "return the receiver converted to a filename with
24060
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2131
     an absolute pathname.
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2132
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2133
     If the receiver does not exist, no absolute filename is generated.
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2134
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2135
     This makes sense, if you want to send #asString or #printString
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2136
     or #hash or #= to it."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2137
23740
c9bcb6904e07 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23719
diff changeset
  2138
    ^ self species named:self pathName
7332
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  2139
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  2140
    "
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  2141
     '.' asFilename
24060
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2142
     '.' asFilename pathName
7332
d53bc141e00c comment
Claus Gittinger <cg@exept.de>
parents: 7329
diff changeset
  2143
     '.' asFilename asAbsoluteFilename
9173
312ada56e4a9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9062
diff changeset
  2144
     'c:' asFilename asAbsoluteFilename
23654
63bb455ac3fd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23632
diff changeset
  2145
     'foo' asFilename
63bb455ac3fd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23632
diff changeset
  2146
     'foo' asFilename asAbsoluteFilename
63bb455ac3fd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23632
diff changeset
  2147
    "
63bb455ac3fd #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23632
diff changeset
  2148
23655
0156e45ea7ea #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23654
diff changeset
  2149
    "Modified: / 31-01-2019 / 23:00:41 / Claus Gittinger"
23740
c9bcb6904e07 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23719
diff changeset
  2150
    "Modified: / 19-02-2019 / 12:29:37 / Stefan Vogel"
24060
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  2151
    "Modified (comment): / 11-04-2019 / 18:24:23 / Stefan Vogel"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2152
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2153
10769
5623284ae0a0 +autoDeletedFiles
Claus Gittinger <cg@exept.de>
parents: 10663
diff changeset
  2154
asAutoDeletedFilename
13653
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  2155
    "will automatically delete myself, when no longer referenced"
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  2156
11784
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  2157
    ^ AutoDeletedFilename basicNew setName:self name
13653
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  2158
6821135a2e1a comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents: 13424
diff changeset
  2159
    "Modified (comment): / 07-09-2011 / 12:20:59 / cg"
10769
5623284ae0a0 +autoDeletedFiles
Claus Gittinger <cg@exept.de>
parents: 10663
diff changeset
  2160
!
5623284ae0a0 +autoDeletedFiles
Claus Gittinger <cg@exept.de>
parents: 10663
diff changeset
  2161
21390
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2162
asBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2163
    "return the receiver converted to a backup filename."
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2164
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2165
"/    ^ self species named:(nameString, '~').
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2166
"/    ^ self species named:(self directoryName, '/~', self baseName).
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2167
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2168
    ^ self addSuffix:'bak'
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2169
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2170
    "
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2171
     'bla' asFilename asBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2172
     '/home/user/directory/bla' asFilename asBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2173
     'directory/bla' asFilename asBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2174
    "
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2175
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2176
    "Created: / 09-02-2017 / 12:57:28 / stefan"
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2177
!
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2178
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2179
asCanonicalizedFilename
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2180
    "return the receiver converted to a filename without intermediate ..'s and .'s
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2181
     (similar to an absolute pathname, but symlinks are not resolved)."
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2182
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  2183
    ^ self species named:(self species canonicalize:nameString)
7074
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2184
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2185
    "
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2186
      'c:\test\work' asFilename asCanonicalizedFilename
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2187
      '/test/work' asFilename asCanonicalizedFilename
4bcbb93535c3 fix for windows
Michael Beyl <mb@exept.de>
parents: 7067
diff changeset
  2188
    "
6802
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2189
!
e86b8bd49233 canonicalizedFilename
Claus Gittinger <cg@exept.de>
parents: 6794
diff changeset
  2190
23407
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2191
asFileURL
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2192
    "return a file URL-object from myself"
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2193
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2194
    ^ (URL fromString:self pathName) method:'file'; yourself.
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2195
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2196
    "Created: / 07-10-2018 / 11:55:18 / Claus Gittinger"
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2197
!
98893f399451 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23393
diff changeset
  2198
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2199
asFilename
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  2200
    "return the receiver converted to a filename; here, that's the receiver itself."
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  2201
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  2202
    "That's pretty easy here :-)"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2203
    ^ self
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2204
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2205
    "Modified: 12.11.1996 / 12:40:03 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2206
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2207
21390
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2208
asNonBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2209
    "return the receiver converted to a backup filename."
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2210
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2211
    nameString last == $~ ifTrue:[
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2212
        ^ self class named:(nameString copyButLast:1).
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2213
    ].
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2214
    (self hasSuffix:'bak') ifTrue:[
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2215
        ^ self withoutSuffix
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2216
    ].
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2217
    ^ self.
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2218
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2219
    "
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2220
     'bla.bak' asFilename asNonBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2221
     '/home/user/directory/bla.bak' asFilename asNonBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2222
     'directory/bla.bak' asFilename asNonBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2223
     'directory/bla~' asFilename asNonBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2224
    "
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2225
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2226
    "Created: / 09-02-2017 / 14:01:47 / stefan"
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2227
!
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  2228
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2229
asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2230
    "return the receiver converted to a string"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2231
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2232
    ^ nameString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2233
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2234
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2235
asURI
15001
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2236
    "return the receiver converted to a file URI"
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2237
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2238
    ^ FileURI fromFilename:self.
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2239
!
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  2240
15001
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2241
asURL
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2242
    "return an URL-object from myself"
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2243
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2244
    ^ URL fromString:self pathName.
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2245
!
e369f08357d4 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14941
diff changeset
  2246
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2247
asUniqueFilename
22939
9ec13a913fa8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22927
diff changeset
  2248
    "If a file by my name already exists, return a new filename with a unique string appended.
9ec13a913fa8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22927
diff changeset
  2249
     Here, a somewhat naive strategy is performed, by trying _1, _2,... 
9ec13a913fa8 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22927
diff changeset
  2250
     until a new name is generated."
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2251
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2252
    |fn baseFn nextSeqNr|
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2253
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2254
    fn := baseFn := self.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2255
    nextSeqNr := 0.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2256
    [ fn exists ] whileTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2257
        |suff|
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2258
        
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2259
        nextSeqNr := (nextSeqNr ? 0) + 1.
20453
d90a2a56261c #BUGFIX by Micha
Michael Beyl <mb@exept.de>
parents: 20452
diff changeset
  2260
        suff := baseFn suffix.
d90a2a56261c #BUGFIX by Micha
Michael Beyl <mb@exept.de>
parents: 20452
diff changeset
  2261
        suff notEmpty ifTrue:[ suff := '.',suff ].
d90a2a56261c #BUGFIX by Micha
Michael Beyl <mb@exept.de>
parents: 20452
diff changeset
  2262
        fn := self class named:((baseFn withoutSuffix name,'_',nextSeqNr asString),suff).
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2263
    ].
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2264
    ^ fn
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2265
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2266
    "
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2267
     'aaa.txt' asFilename contents:'bla'.
20453
d90a2a56261c #BUGFIX by Micha
Michael Beyl <mb@exept.de>
parents: 20452
diff changeset
  2268
     'aaa.1.2.3.apk.txt' asFilename asUniqueFilename contents:'bla2'.
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2269
     'aaa.txt' asFilename asUniqueFilename contents:'bla3'.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2270
     'aaa.txt' asFilename asUniqueFilename contents:'bla4'.
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2271
     #('aaa.txt' 'aaa_1.txt' 'aaa_2.txt' 'aaa_3.txt') do:[:f | f asFilename delete].  
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2272
    "
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2273
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2274
    "Modified (format): / 06-02-2019 / 11:48:44 / Stefan Vogel"
19665
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2275
!
d815a7ce4e57 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19664
diff changeset
  2276
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2277
components
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  2278
    "return the receiver's filename components - that is the name of each directory
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2279
     along the pathName (that DOES include the root directory)"
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2280
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  2281
    ^ self species components:self name
5890
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2282
2c91b599a4dc added #components
Claus Gittinger <cg@exept.de>
parents: 5889
diff changeset
  2283
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2284
     '.' asFilename asAbsoluteFilename components
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2285
     'Makefile' asFilename asAbsoluteFilename components
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2286
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2287
!
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2288
23129
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2289
makeLegalBasename
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2290
    "convert the receiver's name to be a legal basename.
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2291
     This removes/replaces invalid characters and/or compresses
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2292
     the name as required by the OS.
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2293
     It also replaces the directory separator (i.e. '/') by an inderscore.    
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2294
     The implementation may change in the future to be more
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2295
     OS specific."
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2296
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2297
    "
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2298
     actually, in Unix spaces are allowed - but it makes life
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2299
     so hard; therefore, replace them by underscores ...
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2300
    "
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2301
    nameString := nameString copy 
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2302
                    replaceAllForWhich:[:each| 
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2303
                        each isSeparator 
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2304
                        or:[self class isBadCharacter:each]]
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2305
                    with:$_.
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2306
    "
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2307
     need more - especially on SYS5.3 type systems,
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2308
     we may want to contract the fileName to 14 characters.
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2309
    "
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2310
    ^ self
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2311
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2312
    "
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2313
     'hello world' asFilename makeLegalBasename
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2314
      ('abc' copyWith:Character return) asFilename makeLegalBasename
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2315
      ('a/b/c' copyWith:Character return) asFilename makeLegalBasename
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2316
    "
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2317
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2318
    "Created: / 25-06-2018 / 17:11:41 / Claus Gittinger"
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2319
!
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2320
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2321
makeLegalFilename
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  2322
    "convert the receiver's name to be a legal filename.
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2323
     This removes/replaces invalid characters and/or compresses
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  2324
     the name as required by the OS.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2325
     The implementation may change in the future to be more
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2326
     OS specific."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2327
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2328
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2329
     actually, in Unix spaces are allowed - but it makes life
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2330
     so hard; therefore, replace them by underscores ...
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2331
    "
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2332
    |separator|
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2333
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2334
    separator := self separator.
23129
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2335
    nameString := nameString copy 
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2336
                    replaceAllForWhich:[:each| 
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2337
                        each == Character space 
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2338
                        or:[each ~= separator and:[self class isBadCharacter:each]]]
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2339
                    with:$_.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2340
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2341
     need more - especially on SYS5.3 type systems,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2342
     we may want to contract the fileName to 14 characters.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2343
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2344
    ^ self
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2345
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  2346
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2347
     'hello world' asFilename makeLegalFilename
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2348
      ('abc' copyWith:Character return) asFilename makeLegalFilename
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2349
    "
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2350
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2351
    "Modified: / 20-07-1998 / 13:16:51 / cg"
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  2352
    "Modified (comment): / 27-07-2017 / 15:53:53 / stefan"
23129
53cee4c20659 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 23057
diff changeset
  2353
    "Modified (format): / 25-06-2018 / 17:09:23 / Claus Gittinger"
2707
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2354
!
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2355
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2356
withEncoding:encodingSymbol
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2357
    "dummy for now - for ST80 compatibility"
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2358
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2359
    ^ self
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2360
280456505357 added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents: 2630
diff changeset
  2361
    "Created: 20.6.1997 / 17:01:28 / cg"
2
claus
parents: 1
diff changeset
  2362
! !
claus
parents: 1
diff changeset
  2363
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2364
!Filename methodsFor:'enumerating-contents'!
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
allDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2367
    "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
  2368
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2369
     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
  2370
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2371
     This excludes entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2372
     NoOp for non-existing directories; however, this behavior
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2373
     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
  2374
     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
  2375
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2376
    self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2377
        |eachFileOrDirectory|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2378
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2379
        eachFileOrDirectory := self construct:eachFileOrDirectoryName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2380
        eachFileOrDirectory isDirectory ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2381
            aBlock value:eachFileOrDirectory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2382
        ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2383
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2384
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2385
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2386
     '.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2387
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn name].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2388
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2389
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2390
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2391
allParentDirectoriesDo:aBlock
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2392
    "evaluate aBlock for all (recursive) directories along the parent directory path.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2393
     The block is invoked with a filename-arguments."
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2394
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2395
    |parent here|
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2396
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2397
    here := self.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2398
    parent := here directory.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2399
    [here notNil and:[parent ~= here]] whileTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2400
        aBlock value:parent.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2401
        here := parent.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2402
        parent := here directory.
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2403
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2404
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2405
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2406
     '.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2407
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2408
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  2409
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2410
directoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2411
    "evaluate aBlock for directories contained in the directory represented by the receiver.
23159
dd01709041a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23152
diff changeset
  2412
     The block is invoked with a filename-argument.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2413
     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
  2414
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2415
     This excludes entries for '.' or '..'.
18686
a2af6c2de3ec class: Filename
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  2416
     OpenError is raised if I represent a non-existent or non-readable directories.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2417
     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
  2418
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2419
    self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
23159
dd01709041a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23152
diff changeset
  2420
        eachFileOrDirectory isDirectory ifTrue:[
dd01709041a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23152
diff changeset
  2421
            aBlock value:eachFileOrDirectory
dd01709041a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23152
diff changeset
  2422
        ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2423
    ].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2424
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2425
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2426
     '.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2427
    "
23159
dd01709041a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23152
diff changeset
  2428
dd01709041a3 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23152
diff changeset
  2429
    "Modified (comment): / 30-06-2018 / 18:22:41 / Claus Gittinger"
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2430
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2431
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2432
directoryContentsAsFilenamesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2433
    "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
  2434
     The block is invoked with a filename-argument.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2435
     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
  2436
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2437
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2438
     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
  2439
     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
  2440
     Notice: this enumerates fileName objects; see also
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2441
     #directoryContentsDo:, which enumerates strings."
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2442
6776
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  2443
    self directoryContentsDo:[:entry |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2444
        aBlock value:(self construct:entry).
6776
11df52e55905 better loop (dont preread all items in ..asFilenamesDo:)
penk
parents: 6773
diff changeset
  2445
    ]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2446
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2447
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2448
     '.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName].
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2449
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2450
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2451
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2452
    "Modified: / 23.12.1999 / 20:56:35 / cg"
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2453
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2454
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2455
directoryContentsDo:aBlock
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2456
    "evaluate aBlock for each file in the directory represented by the receiver.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2457
     The block is invoked with a string as argument.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2458
     The enumerations order is undefined - i.e. usually NOT sorted by
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2459
     filenames (but by creation time - on some systems).
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2460
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2461
     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
  2462
     So users of this method better test for existing directory before.
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2463
     Notice: this enumerates strings; see also
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2464
     #directoryContentsAsFilenamesDo:, which enumerates fileName objects."
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2465
20533
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2466
    |s files|
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2467
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2468
    s := DirectoryStream directoryNamed:self osNameForDirectoryContents.
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2469
    "check for nil, in order to allow to proceed from an OpenError"
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2470
    s isNil ifTrue:[
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2471
        ^ self.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2472
    ].
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2473
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2474
    "/ the old code did a recursive call with the stream open.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2475
    "/ for very very deep hierarchies, this lead to having too many file streams open for
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2476
    "/ some operating systems.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2477
    "/ (and therefore to a blocked system, sooner or later, when running out of open files)
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2478
    "/ new code reads the directory first, then does the recursion.
20533
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2479
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2480
"/        [
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2481
"/            [s atEnd] whileFalse:[
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2482
"/                |fn|
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2483
"/
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2484
"/                fn := s nextLine.
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2485
"/                (fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2486
"/                    aBlock value:fn
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2487
"/                ].
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2488
"/            ].
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2489
"/        ] ensure:[
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2490
"/            s close.
0c6a58e929d1 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20459
diff changeset
  2491
"/        ].
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2492
    files := OrderedCollection new.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2493
    [
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2494
        [s atEnd] whileFalse:[
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2495
            |fn|
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2496
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2497
            fn := s nextLine.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2498
            (fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2499
                files add:fn
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2500
            ].
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2501
        ].
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2502
    ] ensure:[
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2503
        s close.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2504
    ]. 
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2505
    files do:aBlock
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2506
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2507
    "
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2508
     '.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
7473
5474c91e0aa3 Comments
Stefan Vogel <sv@exept.de>
parents: 7464
diff changeset
  2509
     'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2510
     [
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2511
        'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2512
     ] on:OpenError do:[:ex| ex proceed]
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2513
    "
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2514
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2515
    "Modified: / 18-09-1997 / 18:42:23 / stefan"
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2516
    "Modified: / 23-12-1999 / 20:56:35 / cg"
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2517
    "Modified: / 06-02-2019 / 12:00:19 / Stefan Vogel"
7464
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2518
!
f7a0e6af79c1 category change
Claus Gittinger <cg@exept.de>
parents: 7343
diff changeset
  2519
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2520
filesDo:aBlock
18734
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2521
    "evaluate aBlock for all regular files (i.e. subdirs are ignored)
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2522
     contained in the directory represented by the receiver."
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2523
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2524
    ^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2525
        eachFileOrDirectory isRegularFile ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2526
            aBlock value: eachFileOrDirectory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2527
        ].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  2528
    ].
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2529
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2530
    "
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2531
     '.' asFilename filesDo:[:f | Transcript showCR:f].
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2532
    "
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2533
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2534
    "Created: / 29-08-2006 / 11:03:15 / cg"
10557
2288b6652a8c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10551
diff changeset
  2535
    "Modified: / 29-05-2007 / 12:02:46 / cg"
9806
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2536
!
3e19989eab9f cache the tempDirectory;
Claus Gittinger <cg@exept.de>
parents: 9453
diff changeset
  2537
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2538
filesMatchingGLOB:pattern do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2539
    "Interpreting pattern as a GLOB pattern,
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2540
     evaluate aBlock for each file in me, which matches.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2541
     Returns the number of matches."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2542
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2543
    self assert:(pattern asFilename isAbsolute not).
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2544
    ^ self filesMatchingGLOBComponents:(self class components:pattern) do:aBlock
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2545
    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2546
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2547
     '..' asFilename filesMatchingGLOB:'A*' do:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2548
     '../..' asFilename filesMatchingGLOB:'lib*/*.st' do:[:fn | Transcript showCR:fn].
23393
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  2549
     '/Library/Java/JavaVirtualMachines' asFilename filesMatchingGLOB:'*.jdk' do:[:fn | Transcript showCR:fn].    
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  2550
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  2551
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  2552
    "Modified (comment): / 30-09-2018 / 10:59:19 / Claus Gittinger"
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2553
    "Modified: / 06-02-2019 / 11:55:35 / Stefan Vogel"
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2554
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2555
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2556
filesMatchingGLOBComponents:patternComponents do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2557
    "patternComponents is a component-collection with possible GLOB patterns.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2558
     Evaluate aBlock for each file in me, which matches.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2559
     Returns the number of matches"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2560
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2561
    |dirPath subComponents count|
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2562
    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2563
    dirPath := patternComponents first.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2564
    subComponents := patternComponents copyFrom:2.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2565
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2566
    dirPath includesMatchCharacters ifFalse:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2567
        | sub |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2568
        
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2569
        sub := (self / dirPath).
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2570
        subComponents isEmpty ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2571
            "/ I am a leaf
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2572
            sub exists ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2573
                aBlock value:sub.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2574
                ^ 1.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2575
            ].    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2576
            ^ 0
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2577
        ] ifFalse:[    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2578
            ^ sub filesMatchingGLOBComponents:subComponents do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2579
        ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2580
    ] ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2581
        count := 0.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2582
        subComponents isEmpty ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2583
            "/ I am a leaf
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2584
            self isDirectory ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2585
                self filesMatching:dirPath do:[:eachMatchingFile |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2586
                    aBlock value:(self / eachMatchingFile).
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2587
                    count := count + 1.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2588
                ]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2589
            ]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2590
        ] ifFalse:[    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2591
            self filesMatching:dirPath do:[:eachMatchingSubDir |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2592
                |sub|
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2593
                sub := (self / eachMatchingSubDir).
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2594
                sub isDirectory ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2595
                    count := count + (sub filesMatchingGLOBComponents:subComponents do:aBlock)
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2596
                ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2597
            ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2598
        ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2599
        ^ count
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2600
    ].    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2601
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2602
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2603
     '/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2604
     '../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2605
     '../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2606
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2607
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2608
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2609
filesMatchingGLOBDo:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2610
    "Interpreting myself as a GLOB pattern,
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2611
     evaluate aBlock for each file which matches."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2612
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2613
    |parts dirPath subComponents count top|
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2614
    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2615
    parts := self components.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2616
    dirPath := parts first.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2617
    subComponents := parts copyFrom:2.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2618
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2619
    OpenError handle:[:ex |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2620
        ('%1 [info]: failed to open %2: %3'
24382
b6d7add521a9 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24379
diff changeset
  2621
                bindWith:self className
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2622
                with:ex pathName 
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2623
                with:ex description) infoPrintCR. 
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2624
        self breakPoint:#cg.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2625
        ex proceed.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2626
    ] do:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2627
        top := dirPath asFilename.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2628
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2629
        dirPath includesMatchCharacters ifFalse:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2630
            top isAbsolute ifFalse:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2631
                top := self class currentDirectory construct:dirPath.
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2632
            ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2633
            ^ top filesMatchingGLOBComponents:subComponents do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2634
        ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2635
        
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2636
        top isAbsolute ifFalse:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2637
            top := self class currentDirectory.
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2638
        ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2639
        count := 0.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2640
        top filesMatching:dirPath do:[:sub |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2641
            count := count + ((self / sub) filesMatchingGLOBComponents:subComponents do:aBlock)
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2642
        ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2643
        ^ count
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2644
    ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2645
    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2646
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2647
     '/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2648
     '/etc/a*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2649
     '../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2650
     '../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2651
     '../../lib*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2652
     '../../*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2653
     '../../*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2654
     '../../*java*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2655
     '../../*java*/*/Ary.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2656
     '/*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2657
     '*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2658
     '../*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2659
     './*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2660
     './*/*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2661
     '././A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2662
    "
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2663
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2664
    "Modified: / 06-02-2019 / 11:56:05 / Stefan Vogel"
24382
b6d7add521a9 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24379
diff changeset
  2665
    "Modified: / 28-06-2019 / 08:43:47 / Claus Gittinger"
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2666
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  2667
18734
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2668
filesWithSuffix:suffix do:aBlock
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2669
    "evaluate aBlock for all regular files with a given suffix
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2670
     contained in the directory represented by the receiver.
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2671
     (i.e. subdirs are ignored)"
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2672
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2673
    ^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2674
        (eachFileOrDirectory hasSuffix:suffix) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2675
            eachFileOrDirectory isRegularFile ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2676
                aBlock value: eachFileOrDirectory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2677
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  2678
        ].
18734
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2679
    ].
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2680
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2681
    "
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2682
     '.' asFilename filesWithSuffix:'so' do:[:f | Transcript showCR:f].
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2683
    "
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2684
!
91cf1b39b479 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18686
diff changeset
  2685
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2686
recursiveDirectoryContentsAsFilenamesDo:aBlock
13191
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2687
    "evaluate aBlock for all files and directories found under the receiver.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2688
     The block is invoked with the filenames as argument.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2689
     The walk is bread-first.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2690
     This excludes any entries for '.' or '..'.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2691
     Subdirectory files are included with a relative pathname.
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2692
     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
  2693
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2694
    self recursiveDirectoryContentsDo:[:relFn |
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2695
        aBlock value:(self construct:relFn)
13191
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2696
    ].
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2697
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2698
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2699
     '.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f]
13191
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2700
    "
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2701
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2702
    "Modified: / 12-09-2010 / 15:43:22 / cg"
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2703
!
10ffa6ac5505 added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents: 13139
diff changeset
  2704
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2705
recursiveDirectoryContentsAsFilenamesDo:aBlock filterForVisitingDirectories:filterOrNil
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2706
    "evaluate aBlock for all files and directories found under the receiver.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2707
     The block is invoked with the filenames as argument.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2708
     The walk is bread-first.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2709
     This excludes any entries for '.' or '..'.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2710
     Subdirectory files are included with a relative pathname.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2711
     If filterOrNil is nonNil, it is passed every directory about to be walked into;
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2712
     if it returns false, that directory is not entered.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2713
     Warning: this may take a long time to execute 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2714
     (especially with deep and/or remote fileSystems)."
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2715
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2716
    self 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2717
        recursiveDirectoryContentsDo:[:relFn |
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2718
            aBlock value:(self construct:relFn)
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2719
        ]
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2720
        filterForVisitingDirectories:filterOrNil.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2721
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2722
    "
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2723
     '.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f]
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2724
    "
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2725
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2726
    "Modified: / 12-09-2010 / 15:43:22 / cg"
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2727
!
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2728
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2729
recursiveDirectoryContentsDo:aBlock
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2730
    "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
  2731
     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
  2732
     The walk is bread-first.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2733
     This excludes any entries for '.' or '..'.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2734
     Subdirectory files are included with a relative pathname.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2735
     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
  2736
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2737
    self 
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2738
        recursiveDirectoryContentsWithPrefix:'' 
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2739
        filesDo:aBlock 
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2740
        directoriesDo:aBlock
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2741
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2742
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2743
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2744
    "
13057
4f7fa62156ac comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 12975
diff changeset
  2745
4f7fa62156ac comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 12975
diff changeset
  2746
    "Modified: / 12-09-2010 / 15:43:22 / cg"
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2747
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2748
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2749
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2750
    "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
  2751
     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
  2752
     The walk is breadth-first.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2753
     This excludes any entries for '.' or '..'.
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2754
     The argument to aBlock is a pathname relative to aPrefix.
19114
mawalch
parents: 19088
diff changeset
  2755
     A proceedable exception is raised forn non-accessible directories.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2756
     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
  2757
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2758
    self
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2759
        recursiveDirectoryContentsWithPrefix:aPrefix 
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2760
        filesDo:aBlock 
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2761
        directoriesDo:aBlock
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2762
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2763
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2764
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f]
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  2765
     '/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f]
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2766
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2767
!
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  2768
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2769
recursiveDirectoryContentsDo:aBlock filterForVisitingDirectories:filterOrNil
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2770
    "evaluate aBlock for all files and directories found under the receiver.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2771
     The block is invoked with the relative filenames as string-argument.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2772
     The walk is bread-first.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2773
     This excludes any entries for '.' or '..'.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2774
     Subdirectory files are included with a relative pathname.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2775
     If filterOrNil is nonNil, it is passed every directory about to be walked into;
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2776
     if it returns false, that directory is not entered.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2777
     Warning: this may take a long time to execute 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2778
     (especially with deep and/or remote fileSystems)."
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2779
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2780
    self 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2781
        recursiveDirectoryContentsWithPrefix:'' 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2782
        filesDo:aBlock 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2783
        directoriesDo:aBlock
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2784
        filterForVisitingDirectories:filterOrNil    
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2785
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2786
    "
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2787
     '.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f]
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2788
    "
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2789
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2790
    "Modified: / 12-09-2010 / 15:43:22 / cg"
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2791
!
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2792
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2793
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2794
    "evaluate aBlock for all files and directories found under the receiver.
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2795
     The blocks are invoked with a relative pathname as string-argument.
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2796
     The walk is breadth-first (first files, then directories).
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2797
     This excludes any entries for '.' or '..'.
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2798
     A proceedable exception is raised for non-accessible directories.
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2799
     Warning: this may take a long time to execute 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2800
     (especially with deep and/or remote fileSystems)."
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2801
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2802
    self
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2803
        recursiveDirectoryContentsWithPrefix:aPrefix 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2804
        filesDo:fileBlock 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2805
        directoriesDo:dirBlock
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2806
        filterForVisitingDirectories:nil
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2807
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2808
    "
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2809
     '.' asFilename 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2810
        recursiveDirectoryContentsWithPrefix:'bla'
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2811
        filesDo:[:f | Transcript show:'file: '; showCR:f]
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2812
        directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2813
    "
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2814
!
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2815
22500
aed0c5a72ba6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22497
diff changeset
  2816
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock 
aed0c5a72ba6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22497
diff changeset
  2817
    filterForVisitingDirectories:filterOrNil
aed0c5a72ba6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22497
diff changeset
  2818
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2819
    "evaluate aBlock for all files and directories found under the receiver.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2820
     The blocks are invoked with a relative pathname as string-argument.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2821
     The walk is breadth-first (first files, then directories).
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2822
     This excludes any entries for '.' or '..'.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2823
     A proceedable exception is raised for non-accessible directories.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2824
     If filterOrNil is nonNil, it is passed every directory about to be walked into;
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2825
     if it returns false, that directory is not entered.
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2826
     Warning: this may take a long time to execute 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2827
     (especially with deep and/or remote fileSystems).
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2828
    "
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2829
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2830
    |fileNames dirNames p|
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2831
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2832
    "/ first collect files and dirs
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2833
    fileNames := OrderedCollection new.
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2834
    dirNames := OrderedCollection new.
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2835
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2836
    self directoryContentsDo:[:f | |t|
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2837
        t := self construct:f.
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2838
        t isDirectory ifTrue:[
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2839
            (filterOrNil isNil or:[filterOrNil value:t]) ifTrue:[
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2840
                dirBlock notNil ifTrue:[
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2841
                    t isSymbolicLink ifFalse:[
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2842
                        dirNames add:f
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2843
                    ]
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2844
                ]
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2845
            ]
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2846
        ] ifFalse:[
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2847
            fileBlock notNil ifTrue:[
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2848
                fileNames add:f
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2849
            ]
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2850
        ]
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2851
    ].
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2852
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2853
    aPrefix size ~~ 0 ifTrue:[
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2854
        p := aPrefix , self separator
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2855
    ] ifFalse:[
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2856
        p := ''
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2857
    ].
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2858
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2859
    fileBlock notNil ifTrue:[
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2860
        fileNames do:[:aFile | fileBlock value:(p , aFile)].
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2861
    ].
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2862
    dirBlock notNil ifTrue:[
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2863
        dirNames do:[:dN |
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2864
            |subDir|
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2865
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2866
            subDir := (self construct:dN).
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2867
            (filterOrNil isNil or:[filterOrNil value:subDir]) ifTrue:[
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2868
                dirBlock value:(p , dN).
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2869
                subDir
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2870
                    recursiveDirectoryContentsWithPrefix:(p , dN) 
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2871
                    filesDo:fileBlock directoriesDo:dirBlock
22500
aed0c5a72ba6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22497
diff changeset
  2872
                    filterForVisitingDirectories:filterOrNil
20686
ea3d093f028d #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20678
diff changeset
  2873
            ].
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2874
        ].
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2875
    ].
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2876
    
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2877
    "
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2878
     '.' asFilename 
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2879
        recursiveDirectoryContentsWithPrefix:'bla'
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2880
        filesDo:[:f | Transcript show:'file: '; showCR:f]
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2881
        directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2882
    "
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2883
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  2884
    "Modified: / 06-02-2019 / 11:45:22 / Stefan Vogel"
19664
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2885
!
abce388b4b50 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19599
diff changeset
  2886
24235
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2887
recursiveFilesDo:fileBlock directoriesDo:dirBlock filterForVisitingDirectories:filterOrNil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2888
    "evaluate aBlock for all files and directories found under the receiver.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2889
     The blocks are invoked with a relative pathname as string-argument.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2890
     The walk is depth-first (but files first, then directories).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2891
     This excludes any entries for '.' or '..'.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2892
     A proceedable exception is raised for non-accessible directories.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2893
     If filterOrNil is nonNil, it is passed every directory about to be walked into;
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2894
     if it returns false, that directory is not entered.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2895
     Warning: this may take a long time to execute 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2896
     (especially with deep and/or remote fileSystems).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2897
     Names are enumerated in the order they appear in the folder,
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2898
     (which is not required to be sorted).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2899
    "
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2900
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2901
    self 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2902
        recursiveFilesDo:fileBlock directoriesDo:dirBlock 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2903
        filterForVisitingDirectories:filterOrNil sortedBy:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2904
    
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2905
    "
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2906
     '.' asFilename 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2907
        recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2908
        directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2909
        filterForVisitingDirectories:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2910
    "
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2911
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2912
    "Created: / 29-05-2019 / 09:58:12 / Claus Gittinger"
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2913
    "Modified (comment): / 29-05-2019 / 11:24:57 / Claus Gittinger"
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2914
!
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2915
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2916
recursiveFilesDo:fileBlock directoriesDo:dirBlock filterForVisitingDirectories:filterOrNil sortedBy:sortedByBlock
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2917
    "evaluate aBlock for all files and directories found under the receiver.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2918
     The blocks are invoked with a relative pathname as string-argument.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2919
     The walk is breadth-first (files first, then directories).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2920
     This excludes any entries for '.' or '..'.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2921
     A proceedable exception is raised for non-accessible directories.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2922
     If filterOrNil is nonNil, it is passed every directory about to be walked into;
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2923
     if it returns false, that directory is not entered.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2924
     Warning: this may take a long time to execute 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2925
     (especially with deep and/or remote fileSystems).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2926
     By default, names are enumerated in the order they appear in the folder,
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2927
     (which is not required to be sorted).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2928
     If sortedByBlock is non nil, it is applied with the file names to sort them
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2929
     (usually a block is provided to sort by name, aka [:a :b | a name < b name]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2930
     or by caseless name, like [:a :b | a name caselessBefore: b name]     
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2931
    "
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2932
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2933
    |getFilesAndDirs toDo fileNames dirNames job thisDir|
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2934
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2935
    toDo := OrderedCollection new.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2936
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2937
    getFilesAndDirs := 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2938
        [:aRoot |
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2939
            |contents fileNames dirNames wrap|
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2940
            
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2941
            "/ first collect files and dirs
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2942
            fileNames := OrderedCollection new.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2943
            dirNames := OrderedCollection new.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2944
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2945
            contents := aRoot directoryContents.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2946
            sortedByBlock notNil ifTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2947
                contents sort:[:a :b | sortedByBlock value:(aRoot construct:a) value:(aRoot construct:b)].
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2948
            ].    
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2949
            contents do:[:f | |t|
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2950
                t := aRoot construct:f.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2951
                t isDirectory ifTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2952
                    (filterOrNil isNil or:[filterOrNil value:t]) ifTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2953
                        dirBlock notNil ifTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2954
                            t isSymbolicLink ifFalse:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2955
                                dirNames add:f
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2956
                            ]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2957
                        ]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2958
                    ]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2959
                ] ifFalse:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2960
                    fileBlock notNil ifTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2961
                        fileNames add:f
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2962
                    ]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2963
                ]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2964
            ].
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2965
            toDo add:{ aRoot . fileNames . dirNames }
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2966
        ].    
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2967
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2968
    getFilesAndDirs value:self.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2969
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2970
    [toDo notEmpty] whileTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2971
        job := toDo removeFirst.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2972
        "/ process files..
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2973
        thisDir := job at:1.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2974
        fileNames := job at:2.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2975
        dirNames := job at:3.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2976
        
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2977
        fileNames do:[:fN | fileBlock value:(thisDir constructString:fN)].
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2978
        dirNames do:[:dN |
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2979
            |subDir|
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2980
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2981
            subDir := (thisDir construct:dN).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2982
            (filterOrNil isNil or:[filterOrNil value:subDir]) ifTrue:[
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2983
                dirBlock value:(subDir name).
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2984
                getFilesAndDirs value:subDir.
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2985
            ].
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2986
        ].
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2987
    ].
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2988
    
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2989
    "
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2990
     '.' asFilename 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2991
        recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2992
        directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2993
        filterForVisitingDirectories:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2994
        sortedBy:[:a :b | a name caselessBefore: b name]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2995
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2996
     '.' asFilename 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2997
        recursiveFilesDo:[:f | Transcript showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2998
        directoriesDo:[:f | Transcript showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  2999
        filterForVisitingDirectories:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3000
        sortedBy:[:a :b | a name caselessBefore: b name]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3001
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3002
     '../../..' asFilename 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3003
        recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3004
        directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3005
        filterForVisitingDirectories:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3006
        sortedBy:[:a :b | a name caselessBefore: b name]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3007
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3008
     '../../..' asFilename 
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3009
        recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3010
        directoriesDo:[:f | Transcript show:'dir: '; showCR:f]
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3011
        filterForVisitingDirectories:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3012
        sortedBy:nil
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3013
    "
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3014
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3015
    "Created: / 29-05-2019 / 10:15:40 / Claus Gittinger"
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3016
    "Modified (comment): / 29-05-2019 / 11:28:57 / Claus Gittinger"
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3017
!
210f242ffbd9 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 24101
diff changeset
  3018
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3019
withAllDirectoriesDo:aBlock
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3020
    "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
  3021
     The block is invoked with a filename-arguments.
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3022
     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
  3023
     filenames (but by creation time - on some systems).
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3024
     This excludes entries for '.' or '..'.
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  3025
     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
  3026
     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
  3027
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3028
    self isDirectory ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3029
        aBlock value:self.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3030
    ].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  3031
    self allDirectoriesDo:aBlock.
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3032
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3033
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3034
     '.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
17310
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  3035
     'IdoNOTexist' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
ebac8ce814f7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17227
diff changeset
  3036
     '/etc/hosts' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name].
5889
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3037
    "
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3038
! !
171985b0ea2f more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents: 5877
diff changeset
  3039
542
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  3040
!Filename methodsFor:'error handling'!
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  3041
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3042
fileCreationError:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3043
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3044
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3045
    "report an error that some file could not be created"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3046
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3047
    ^ OperatingSystem accessDeniedErrorSignal
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3048
        raiseRequestWith:filename?self
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3049
        errorString:(' - cannot create/write file: "%1"' bindWith:(filename ? self) asString)
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3050
!
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3051
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3052
reportError:string with:filename
1120
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3053
    "{ Pragma: +optSpace }"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3054
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3055
    "report an error"
94c803be0210 compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents: 1081
diff changeset
  3056
15192
98d237124310 class: Filename
Claus Gittinger <cg@exept.de>
parents: 15163
diff changeset
  3057
    ^ OsError
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3058
        raiseRequestWith:filename?self
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3059
        errorString:string
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3060
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3061
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3062
!Filename methodsFor:'file access'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3063
3015
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3064
appendStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3065
    "return a stream for appending to the file represented by the receiver.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3066
     If the file does not already exist, it is created.
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3067
     Same as #appendingWriteStream for ST-80 compatibility."
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3068
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3069
    ^ self appendingWriteStream
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3070
!
5df2984673db more ST0 compatibility
ca
parents: 2987
diff changeset
  3071
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3072
appendingWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3073
    "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
  3074
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3075
     if it does exist, writes are appended at the end."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3076
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3077
    ^ FileStream appendingOldFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3078
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3079
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3080
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3081
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3082
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3083
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3084
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3085
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3086
     s := '/tmp/foo' asFilename appendingWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3087
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3088
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3089
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3090
     '/tmp/foo' asFilename contents
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3091
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3092
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3093
15490
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3094
existingReadWriteStream
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3095
    "return a stream for read/write the file represented by the receiver.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3096
     If the file does not already exist, an exception is raised."
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3097
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3098
    ^ FileStream oldFileNamed:(self osNameForAccess)
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3099
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3100
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3101
     '/tmp/blaFaselQuall666666' asFilename remove.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3102
     '/tmp/blaFaselQuall666666' asFilename existingReadWriteStream.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3103
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3104
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3105
     |s|
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3106
     s := '/tmp/foo' asFilename readWriteStream.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3107
     s nextPutAll:'1234567890'; close.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3108
     s := '/tmp/foo' asFilename existingReadWriteStream.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3109
     s nextPutAll:'abcdef'; close.
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3110
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3111
     '/tmp/foo' asFilename contents inspect.
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3112
     '/tmp/foo' asFilename remove
15490
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3113
    "
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3114
!
5089229237d8 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15465
diff changeset
  3115
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3116
newReadWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3117
    "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
  3118
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3119
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3120
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3121
    ^ FileStream newFileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3122
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3123
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3124
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3125
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3126
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3127
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3128
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3129
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3130
     s := '/tmp/foo' asFilename newReadWriteStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3131
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3132
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3133
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3134
     '/tmp/foo' asFilename contents
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3135
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3136
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3137
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3138
openWithMode:anArrayOrString
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3139
    "return a stream for read/write the file represented by the receiver.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3140
     If the file does not already exist, it is created;
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3141
     if it does exist, it is truncated."
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3142
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3143
    ^ FileStream open:self osNameForAccess withMode:anArrayOrString
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3144
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3145
    "
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3146
     |s|
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3147
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3148
     s := '/tmp/foo' asFilename openWithMode:'r+'.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3149
     s nextPutAll:'1234567890'.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3150
     s close.
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3151
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3152
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3153
     '/tmp/foo' asFilename contents
15459
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3154
    "
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3155
!
4e840cc9789e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15455
diff changeset
  3156
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3157
readStream
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  3158
    "Return a stream for reading from the file represented by the receiver.
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  3159
     Raises an error if the file does not exist."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3160
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3161
    ^ FileStream readonlyFileNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3162
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3163
    "
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  3164
      '/tmp/foo' asFilename readStream
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3165
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3166
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3167
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3168
readWriteStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3169
    "return a stream for read/write the file represented by the receiver.
7828
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  3170
     If the file does not already exist, it is created.
5167f23f77f6 comment
Claus Gittinger <cg@exept.de>
parents: 7776
diff changeset
  3171
     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
  3172
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  3173
    ^ FileStream fileNamed:(self osNameForAccess)
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3174
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3175
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3176
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3177
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3178
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3179
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3180
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3181
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3182
     s := '/tmp/foo' asFilename readWriteStream.
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3183
     s nextPutAll:'abcdef'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3184
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3185
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3186
     '/tmp/foo' asFilename contents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3187
     '/tmp/foo' asFilename remove
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3188
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3189
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3190
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3191
writeStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3192
    "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
  3193
     If the file does not already exist, it is created;
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3194
     if it does exist, it is truncated."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3195
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3196
    ^ FileStream newFileForWritingNamed:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3197
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3198
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3199
     '/tmp/foo' asFilename writeStream
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3200
    "
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3201
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3202
    "
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3203
     |s|
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3204
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3205
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3206
     s nextPutAll:'1234567890'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3207
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3208
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3209
     s := '/tmp/foo' asFilename writeStream.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3210
     s nextPutAll:'12345'.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3211
     s close.
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3212
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3213
     '/tmp/foo' asFilename contents
5720
0ddf31b08b3b comments and examples
Claus Gittinger <cg@exept.de>
parents: 5642
diff changeset
  3214
    "
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3215
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3216
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3217
!Filename methodsFor:'file access - migration'!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3218
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3219
appendingWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3220
    "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
  3221
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3222
     if it does exist, writes are appended at the end.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3223
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3224
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3225
     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
  3226
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3227
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3228
    ^ [
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3229
        FileStream appendingOldFileNamed:(self osNameForAccess)
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3230
      ] on:FileStream openErrorSignal do:[:ex| nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3231
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3232
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3233
newReadWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3234
    "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
  3235
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3236
     if it does exist, it is truncated.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3237
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3238
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3239
     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
  3240
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3241
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3242
    ^ [
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3243
         FileStream newFileNamed:(self osNameForAccess)
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3244
    ] on:FileStream openErrorSignal do:[:ex|nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3245
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3246
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3247
readStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3248
    "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
  3249
     If the file does not already exist, nil is returned.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3250
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3251
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3252
     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
  3253
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3254
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3255
    ^ [
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3256
        FileStream readonlyFileNamed:(self osNameForAccess)
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3257
    ] on:FileStream openErrorSignal do:[:ex|nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3258
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3259
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3260
     '/tmp/foo' asFilename readStreamOrNil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3261
     '/tmp/foo' asFilename readStream
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3262
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3263
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3264
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3265
readWriteStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3266
    "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
  3267
     If the file does not already exist, it is created.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3268
     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
  3269
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3270
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3271
     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
  3272
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3273
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3274
    ^ [
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3275
        FileStream fileNamed:(self osNameForAccess)
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3276
    ] on:FileStream openErrorSignal do:[:ex|^ nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3277
!
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3278
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3279
writeStreamOrNil
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3280
    "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
  3281
     If the file does not already exist, it is created;
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3282
     if it does exist, it is truncated.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3283
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3284
     Return nil, if the file cannot be opened.
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3285
     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
  3286
     instead of an exception when an error occurs."
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3287
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3288
    ^ [
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3289
        FileStream newFileForWritingNamed:(self osNameForAccess)
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  3290
    ] on:FileStream openErrorSignal do:[:ex|^ nil].
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3291
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3292
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3293
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3294
     '/etc/foo' asFilename writeStreamOrNil
8140
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3295
    "
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3296
! !
7cc7ac5f29ca Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents: 8095
diff changeset
  3297
16310
c58c06bf77b6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16272
diff changeset
  3298
!Filename methodsFor:'file access rights'!
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3299
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3300
accessRights
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3301
    "return the access rights of the file as opaque data
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3302
     (SmallInteger in unix/linux)"
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3303
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3304
    |access|
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3305
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  3306
    access := OperatingSystem accessModeOf:self osNameForAccess.
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3307
    access isOSErrorHolder ifTrue:[
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3308
        access reportProceedableError:'get access rights failed'.
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3309
    ].
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3310
    ^ access.
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3311
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3312
    "
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  3313
     'Make.proto' asFilename accessRights printStringRadix:8
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  3314
     'foo' asFilename accessRights printStringRadix:8
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  3315
    "
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  3316
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  3317
    "Modified (comment): / 12-04-2019 / 12:05:34 / Stefan Vogel"
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3318
!
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3319
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3320
accessRights:opaqueData
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3321
    "set the access rights of the file to opaqueData,
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3322
     which is normally retrieved by Filename>>#accessRights."
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3323
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3324
    |osErrorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3325
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3326
    osErrorHolder := OperatingSystem changeAccessModeOf:self osNameForFile to:opaqueData.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3327
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3328
        osErrorHolder reportProceedableError:'change access rights failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3329
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3330
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3331
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3332
    "
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3333
     |rights|
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3334
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3335
     rights := 'Make.proto' asFilename accessRights.
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3336
     'Make.proto' asFilename accessRights:rights.
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3337
    "
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3338
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3339
    "Modified: / 5.5.1999 / 13:41:21 / cg"
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3340
!
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3341
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3342
addAccessRights:aCollection
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3343
    "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
  3344
     by the receiver. The argument must be a collection of symbols,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3345
     such as #readUser, #writeGroup etc."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3346
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3347
    |access osName osErrorHolder|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3348
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  3349
    osName := self osNameForFile.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  3350
    access := OperatingSystem accessModeOf:osName.
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3351
    access isOSErrorHolder ifTrue:[
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3352
        access reportProceedableError:'get access rights failed'.
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3353
    ].
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3354
        
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3355
    aCollection do:[:accessSymbol |
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3356
        access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol).
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3357
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3358
    osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3359
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3360
        osErrorHolder reportProceedableError:'change access rights failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3361
    ].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3362
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
     'foo' asFilename writeStream close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3365
     'foo' asFilename addAccessRights:#(readUser readGroup readOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3366
     'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3367
     'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3368
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3369
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3370
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3371
makeExecutable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3372
    "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
  3373
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3374
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3375
    ^ self addAccessRights:#(executeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3376
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3377
    "Created: 9.1.1996 / 15:32:47 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3378
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3379
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3380
makeExecutableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3381
    "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
  3382
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3383
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3384
    ^ self addAccessRights:#(executeUser executeGroup executeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3385
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3386
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3387
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3388
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3389
makeExecutableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3390
    "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
  3391
     For directories, execution means: 'allow changing into it'"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3392
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3393
    ^ self addAccessRights:#(executeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3394
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3395
    "Created: 9.1.1996 / 15:32:28 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3396
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3397
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3398
makeReadable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3399
    "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
  3400
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3401
    ^ self addAccessRights:#(readUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3402
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3403
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3404
makeReadableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3405
    "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
  3406
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3407
    ^ self addAccessRights:#(readUser readGroup readOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3408
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3409
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3410
makeReadableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3411
    "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
  3412
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3413
    ^ self addAccessRights:#(readGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3414
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3415
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3416
makeUnwritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3417
    "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
  3418
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3419
    ^ self removeAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3420
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3421
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3422
makeWritable
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3423
    "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
  3424
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3425
    ^ self addAccessRights:#(writeUser)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3426
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3427
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3428
makeWritableForAll
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3429
    "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
  3430
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3431
    ^ self addAccessRights:#(writeUser writeGroup writeOthers)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3432
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3433
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3434
makeWritableForGroup
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3435
    "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
  3436
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3437
    ^ self addAccessRights:#(writeGroup)
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3438
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3439
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3440
removeAccessRights:aCollection
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3441
    "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
  3442
     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
  3443
     such as #readUser, #writeGroup etc.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3444
     Raises an exception if not successful."
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3445
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3446
    |access osName osErrorHolder|
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3447
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3448
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3449
    access := OperatingSystem accessModeOf:osName.
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3450
    access isOSErrorHolder ifTrue:[
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3451
        access reportProceedableError:'get access rights failed'.
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3452
    ].
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3453
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3454
    aCollection do:[:accessSymbol |
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3455
        access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3456
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3457
    osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3458
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3459
        osErrorHolder reportProceedableError:'change access rights failed'.
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3460
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3461
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3462
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3463
     'foo' asFilename writeStream close.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3464
     'foo' asFilename removeAccessRights:#(readUser readGroup readOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3465
     'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3466
     'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers).
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3467
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3468
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3469
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3470
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3471
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3472
symbolicAccessRights
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3473
    "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
  3474
     The returned collection consists of symbols like:
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3475
        #readUser, #writeGroup etc."
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3476
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3477
    |access osName|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3478
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3479
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3480
    access := OperatingSystem accessModeOf:osName.
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3481
    access isOSErrorHolder ifTrue:[
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3482
        access reportProceedableError:'get access rights failed'.
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3483
    ].
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3484
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3485
    ^
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3486
        #(  readUser writeUser executeUser
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3487
            readGroup writeGroup executeGroup
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3488
            readOthers writeOthers executeOthers
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3489
          ) select:[:eachSymbolicAccessSymbol |
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3490
                access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol).
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3491
            ].
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3492
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3493
    "
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3494
     'Make.proto' asFilename symbolicAccessRights
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3495
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3496
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3497
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3498
!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3499
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3500
symbolicAccessRights:aCollectionOfSymbols
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3501
    "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
  3502
     The collection must consist of symbols like:
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3503
        #readUser, #writeGroup etc."
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3504
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3505
    |access osName osErrorHolder|
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3506
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3507
    osName := self osNameForFile.
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3508
    access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol |
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3509
                bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol)
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3510
              ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3511
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3512
    osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3513
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3514
        osErrorHolder reportProceedableError:'change access rights failed'.
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3515
    ].
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3516
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3517
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3518
     |rights|
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3519
21071
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3520
     rights := 'Make.proto' asFilename symbolicAccessRights.
6870b933f645 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21064
diff changeset
  3521
     'Make.proto' asFilename symbolicAccessRights:(rights , #(executeOthers)).
6223
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3522
    "
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3523
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3524
    "Modified: / 5.5.1999 / 13:41:21 / cg"
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3525
! !
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3526
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3527
!Filename methodsFor:'file operations'!
e0ea936d07c0 more for file accessRights
Claus Gittinger <cg@exept.de>
parents: 6139
diff changeset
  3528
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3529
appendTo:streamOrNewName
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3530
    "append the file - the argument must be a stream or convertable to a filename.
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  3531
     Raises an exception, if an error occurs."
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  3532
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3533
    |inStream outStream outStreamToClose resetBinary|
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3534
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3535
    resetBinary := false.
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  3536
    inStream := self readStream.
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  3537
    [
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3538
        streamOrNewName isStream ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3539
            outStream := streamOrNewName.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3540
            resetBinary := (outStream binary:true) not. 
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3541
            outStream isBinary ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3542
                "Transcript ignores the binary setting"    
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3543
                inStream binary.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3544
            ] ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3545
                resetBinary := false.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3546
            ].
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3547
        ] ifFalse:[
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3548
            outStream := outStreamToClose := streamOrNewName asFilename appendingWriteStream.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3549
            "switch both streams to binary mode, in order to use
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3550
             a faster ExternalStream buffer in #copyToEndInto:"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3551
            outStream binary.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3552
            inStream binary.
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3553
        ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3554
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3555
        inStream copyToEndInto:outStream.
7329
0c9cf1bbfc35 New: #appendTo:
Stefan Vogel <sv@exept.de>
parents: 7308
diff changeset
  3556
    ] ensure:[
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3557
        inStream close.
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3558
        outStreamToClose notNil ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3559
            outStreamToClose close
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3560
        ] ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3561
            resetBinary ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3562
                outStream binary:false.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3563
            ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3564
        ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3565
    ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3566
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3567
    "
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3568
     'Make.proto' asFilename appendTo:'/tmp/Makefile.foo'.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3569
     'Make.proto' asFilename appendTo:Transcript.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3570
     'Make.proto' asFilename appendTo:'/tmp/Makefile.foo' asFilename
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3571
     'Make.proto' asFilename appendTo:'/dev/null'
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3572
    "
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3573
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3574
    "Modified: / 23-12-1999 / 21:52:36 / cg"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3575
    "Modified (comment): / 13-03-2019 / 19:45:03 / Stefan Vogel"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3576
!
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3577
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3578
copyTo:streamOrNewName
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3579
    "Copy the file's contents into another file or stream.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3580
     The argument must be a stream or convertable to a filename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3581
     Raises an exception, if an error occurs."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3582
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3583
    |inStream outStream outStreamToClose newFilename newNameAlreadyExists resetBinary|
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3584
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3585
    streamOrNewName isStream ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3586
        outStream := streamOrNewName.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3587
        "Contents is not copied if the out stream represent same file as myself."
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3588
        (outStream isFileStream 
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3589
         and:[outStream asFilename pathName = self pathName]) ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3590
            ^ self
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3591
        ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3592
    ] ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3593
        newFilename := streamOrNewName asFilename.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3594
        "Contents is not copied if newName represents the same file as myself."
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3595
        newFilename pathName = self pathName ifTrue:[ 
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3596
            ^ self 
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3597
        ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3598
        newNameAlreadyExists := newFilename exists.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3599
        (newNameAlreadyExists and:[newFilename isDirectory]) ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3600
            newFilename := newFilename construct:(self baseName).
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3601
            newNameAlreadyExists := newFilename exists.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3602
        ].
19957
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3603
    ].
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3604
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3605
    inStream := self readStream.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3606
    inStream isNil ifTrue:[
19957
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3607
        "open failed, but somenone did a proceed for the OpenError.
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3608
         Ignore this file but continue in order to copy the rest when
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3609
         doing a recursive copy"
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3610
        ^ self.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3611
    ].
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3612
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  3613
    [
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3614
        newFilename notNil ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3615
            "argument is a name"    
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3616
            outStream := outStreamToClose := newFilename writeStream.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3617
            newNameAlreadyExists ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3618
                "ignore the error - may occur when copying to a network drive"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3619
                OsError catch:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3620
                    "would be nice to keep the access rights of the original test suite"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3621
                    newFilename accessRights:self accessRights.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3622
                ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3623
            ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3624
            "switch both streams to binary mode, in order to use
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3625
             a faster ExternalStream buffer in #copyToEndInto:"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3626
            outStream binary:true; buffered:false.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3627
            inStream binary:true.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3628
        ] ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3629
            "argument is a Stream"    
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3630
            resetBinary := (outStream binary:true) not.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3631
            outStream isBinary ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3632
                "internalStreams ignore the binary setting..."    
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3633
                inStream binary:true.
19957
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3634
            ].
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3635
        ].
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3636
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3637
        inStream buffered:false.
19957
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3638
        inStream copyToEndInto:outStream.
6804
caf6a4521d4c added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents: 6803
diff changeset
  3639
    ] ensure:[
19957
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3640
        inStream close.
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3641
        outStreamToClose notNil ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3642
            outStreamToClose close
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3643
        ] ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3644
            resetBinary ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3645
                outStream binary:false.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3646
            ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3647
        ].
615
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
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3650
    "
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3651
     'Make.proto' asFilename copyTo:'/tmp/Makefile.foo'
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3652
     'Make.proto' asFilename copyTo:'/tmp'
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3653
     'Make.proto' asFilename copyTo:Transcript
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3654
     'smalltalk' asFilename copyTo:'/dev/null'
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3655
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3656
10020
3cd498c53ad9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 9912
diff changeset
  3657
    "Modified: / 10-09-2004 / 09:49:28 / janfrog"
19957
1d663e2ea5bc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 19821
diff changeset
  3658
    "Modified: / 06-06-2016 / 12:15:25 / cg"
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3659
    "Modified: / 13-03-2019 / 22:51:26 / Stefan Vogel"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3660
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3661
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3662
copyToStream:outStream
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3663
    "Copy the file's contents into outStream.
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3664
     Raises an exception, if an error occurs."
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3665
15858
db1336645839 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15846
diff changeset
  3666
    |inStream resetBinary|
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3667
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3668
    "Contents is not copied if newName represent same file as me."
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3669
    (outStream isFileStream 
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3670
     and:[outStream fileName pathName = self pathName]) ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3671
        ^ self
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3672
    ].
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3673
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3674
    inStream := self readStream.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3675
    [
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3676
        resetBinary := (outStream binary:true) not.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3677
        outStream isBinary ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3678
            "internal streams ignore the #binary:true setting"    
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3679
            inStream binary:true. "inStream buffered:false."
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3680
        ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3681
        inStream copyToEndInto:outStream.
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3682
    ] ensure:[
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3683
        inStream close.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3684
        resetBinary ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3685
            outStream binary:false.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3686
        ].
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3687
    ].
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3688
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3689
    "
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3690
     |out|
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3691
     out := FileStream newTemporary.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3692
     'Make.proto' asFilename copyToStream:out.
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3693
     out reset; contents
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3694
    "
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3695
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3696
    "Modified: / 13-03-2019 / 19:57:11 / Stefan Vogel"
15465
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3697
!
2fc958e10857 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15459
diff changeset
  3698
6983
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3699
createAsEmptyFile
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  3700
    "create an empty file with the receiver's name.
6983
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3701
     Raises an exception if not successful
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3702
    (either already existing or creation not possible)"
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3703
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3704
    |writeStream|
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3705
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3706
    self exists ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3707
        OperatingSystem accessDeniedErrorSignal
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3708
            raiseRequestWith:self
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3709
            errorString:(' - file exists: ' , self asString).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3710
        ^ self
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3711
    ].
6983
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3712
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3713
    FileStream openErrorSignal handle:[:ex|
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3714
        self fileCreationError:self.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3715
        ^ self
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3716
    ] do:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3717
        writeStream := self newReadWriteStream.
6983
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3718
    ].
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3719
    writeStream close.
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3720
!
c8c851f37aec createEmpty
Claus Gittinger <cg@exept.de>
parents: 6978
diff changeset
  3721
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3722
createAsHardLinkTo:linkFilenameString
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3723
    "create a directory with the receiver's name.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3724
     Raises an exception if not successful"
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3725
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3726
    |errorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3727
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3728
    errorHolder := OperatingSystem createHardLinkFrom:linkFilenameString asFilename osName to:self osName.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3729
    errorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3730
        errorHolder reportProceedableError:'hard link failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3731
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3732
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3733
    "
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3734
        '/tmp/link' asFilename createAsHardLinkTo:'bla'
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3735
    "
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3736
!
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3737
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3738
createAsSymbolicLinkTo:linkFilenameString
23057
d60063e6cf9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23043
diff changeset
  3739
    "create a symbolic link named linkFilenameString which points to me
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3740
     Raises an exception if not successful"
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3741
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3742
    |errorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3743
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3744
    errorHolder := OperatingSystem createSymbolicLinkFrom:linkFilenameString asFilename osName to:self osName.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3745
    errorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3746
        errorHolder reportError:'symbolic link failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3747
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3748
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3749
    "
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3750
        '/tmp/link' asFilename createAsSymbolicLinkTo:'bla'
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3751
    "
23057
d60063e6cf9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23043
diff changeset
  3752
d60063e6cf9a #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23043
diff changeset
  3753
    "Modified (comment): / 07-06-2018 / 17:16:01 / Claus Gittinger"
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3754
!
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3755
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3756
makeDirectory
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  3757
    "create a directory with the receiver's name.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3758
     Raises an exception if not successful"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3759
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3760
    |osErrorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3761
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3762
    osErrorHolder := OperatingSystem createDirectory:(self osNameForDirectory).
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3763
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3764
        "/
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3765
        "/ could have existed before ...
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3766
        "/
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3767
        (self exists and:[self isDirectory]) ifFalse:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3768
            osErrorHolder reportProceedableError:'make directory failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3769
        ]
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3770
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3771
    ^ nil
1970
Claus Gittinger <cg@exept.de>
parents: 1969
diff changeset
  3772
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3773
    "Modified: / 5.5.1999 / 13:36:33 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3774
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3775
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3776
moveFileTo:newName
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3777
    "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
  3778
     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
  3779
     Raise an exception if not successful.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3780
     (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
  3781
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3782
    [self renameTo:newName]
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3783
        on:OsError
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3784
        do:[:ex |
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3785
            ex creator == OperatingSystem fileNotFoundErrorSignal ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3786
                ex reject
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3787
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3788
            self safeCopyTo:newName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3789
            self remove
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3790
        ].
6996
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3791
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3792
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3793
     |f s|
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3794
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3795
     f := '/tmp/foo' asFilename.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3796
     s := f writeStream.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3797
     s nextPutLine:'hello'.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3798
     s close.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3799
     f renameTo:'./foo'
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3800
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3801
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3802
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3803
     |f s|
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3804
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3805
     f := '/tmp/foo' asFilename.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3806
     s := f writeStream.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3807
     s nextPutLine:'hello'.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3808
     s close.
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3809
     f moveTo:'./foo'
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3810
    "
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3811
!
720a54a2a358 move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents: 6995
diff changeset
  3812
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3813
moveTo:newNameArg
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3814
    "copy the file represented by the receiver, then delete it.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3815
     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
  3816
     Raise an exception if not successful.
3d801043be3f dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents: 5577
diff changeset
  3817
     (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
  3818
16490
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3819
    |newName|
1be874f7ae34 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16485
diff changeset
  3820
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3821
    newName := newNameArg asFilename.
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3822
    [self renameTo:newName]
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3823
        on:(OSErrorHolder inappropriateReferentSignal)
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3824
        do:[:ex |
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3825
            "handle renames accross device boundaries (Unix. cross device link)"
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3826
            self isDirectory ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3827
                self recursiveMoveDirectoryTo:newName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3828
            ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3829
                self safeCopyTo:newName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3830
                self remove.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3831
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  3832
        ].
5507
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3833
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3834
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3835
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3836
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3837
     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
  3838
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3839
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3840
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3841
     f renameTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3842
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3843
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3844
    "
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3845
     |f s|
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3846
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3847
     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
  3848
     s := f writeStream.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3849
     s nextPutLine:'hello'.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3850
     s close.
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3851
     f moveTo:'./foo'
e8c61b1741c6 in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents: 5303
diff changeset
  3852
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3853
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3854
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3855
recursiveCopyTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3856
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3857
     Otherwise, copy the directory and recursively
12975
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3858
     all of its subfiles/subdirectories.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3859
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3860
     Raises an exception if not successful.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3861
     Do not resolve symbolic links.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3862
     If a whole directory is to be copied and the destination directory
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3863
     does not exist, it will be created."
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3864
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3865
    |ok destinationFilename|
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3866
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3867
    destinationFilename := destination asFilename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3868
    self isDirectory ifFalse:[
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3869
        self copyTo:destinationFilename.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3870
        ^ self.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3871
    ].
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3872
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3873
    "/ typically, an 'cp -r' is faster;
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3874
    "/ 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
  3875
    "/ fallBack doing a manual directory walk.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3876
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3877
    ok := OperatingSystem
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3878
            recursiveCopyDirectory:(self osNameForDirectory)
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3879
            to:(destinationFilename osNameForDirectory).
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3880
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3881
    ok ifFalse:[
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3882
        self recursiveCopyWithoutOSCommandTo:destinationFilename
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3883
    ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3884
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3885
    "
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3886
        '.' asFilename recursiveCopyTo:'/temp/xxx'.
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3887
    "
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3888
12975
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3889
    "Created: / 05-05-1999 / 13:35:01 / cg"
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3890
    "Modified: / 31-05-1999 / 13:11:34 / cg"
8303274002a8 comment/format in: #recursiveCopyTo:
sr
parents: 12974
diff changeset
  3891
    "Modified: / 29-07-2010 / 12:41:06 / sr"
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3892
    "Modified: / 13-03-2019 / 20:04:44 / Stefan Vogel"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3893
!
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3894
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3895
recursiveCopyWithoutOSCommandTo:destination
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3896
    "if I represent a regular file, copy it.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3897
     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
  3898
     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
  3899
     Raises an exception if not successful.
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3900
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3901
     Do not resolve symbolic links.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  3902
     If a whole directory is to be copied and the destination directory
17143
5b1217eaafa7 class: Filename
Stefan Vogel <sv@exept.de>
parents: 17113
diff changeset
  3903
     does not exist, it will be created."
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3904
12529
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3905
    |destinationFilename|
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3906
Stefan Vogel <sv@exept.de>
parents: 12437
diff changeset
  3907
    destinationFilename := destination asFilename.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3908
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3909
    self isDirectory ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3910
        "plain file copy"    
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3911
        self copyTo:destinationFilename.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3912
        ^ self.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3913
    ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3914
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3915
    "copy a whole directory tree"
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3916
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3917
    destinationFilename exists ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3918
        destinationFilename makeDirectory.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3919
        OsError catch:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3920
            destinationFilename accessRights:self accessRights.
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3921
        ].
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3922
    ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3923
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3924
    self directoryContentsDo:[:aFilenameString |
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3925
        |src srcInfo dst|
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3926
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3927
        src := self construct:aFilenameString.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3928
        dst := destinationFilename construct:aFilenameString.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3929
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3930
        srcInfo := src linkInfo.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3931
        srcInfo isDirectory ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3932
            src recursiveCopyWithoutOSCommandTo:dst
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3933
        ] ifFalse:[srcInfo isSymbolicLink ifTrue:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3934
            dst
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3935
                remove;
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3936
                createAsSymbolicLinkTo:srcInfo path.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3937
        ] ifFalse:[
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3938
            src copyTo:dst.
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3939
        ]].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3940
    ].
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3941
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3942
    "
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3943
     '.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3944
     'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'.
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3945
    "
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3946
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  3947
    "Modified: / 31-05-1999 / 18:12:31 / cg"
23911
90ff359c758e #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23867
diff changeset
  3948
    "Modified (format): / 13-03-2019 / 20:12:18 / Stefan Vogel"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3949
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  3950
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3951
recursiveMakeDirectory
18490
ec5c1c050681 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18272
diff changeset
  3952
    "create a directory with the receiver's name and all required intermediate
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3953
     directories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3954
     Raises an exception if not successful."
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3955
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3956
    |osErrorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3957
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3958
    osErrorHolder := OperatingSystem recursiveCreateDirectory:(self osNameForDirectory).
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3959
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3960
        osErrorHolder reportProceedableError:'recursive makedir failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3961
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3962
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3963
    "
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3964
        'k:\bla\quark' asFilename recursiveMakeDirectory
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3965
    "
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3966
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3967
    "Created: / 27.11.1995 / 23:36:40 / cg"
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  3968
    "Modified: / 5.5.1999 / 13:38:42 / cg"
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3969
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3970
    "
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3971
        'C:\windows\bla\xx' asFilename recursiveMakeDirectory
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3972
        'C:\windows\bla' asFilename recursiveRemoveAll
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  3973
    "
659
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3974
!
d85bed1960be added recursiveMakeDirectory
Claus Gittinger <cg@exept.de>
parents: 630
diff changeset
  3975
24008
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3976
recursiveMakeDirectoryForEachCreatedDo:aOneArgBlock
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3977
    "create a directory with the receiver's name and all required intermediate directories. 
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3978
     For each created directory evaluate aOneArgBlock with the
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3979
     filename of the created directory.
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3980
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3981
     Raises an exception if not successful."
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3982
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3983
    |osErrorHolder|
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3984
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3985
    osErrorHolder := OperatingSystem 
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3986
                        recursiveCreateDirectory:(self osNameForDirectory)
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3987
                        forEachCreatedDo:aOneArgBlock.
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3988
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3989
    osErrorHolder notNil ifTrue:[
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3990
        osErrorHolder reportProceedableError:'recursive makedir failed'.
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3991
    ].
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3992
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3993
    "
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3994
        '/tmp/bla/fasel/murks' asFilename recursiveMakeDirectoryForEachCreatedDo:[:name| Transcript show:'Created: '; showCR:name].
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3995
        '/tmp/bla' asFilename recursiveRemove.
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3996
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3997
        'k:\bla\quark' asFilename recursiveMakeDirectory
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3998
    "
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  3999
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4000
    "Created: / 27.11.1995 / 23:36:40 / cg"
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4001
    "Modified: / 5.5.1999 / 13:38:42 / cg"
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4002
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4003
    "
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4004
        'C:\windows\bla\xx' asFilename recursiveMakeDirectory
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4005
        'C:\windows\bla' asFilename recursiveRemoveAll
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4006
    "
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4007
!
cd8978bc0fba #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23939
diff changeset
  4008
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4009
recursiveMoveDirectoryTo:newName
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4010
    "recursively copy the directory represented by the receiver, then delete it.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4011
     This is different to renaming in case of cross device moves.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4012
     Raise an exception if not successful.
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4013
     (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
  4014
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4015
    [self renameTo:newName]
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4016
        on:OsError
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4017
        do:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4018
            self recursiveCopyTo:newName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4019
            self recursiveRemove
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4020
        ].
6997
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4021
!
b8c2bf07f9c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 6996
diff changeset
  4022
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4023
recursiveRemove
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  4024
    "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
  4025
     Otherwise, remove the directory and all of its subfiles/subdirectories.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4026
     Raise an exception if not successful."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4027
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4028
    |ok|
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4029
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4030
    "/ typically, an 'rm -rf' is faster and removes better;
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4031
    "/ however, if the command fails (or the OS does not support it),
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4032
    "/ fallBack doing a manual directory walk.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4033
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4034
    ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory).
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4035
    ok ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4036
        self recursiveRemoveWithoutOSCommand
18952
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4037
    ].
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4038
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4039
    "
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4040
     'foo/bar' asFilename recursiveMakeDirectory.
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4041
     'foo' asFilename remove.
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4042
     self assert:('foo' asFilename exists not).
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4043
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4044
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4045
     'foo' asFilename recursiveRemove.
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4046
     'foo/bar' asFilename recursiveMakeDirectory.
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4047
     'foo' asFilename recursiveRemove.
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4048
     self assert:('foo' asFilename exists not).
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4049
    "
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4050
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4051
    "Created: / 14.11.1995 / 11:19:29 / cg"
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4052
    "Modified: / 5.5.1999 / 13:43:35 / cg"
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4053
!
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4054
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4055
recursiveRemoveAll
13247
9e47a0e73ba4 comment/format in: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13246
diff changeset
  4056
    "Remove all of my subfiles/subdirectories.
3302
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4057
     Raise an error if not successful.
0a7c13913226 try OS-remove first,
Claus Gittinger <cg@exept.de>
parents: 3299
diff changeset
  4058
     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
  4059
     command to do the remove."
3299
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  4060
5abe74e42d94 recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents: 3171
diff changeset
  4061
    self isDirectory ifTrue:[
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4062
        self directoryContentsAsFilenamesDo:[:eachFilename |
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4063
            OsError handle:[:ex |
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4064
                eachFilename isDirectory ifFalse:[ ex reject ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4065
                eachFilename
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4066
                    recursiveRemoveAll;
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4067
                    removeDirectory.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4068
            ] do:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4069
                eachFilename remove
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4070
            ].
18952
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4071
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4072
"/            eachFilename isDirectory ifTrue:[
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4073
"/                eachFilename recursiveRemoveWithoutOSCommand
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4074
"/            ] ifFalse:[
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4075
"/                eachFilename remove
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4076
"/            ].
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4077
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4078
    ].
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4079
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4080
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4081
     'foo' asFilename makeDirectory.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4082
     'foo/bar' asFilename writeStream close.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4083
     'foo' asFilename remove
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4084
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4085
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4086
     'foo' asFilename makeDirectory.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4087
     'foo/bar' asFilename writeStream close.
18952
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4088
     'foo' asFilename recursiveRemove.
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4089
     self assert:('foo' asFilename exists not).
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4090
    "
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4091
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4092
    "Created: / 25-01-2011 / 16:42:15 / cg"
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4093
!
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4094
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4095
recursiveRemoveWithoutOSCommand
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4096
    "if I represent a regular file, remove it.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4097
     Otherwise, remove the directory and all of its subfiles/subdirectories.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4098
     Raise an error if not successful.
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4099
     This one walks down the directory hierarchy, not using any OS
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4100
     command to do the remove."
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4101
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4102
    self
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4103
        recursiveRemoveAll;
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4104
        remove.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4105
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4106
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4107
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4108
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  4109
     'foo' asFilename remove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4110
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4111
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4112
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4113
     'foo/bar' asFilename writeStream close.
4940
c9c75e550748 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4939
diff changeset
  4114
     'foo' asFilename recursiveRemove
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4115
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4116
13246
3be09aea2c0f added: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13203
diff changeset
  4117
    "Created: / 25-02-1998 / 19:50:40 / cg"
13949
b82c0fc2b875 changed:
Claus Gittinger <cg@exept.de>
parents: 13877
diff changeset
  4118
    "Modified: / 19-01-2012 / 17:18:28 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4119
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4120
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4121
remove
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  4122
    "remove the file/directory.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4123
     Raises an exception if not successful.
845
6bcb2386d05a commentary
Claus Gittinger <cg@exept.de>
parents: 844
diff changeset
  4124
     Use #recursiveRemove in order to (recursively) remove non empty directories."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4125
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4126
    |linkInfo osName osErrorHolder|
8741
d3f70a668435 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8738
diff changeset
  4127
18952
c7e4edd352f8 #REFACTORING
Stefan Vogel <sv@exept.de>
parents: 18734
diff changeset
  4128
    osName := self osNameForAccess.
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4129
    osErrorHolder := OperatingSystem removeFile:osName.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4130
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4131
        linkInfo := self linkInfo.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4132
        linkInfo isNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4133
            "file does not exist - no error"
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4134
            ^ self.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4135
        ] ifFalse:[linkInfo isDirectory ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4136
            osErrorHolder := OperatingSystem removeDirectory:osName
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4137
        ]].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4138
        osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4139
            self exists ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4140
                osErrorHolder reportProceedableError:'remove failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4141
            ]
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4142
        ]
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4143
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4144
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4145
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4146
     (FileStream newFileNamed:'foo') close.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4147
     'foo' asFilename remove
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4148
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4149
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4150
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4151
     'foo' asFilename makeDirectory.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4152
     'foo/bar' asFilename writeStream close.
8738
4c100f8830b1 Save a system call in #remove.
Stefan Vogel <sv@exept.de>
parents: 8679
diff changeset
  4153
     'foo' asFilename remove.   'expect an exception'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4154
     'foo' asFilename recursiveRemove.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4155
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4156
13793
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  4157
    "Modified: / 20-11-1997 / 17:40:22 / stefan"
3f1c660956ce added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents: 13781
diff changeset
  4158
    "Modified: / 11-10-2011 / 10:20:01 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4159
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4160
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4161
removeDirectory
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4162
    "remove the directory.
21441
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4163
     Raises an exception if not successful (or if it's not a directory).
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  4164
     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
  4165
     Use #recursiveRemove in order to (recursively) remove non empty directories."
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4166
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4167
    |osErrorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4168
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4169
    osErrorHolder := OperatingSystem removeDirectory:self osNameForAccess.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4170
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4171
        self exists ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4172
            osErrorHolder reportProceedableError:'remove directory failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4173
        ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4174
    ].
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4175
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4176
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4177
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4178
     (FileStream newFileNamed:'foo') close.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4179
     'foo' asFilename removeDirectory
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4180
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4181
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4182
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4183
     'foo' asFilename writeStream close.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4184
     'foo' asFilename removeDirectory
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4185
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4186
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4187
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4188
     'foo' asFilename makeDirectory.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4189
     'foo/bar' asFilename writeStream close.
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4190
     ('foo' asFilename remove) ifFalse:[
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4191
        Transcript showCR:'could not remove foo'
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4192
     ]
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4193
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4194
21441
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4195
    "Modified: / 20-11-1997 / 17:40:22 / stefan"
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4196
    "Modified: / 05-05-1999 / 13:41:12 / cg"
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4197
    "Modified (comment): / 13-02-2017 / 20:19:10 / cg"
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4198
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4199
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4200
removeFile
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4201
    "remove the file.
21441
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4202
     Raises an exception if not successful (or if it's not a file).
5596
4168727b2da4 comments
Claus Gittinger <cg@exept.de>
parents: 5595
diff changeset
  4203
     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
  4204
     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
  4205
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4206
    |osErrorHolder|
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4207
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4208
    osErrorHolder := OperatingSystem removeFile:self osNameForAccess.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4209
    osErrorHolder notNil ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4210
        self exists ifTrue:[
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4211
            osErrorHolder reportProceedableError:'remove of file failed'.
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4212
        ].
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4213
    ].
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4214
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4215
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4216
     (FileStream newFileNamed:'foo') close.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4217
     'foo' asFilename removeFile
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4218
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4219
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4220
    "
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4221
     'foo' asFilename makeDirectory.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4222
     'foo' asFilename removeFile
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4223
    "
21441
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4224
ff5dc8186e55 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 21390
diff changeset
  4225
    "Modified (comment): / 13-02-2017 / 20:19:15 / cg"
5595
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4226
!
b80d12c4983b added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents: 5594
diff changeset
  4227
21045
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4228
renameTo:newName
22503
f1351a3f1466 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22500
diff changeset
  4229
    "rename the file - the argument must be convertable to a filename.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  4230
     Raises an exception if not successful.
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  4231
     If newName already exists, it will be replaced by myself."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4232
21045
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4233
    |errorHolder|
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4234
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4235
    errorHolder := OperatingSystem
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4236
                        renameFile:(self osNameForFile)
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4237
                        to:(newName asFilename osNameForFile).
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4238
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4239
    errorHolder notNil ifTrue:[
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4240
        errorHolder
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4241
            parameter:self;
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4242
            reportProceedableError:'rename failed'.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4243
    ].
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4244
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4245
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4246
     '/tmp/foo' asFilename renameTo:'/tmp/bar'
21045
fc59c941ec72 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21023
diff changeset
  4247
     '/tmp/' asFilename renameTo:'/etc/bar'
21023
22ed5c14aa99 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 20798
diff changeset
  4248
     'C:\windows' asFilename renameTo:'C:\win'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4249
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4250
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4251
    "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
  4252
!
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4253
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4254
safeCopyTo:newNameArg
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4255
    "Copy the file's contents into another file.
22542
d9668611fc38 #DOCUMENTATION by mawalch
mawalch
parents: 22503
diff changeset
  4256
     Do it safe in an atomic operation which makes sure that no partially written file appears.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4257
     The argument must be convertable to a filename.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4258
     Raises an exception, if an error occurs."
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4259
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  4260
    |newName inStream accessRights tempStream|
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4261
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4262
    newName := newNameArg asFilename.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4263
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4264
    "Contents is not copied if newName represent same file as me."
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4265
    newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ].
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4266
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4267
    inStream := self readStream.
15823
58ec1dc2d37e class: Filename
Stefan Vogel <sv@exept.de>
parents: 15819
diff changeset
  4268
    newName exists ifTrue:[
20252
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4269
        accessRights := newName accessRights.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4270
    ] ifFalse:[
20252
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4271
        accessRights := self accessRights.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4272
    ].
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4273
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4274
    [
20252
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4275
        "let the temp filename start with a ~ to make it invisible"
23623
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  4276
        tempStream := FileStream newTemporaryIn:newName directory osNameForDirectory nameTemplate:'~%1_%2'.
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4277
        "ignore the error - may occur when copying to a network drive"
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  4278
        OsError catch:[
20252
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4279
            "would be nice to keep the access rights of the original file"
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4280
            tempStream fileName accessRights:accessRights.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4281
        ].
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4282
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4283
        inStream binary; buffered:false.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4284
        tempStream binary; buffered:false.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4285
        [
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4286
            inStream copyToEndInto:tempStream.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4287
        ] ifCurtailed:[
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4288
            tempStream close.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4289
            tempStream fileName remove.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4290
            tempStream := nil.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4291
        ].
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4292
        tempStream syncData.
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4293
    ] ensure:[
20252
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4294
        inStream close.
17b9880f243e #OTHER by mawalch
mawalch
parents: 20158
diff changeset
  4295
        tempStream notNil ifTrue:[tempStream close].
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4296
    ].
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4297
    tempStream fileName renameTo:newName.
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4298
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4299
    "
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4300
     'Make.proto' asFilename safeCopyTo:'/tmp/Makefile.foo'
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4301
     'Make.proto' asFilename safeCopyTo:'/'
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4302
     'smalltalk' asFilename safeCopyTo:'/xxxxxxxxxxxxxxxx/bla'
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4303
    "
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4304
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4305
    "Modified: / 10-09-2004 / 09:49:28 / janfrog"
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4306
    "Modified: / 29-09-2006 / 16:26:32 / cg"
22542
d9668611fc38 #DOCUMENTATION by mawalch
mawalch
parents: 22503
diff changeset
  4307
    "Modified (comment): / 13-02-2018 / 11:59:48 / mawalch"
23623
0b30772c722c #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23606
diff changeset
  4308
    "Modified: / 21-01-2019 / 16:01:21 / Stefan Vogel"
15819
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4309
!
27e368019158 class: Filename
Stefan Vogel <sv@exept.de>
parents: 15811
diff changeset
  4310
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4311
truncateTo:newSize
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4312
    "change the file's size.
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4313
     This may not be supported on all operating systems
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4314
     (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
  4315
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4316
    (OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4317
        ^ 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
  4318
    ]
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4319
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4320
    "
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4321
     |s|
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4322
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4323
     s := 'test' asFilename writeStream.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4324
     s next:1000 put:$1.
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4325
     s close.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4326
     ('test' asFilename fileSize) printCR.
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4327
     'test' asFilename truncateTo:100.
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  4328
     ('test' asFilename fileSize) printCR.
932
f57ec42ceb44 added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents: 883
diff changeset
  4329
    "
4148
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4330
70c391aa0e3e added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents: 4131
diff changeset
  4331
    "Modified: / 5.5.1999 / 13:41:59 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4332
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4333
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4334
!Filename methodsFor:'file queries'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4335
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4336
accessTime
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4337
    "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
  4338
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4339
    | i |
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4340
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4341
    (i := self info) isNil ifTrue:[^ nil].
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  4342
    ^ i accessTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4343
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4344
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4345
     Filename currentDirectory accessTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4346
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4347
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4348
    "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
  4349
    "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
  4350
    "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
  4351
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4352
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4353
creationTime
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4354
    "return a timeStamp containing the file's creation time.
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4355
     NOTICE: only windoof distinguishes creation from modification;
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  4356
     under unix, nil is returned (callers should fall back and use mod-time then"
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4357
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4358
    |i|
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4359
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4360
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  4361
    ^ i creationTime
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  4362
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  4363
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4364
     Filename currentDirectory creationTime
6977
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4365
    "
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4366
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4367
    "Created: / 9.7.1996 / 10:18:59 / cg"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4368
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4369
    "Modified: / 14.8.1998 / 17:42:50 / cg"
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4370
!
eca61146235c added creationTime
penk
parents: 6973
diff changeset
  4371
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4372
dates
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4373
    "return the file's modification and access times as an object (currently a dictionary)
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4374
     that responds to the at: message with arguments
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4375
     #modified, #accessed or #statusChanged."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4376
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4377
    |info dates osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4378
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4379
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4380
    info := OperatingSystem infoOf:osName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4381
    info isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4382
        "maybe this is a symbolic link with a broken link target.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4383
         Answer the dates of the link itself"
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4384
        info := OperatingSystem linkInfoOf:osName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4385
        info isNil ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4386
            ^ nil
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4387
        ]
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
    dates := IdentityDictionary new.
6978
28e56617ff1f creationTime
penk
parents: 6977
diff changeset
  4390
    dates at:#created put:(info creationTime).
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  4391
    dates at:#modified put:(info modificationTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  4392
    dates at:#accessed put:(info accessTime).
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  4393
    dates at:#statusChanged put:(info statusChangeTime).
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4394
    ^ dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4395
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4396
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4397
     Filename currentDirectory dates
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4398
     '../regression' asFilename dates
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4399
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4400
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4401
    "Modified: 1.11.1996 / 20:19:24 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4402
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4403
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4404
fileSize
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4405
    "return the size of the file in bytes"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4406
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4407
    |i|
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4408
22395
6e3d466ccef0 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22127
diff changeset
  4409
    (i := self info) isNil ifTrue:[^ 0].
6794
498d85323172 use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents: 6793
diff changeset
  4410
    ^ i fileSize
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4411
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4412
    "Modified: / 17.8.1998 / 10:23:46 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4413
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4414
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4415
fileType
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4416
    "this returns a string describing the type of contents of
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4417
     the file. This is done using the unix 'file' command,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4418
     (which usually is configurable by /etc/magic).
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4419
     On non-unix systems, this may simply return 'file',
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4420
     not knowning about the contents.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4421
     Warning:
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4422
         Since the returned string differs among systems (and language settings),
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4423
         it is only useful for user-information;
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4424
         NOT as a tag to be used by a program."
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4425
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4426
    |info mime|
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4427
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4428
    "/ since we cannot depend on a 'file' command being available,
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4429
    "/ do the most obvious ones here.
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4430
    "/ (also useful since the 'file' command takes some time, and the code
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4431
    "/  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
  4432
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4433
    info := self linkInfo.
9060
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  4434
    info isNil ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4435
        ^ 'removed'         "/ could happen, when coming from a snapshot image
9060
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  4436
    ].
d8cd096117b4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 8947
diff changeset
  4437
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4438
    info isSymbolicLink ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4439
        ^ 'symbolic link to ' , info path
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  4440
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4441
    info isDirectory ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4442
        self isReadable ifFalse:[^ 'directory, unreadable'].
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4443
        self isExecutable ifFalse:[^ 'directory, locked'].
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4444
        ^ 'directory'
2573
6545b4c31872 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2566
diff changeset
  4445
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4446
    info isCharacterSpecial ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4447
        ^ 'character device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4448
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4449
    info isBlockSpecial ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4450
        ^ 'block device special file'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4451
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4452
    info isSocket ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4453
        ^ 'socket'
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4454
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4455
    info isFifo ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4456
        ^ 'fifo'
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  4457
    ].
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  4458
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  4459
    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
  4460
    info fileSize == 0 ifTrue:[^ 'empty'].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  4461
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4462
    "/ suffix := self suffix asLowercase.
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  4463
    "/ baseNm := self withoutSuffix baseName asLowercase.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4464
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4465
    mime := self mimeTypeOfContents.
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  4466
    mime notNil ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4467
        "/ kludge to avoid making libview a prereq. of libbasic
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4468
        (Smalltalk at:#MIMETypes) notNil ifTrue:[
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4469
            info := (Smalltalk at:#MIMETypes) fileInfoForMimeType:mime.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4470
            info notNil ifTrue:[^ info].
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4471
        ].
1602
ef3e0a750ee8 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1601
diff changeset
  4472
    ].
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4473
    ^ 'file'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4474
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4475
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4476
     'Makefile' asFilename fileType
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4477
     '.' asFilename fileType
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4478
     '/dev/null' asFilename fileType
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4479
     '/usr/tmp' asFilename fileType
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4480
     '/tmp/.X11-unix/X0' asFilename fileType
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4481
     'smalltalk.rc' asFilename fileType
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4482
     'bitmaps/SBrowser.xbm' asFilename fileType
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4483
    "
1601
1d57e1047323 avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents: 1540
diff changeset
  4484
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4485
    "Modified: / 21-07-1998 / 11:25:56 / cg"
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  4486
    "Modified (comment): / 06-02-2019 / 11:49:16 / Stefan Vogel"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4487
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4488
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4489
id
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4490
    "return the file's/directory's file-id (inode number)"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4491
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4492
    ^ OperatingSystem idOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4493
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4494
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4495
     Filename currentDirectory id
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4496
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4497
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4498
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4499
    "Created: 5.8.1997 / 19:26:01 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4500
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4501
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4502
info
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4503
    "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
  4504
     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
  4505
     the returned object) is:
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4506
22401
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  4507
         type       - a symbol giving the files fileType
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  4508
         mode       - numeric access mode
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  4509
         uid        - owners user id
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  4510
         gid        - owners group id
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  4511
         fileSize   - files size
6d41c49ab4c5 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22396
diff changeset
  4512
         id         - files number (i.e. inode number)
20798
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4513
         accessed      - last access time (as osTime-stamp)
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4514
         modified      - last modification time (as osTime-stamp)
23152
f14eea04dd92 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23129
diff changeset
  4515
         statusChangeTime - last status change (as osTime-stamp)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4516
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4517
     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
  4518
     all of the information.
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4519
     The minimum returned info (i.e. on all OS's) will consist of at least:
20798
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4520
        modified
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4521
        size
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4522
        type
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4523
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4524
     Don't expect things like uid/gid/mode to be non-nil; write your application
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4525
     to either handle nil values,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4526
     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
  4527
     (i.e. instead of:
20798
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4528
        someFilename type == #directory
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4529
      use
20798
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4530
        someFilename isDirectory
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4531
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4532
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4533
    ^ OperatingSystem infoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4534
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4535
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4536
     Filename currentDirectory info
3768
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4537
     '/dev/null' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4538
     '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
  4539
     '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
  4540
     '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
  4541
     '../../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
  4542
     '.' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4543
     '..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4544
     '..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4545
     '..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4546
     '..\..\..\..' asFilename info
4801b87c1cd7 care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents: 3763
diff changeset
  4547
     'c:\' asFilename info
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4548
    "
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  4549
16272
e795e4d67993 class: Filename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16255
diff changeset
  4550
    "Modified: / 17-08-1998 / 10:24:10 / cg"
e795e4d67993 class: Filename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 16255
diff changeset
  4551
    "Modified (comment): / 21-03-2014 / 00:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
23152
f14eea04dd92 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23129
diff changeset
  4552
    "Modified (comment): / 29-06-2018 / 09:54:46 / Claus Gittinger"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4553
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4554
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4555
linkInfo
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4556
    "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
  4557
     instead of the link's target.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4558
     The information is the same as returned by #info, except that if the
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4559
     receiver represents a symbolic link, the links information
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4560
     is returned
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4561
     (while in this case, #info returns the info of the target file,
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4562
      which is accessed via the symbolic link).
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4563
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4564
     In addition to the normal entries, Unix returns an additional entry:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4565
         path -> the target files pathname
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4566
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4567
     See the comment in #info for more details."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4568
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4569
    ^ OperatingSystem linkInfoOf:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4570
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4571
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4572
     Filename currentDirectory linkInfo
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4573
     '/dev/null' asFilename linkInfo
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4574
     'Make.proto' asFilename linkInfo
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4575
     'Make.proto' asFilename linkInfo path
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4576
     'source/Point.st' asFilename linkInfo
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4577
     '../../libbasic/Point.st' asFilename linkInfo
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4578
     '/usr/tmp' asFilename linkInfo
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4579
    "
1862
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  4580
e8f44f10f1ab changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents: 1859
diff changeset
  4581
    "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
  4582
!
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4583
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4584
modificationTime
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  4585
    "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
  4586
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  4587
    |i|
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  4588
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  4589
    (i := self info) isNil ifTrue:[^ nil].      "/ non-existing
6793
0d3e3fd18a70 modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents: 6776
diff changeset
  4590
    ^ i modificationTime
1532
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4591
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4592
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4593
     Filename currentDirectory modificationTime
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4594
    "
6b4c38b9090c added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents: 1523
diff changeset
  4595
3763
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  4596
    "Created: / 9.7.1996 / 10:18:59 / cg"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  4597
    "Modified: / 26.9.1997 / 13:05:39 / stefan"
31d58d04ac15 care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents: 3753
diff changeset
  4598
    "Modified: / 14.8.1998 / 17:42:50 / cg"
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4599
!
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4600
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4601
type
23420
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  4602
    "return the symbolic type of the file.
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  4603
     For symbolic links it is the type of the linked-to file."
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4604
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  4605
    ^ OperatingSystem typeOf:(self osNameForAccess)
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4606
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4607
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4608
     Filename currentDirectory type
2836
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4609
    "
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4610
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4611
    "Modified: 9.7.1996 / 10:19:27 / cg"
2217da816fd9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2707
diff changeset
  4612
    "Created: 5.8.1997 / 19:31:26 / cg"
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4613
! !
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4614
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4615
!Filename methodsFor:'file utilities'!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4616
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4617
edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4618
    "start an editView on the file represented by the receiver"
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4619
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4620
    EditTextView openOn:self asString
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4621
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4622
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4623
     'smalltalk.rc' asFilename edit
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4624
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4625
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4626
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4627
fileIn
13424
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  4628
    "load source code from the file"
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  4629
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  4630
    ^ (ProgrammingLanguage forFile: self) fileIn: self
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  4631
bfbcff5c64be changed: #fileIn
Claus Gittinger <cg@exept.de>
parents: 13247
diff changeset
  4632
    "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
  4633
! !
fec8c38962ba error reporting
Claus Gittinger <cg@exept.de>
parents: 539
diff changeset
  4634
23506
757d14838de2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23420
diff changeset
  4635
2
claus
parents: 1
diff changeset
  4636
!Filename methodsFor:'instance creation'!
claus
parents: 1
diff changeset
  4637
10969
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4638
/ subname
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4639
    "Same as construct: Taking the receiver as a directory name, construct a new
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4640
     filename for an entry within this directory
10969
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4641
     (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
  4642
     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
  4643
     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
  4644
     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
  4645
     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
  4646
     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
  4647
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4648
    ^ 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
  4649
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4650
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4651
     '/tmp' asFilename / 'foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4652
     '/' asFilename / 'foo' / 'bar' / 'baz'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4653
     '/foo/bar' asFilename / ('baz' asFilename)
10969
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4654
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4655
     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
  4656
       '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
  4657
    "
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4658
!
046b204c6ea2 New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents: 10902
diff changeset
  4659
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4660
construct:subname
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4661
    "taking the receiver as a directory name, construct a new
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4662
     filename for an entry within this directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4663
     (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
  4664
     The argument may not specify an absolute path name.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4665
     Please do not use this to create filenames with suffixes,
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4666
     since some systems require special naming conventions.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4667
     See also: #withSuffix: (which is different, but often needed)."
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4668
11784
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  4669
    |constructedName|
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  4670
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  4671
    constructedName := self constructString:subname.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4672
    ^ self species named:constructedName.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4673
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4674
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4675
     '/tmp' asFilename construct:'foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4676
     '/' asFilename construct:'foo'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4677
     '/usr/tmp' asFilename construct:'foo'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4678
     '/foo/bar' asFilename construct:'baz'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4679
     '/foo/bar' asFilename construct:'baz' asFilename
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4680
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4681
     Bad example; works on UNIX, but may not on others:
11784
dc0f068adfd6 *** empty log message ***
Stefan Vogel <sv@exept.de>
parents: 11781
diff changeset
  4682
       'foo/bar.baz' asFilename construct:'.suff'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4683
    "
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
    "Modified: 29.2.1996 / 20:55:06 / cg"
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4686
!
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4687
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4688
constructDirectory:subname
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4689
    "same as #construct: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4690
     (may allow different/relaxed name syntax of the argument on some systems)"
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4691
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4692
    ^ self species named:(self constructDirectoryString:subname)
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4693
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4694
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4695
constructDirectoryString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4696
    "same as #constructString: on most systems.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4697
     (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
  4698
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4699
    ^ self constructString:subName
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4700
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4701
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4702
constructString:subName
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4703
    "taking the receiver as a directory name, construct a new
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4704
     filename-string for an entry within this directory
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  4705
     (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
  4706
     The argument may not specify an absolute path name.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4707
     The code below works for UNIX & MSDOS;
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  4708
     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
  4709
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  4710
    |sepString sub|
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  4711
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  4712
    sub := subName asString.
20069
4abc2e12bcec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19957
diff changeset
  4713
    nameString size == 0 ifTrue:[
4abc2e12bcec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19957
diff changeset
  4714
        ^ sub
4abc2e12bcec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19957
diff changeset
  4715
    ].
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4716
    sepString := self species separatorString.
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  4717
    (nameString endsWith:sepString) ifTrue:[
20069
4abc2e12bcec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 19957
diff changeset
  4718
        ^ nameString , sub
6247
c6e11cb150db *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6245
diff changeset
  4719
    ].
2960
55d3fa37f610 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2947
diff changeset
  4720
    ^ nameString , sepString , sub
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4721
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4722
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4723
     '/tmp' asFilename constructString:'foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4724
     '/' asFilename constructString:'foo'
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4725
     '/usr/tmp' asFilename constructString:'foo'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4726
     '/foo/bar' asFilename constructString:'baz'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4727
     '' asFilename constructString:'baz'
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4728
    "
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  4729
3677
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  4730
    "Modified: / 7.9.1995 / 10:15:22 / claus"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  4731
    "Created: / 9.9.1997 / 08:57:08 / cg"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  4732
    "Modified: / 20.1.1998 / 15:58:23 / md"
51542c86ba2a md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents: 3666
diff changeset
  4733
    "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
  4734
!
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4735
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4736
filenameFor:fileName
6973
c46e1d005ea4 comment
Claus Gittinger <cg@exept.de>
parents: 6943
diff changeset
  4737
    "return a filename representing the argument, fileName
c46e1d005ea4 comment
Claus Gittinger <cg@exept.de>
parents: 6943
diff changeset
  4738
     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
  4739
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4740
    |f|
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4741
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4742
    f := fileName asFilename.
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4743
    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
  4744
    ^ (self construct:fileName)
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4745
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4746
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4747
     '/tmp' asFilename filenameFor:'foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4748
     '/tmp' asFilename filenameFor:'/foo'
2944
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4749
    "
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4750
e1f1111afa12 Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents: 2939
diff changeset
  4751
    "Created: 18.9.1997 / 14:34:14 / stefan"
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4752
!
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4753
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4754
secureConstruct:subname
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4755
    "taking the receiver as a directory name, construct a new
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4756
     filename for an entry within this directory
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4757
     (i.e. for a file or a subdirectory in that directory).
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4758
     The argument may not specify an absolute path name.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4759
     Please do not use this to create filenames with suffixes,
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4760
     since some systems require special naming conventions.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4761
     See also: #withSuffix: (which is different, but often needed).
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4762
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4763
     This method differs from #construct:, by not permitting subName
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4764
     to navigate above the current filename (via '..') and is used eg.
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4765
     by the documentation viewer and other services to prevent remote
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4766
     access outside some predefined root folder."
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4767
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4768
    ^ self species named:(self secureConstructString:subname)
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4769
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4770
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4771
     '/tmp' asFilename secureConstruct:'foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4772
     '/tmp' asFilename secureConstruct:'../foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4773
     '/tmp' asFilename secureConstruct:'/./foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4774
     '/tmp' asFilename secureConstruct:'foo/../bar'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4775
     '/' asFilename secureConstruct:'foo'
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4776
     '/usr/tmp' asFilename secureConstruct:'foo'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4777
     '/foo/bar' asFilename secureConstruct:'baz'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4778
     '/foo/bar' asFilename secureConstruct:'baz' asFilename
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4779
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4780
     Bad example; works on UNIX, but may not on others:
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4781
       'foo/bar.baz' secureConstruct:'.suff'
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4782
    "
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4783
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4784
    "Modified: 29.2.1996 / 20:55:06 / cg"
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4785
!
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4786
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4787
secureConstructString:subName
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4788
    "taking the receiver as a directory name, construct a new
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4789
     filename-string for an entry within this directory
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4790
     (i.e. for a file or a subdirectory in that directory).
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4791
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4792
     This method differs from #constructString:, by not permitting subName
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4793
     to navigate above the current filename (via '..') and is used eg.
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4794
     by the documentation viewer and other services to prevent remote
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4795
     access outside some predefined root folder.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4796
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4797
     The code below works for UNIX & MSDOS;
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4798
     other filename classes (i.e. VMS) have to redefine this method."
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4799
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4800
    |sepString sub normalizedPath pathStream|
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4801
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4802
    sepString := self species separatorString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4803
    sub := subName asString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4804
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4805
    sub := sub asCollectionOfSubstringsSeparatedByAll:sepString.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4806
    normalizedPath := OrderedCollection new:sub size.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4807
    sub do:[:eachPathComponent|
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4808
        eachPathComponent = '..' ifTrue:[
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4809
            normalizedPath isEmpty ifTrue:[
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4810
                self error:'secureConstruct: - trying to escape from: ', nameString.
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4811
            ].
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4812
            normalizedPath removeLast.
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4813
        ] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4814
            normalizedPath add:eachPathComponent.
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4815
        ]]
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4816
    ].
18272
d04d39e0f8cb class: Filename
Stefan Vogel <sv@exept.de>
parents: 17310
diff changeset
  4817
    pathStream := CharacterWriteStream with:nameString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4818
    (nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4819
        pathStream nextPutAll:sepString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4820
    ].
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4821
    normalizedPath do:[:eachPathComponent|
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4822
        pathStream nextPutAll:eachPathComponent.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4823
    ] separatedBy:[
22927
6dab5d9ece9d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22850
diff changeset
  4824
        pathStream nextPutAll:sepString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4825
    ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4826
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4827
    ^ pathStream contents.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4828
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4829
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4830
     '/tmp' asFilename secureConstructString:'fooÅ '
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4831
     '/tmp' asFilename secureConstructString:'../foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4832
     '/tmp' asFilename secureConstructString:'foo/../bla'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4833
     '/tmp' asFilename secureConstructString:'foo/./bla'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4834
     '/tmp' asFilename secureConstructString:'/bla/foo/../../foo'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4835
     '/' asFilename secureConstructString:'foo'
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4836
     '/usr/tmp' asFilename secureConstructString:'foo'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4837
     '/foo/bar' asFilename secureConstructString:'baz'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4838
     '' asFilename secureConstructString:'baz'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4839
     '' asFilename secureConstructString:'/baz'
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4840
    "
2
claus
parents: 1
diff changeset
  4841
! !
claus
parents: 1
diff changeset
  4842
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4843
!Filename methodsFor:'misc'!
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4844
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4845
, aString
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4846
    "this allows filenames to understand how names are concatenated.
14072
b9389ad3cf2c comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13949
diff changeset
  4847
     Returns a string consisting of the receiver's name, concatenated
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4848
     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
  4849
     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
  4850
     See also: #withSuffix: which is new and better."
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4851
5866
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  4852
    <resource:#obsolete>
32478aced225 Use <resource:#obsolete>
Stefan Vogel <sv@exept.de>
parents: 5859
diff changeset
  4853
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4854
    self obsoleteMethodWarning:'use #construct:'.
308
f04744ef7b5d *** empty log message ***
claus
parents: 276
diff changeset
  4855
    ^ (nameString , aString asString)
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4856
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4857
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4858
     'Makefile' asFilename , '.bak'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4859
     ('Makefile' asFilename , '.bak') asFilename
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4860
     'Makefile' asFilename withSuffix:'bak'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4861
     'Makefile' asFilename construct:'.bak'
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4862
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  4863
14072
b9389ad3cf2c comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13949
diff changeset
  4864
    "Modified: / 07-09-1997 / 23:45:36 / cg"
b9389ad3cf2c comment/format in: #,
Claus Gittinger <cg@exept.de>
parents: 13949
diff changeset
  4865
    "Modified (comment): / 01-04-2012 / 13:18:21 / cg"
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4866
!
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4867
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4868
canonicalize
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4869
    "normalize a filename by removing all empty path components or dots,
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4870
     and by resolving parent directory '..' references.
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4871
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4872
     The code below works for UNIX & MSDOS;
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4873
     other filename classes (i.e. VMS) may want to redefine this method."
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4874
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  4875
    nameString := self species canonicalize:nameString.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4876
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4877
    "
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4878
        '/tmp/bla' asFilename canonicalize.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4879
        '/tmp/bla/../fasel' asFilename canonicalize.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4880
        '/tmp/bla/.././/fasel' asFilename canonicalize.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4881
        '..' asFilename canonicalize.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4882
        'bla/../fasel' asFilename canonicalize.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4883
        '//bla/../fasel' asFilename canonicalize.
9263
67350979c827 Add #secureConstruct:
Stefan Vogel <sv@exept.de>
parents: 9235
diff changeset
  4884
    "
195
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4885
! !
515af3696a5c *** empty log message ***
claus
parents: 192
diff changeset
  4886
14232
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4887
!Filename methodsFor:'os shell'!
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4888
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4889
openExplorer
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4890
    "open a file-explorer on the directory represented by the receiver.
22656
85edf3e70438 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22542
diff changeset
  4891
     On osx systems, a finder is opened.
85edf3e70438 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22542
diff changeset
  4892
     On other systems, a filebrowser is opened"
14232
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4893
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4894
    OperatingSystem
22396
317c7c679a76 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22395
diff changeset
  4895
        openApplicationForDocument:self pathName
317c7c679a76 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22395
diff changeset
  4896
        operation:#explore.
317c7c679a76 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22395
diff changeset
  4897
317c7c679a76 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22395
diff changeset
  4898
    "
22656
85edf3e70438 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 22542
diff changeset
  4899
     Filename currentDirectory openExplorer
22396
317c7c679a76 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22395
diff changeset
  4900
    "
14232
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4901
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4902
    "Created: / 21-07-2012 / 12:28:18 / cg"
22396
317c7c679a76 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 22395
diff changeset
  4903
    "Modified: / 20-12-2017 / 21:34:41 / stefan"
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4904
!
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4905
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4906
openFinder
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4907
    "open a finder on the directory represented by the receiver.
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4908
     On non-osx systems, an error is raised"
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4909
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4910
    OperatingSystem isOSXlike ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  4911
        self warn:'sorry - this operation is only available under osx'.
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4912
    ].
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4913
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  4914
    OperatingSystem executeCommand:'open "',self pathName,'"'
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4915
!
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4916
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4917
openTerminal
16545
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4918
    "open a terminal window on the directory represented by the receiver;
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4919
     on osx, a terminal app is opened,
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4920
     on windows a cmd.exe window,
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4921
     on unix, an xterm is opened."
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4922
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4923
    OperatingSystem isOSXlike ifTrue:[
20798
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4924
        "/ I don't know yet how to tell the terminal to
20678
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4925
        "/ go to a particular directory.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4926
        "/ therefore, use the built in terminal
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4927
        VT100TerminalView openShellIn:self pathName.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4928
        ^ self.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4929
    ].
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4930
    "/ using the code below seems to close the window immediately
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4931
    "/ at least on win7.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4932
    "/ use out own terminal, to make sure.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4933
    (OperatingSystem isMSWINDOWSlike
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4934
    and:[OperatingSystem isWin7Like]) ifTrue:[
20798
47754fe46c8c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20709
diff changeset
  4935
        "/ I don't know yet how to tell the terminal to
20678
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4936
        "/ go to a particular directory.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4937
        "/ therefore, use the built in terminal
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4938
        VT100TerminalView openShellIn:self pathName.
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4939
        ^ self.
16545
a54abb909c13 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16492
diff changeset
  4940
    ].
14804
89d40ef13b2c class: Filename
Claus Gittinger <cg@exept.de>
parents: 14759
diff changeset
  4941
14941
0793160108eb class: Filename
Claus Gittinger <cg@exept.de>
parents: 14932
diff changeset
  4942
    [
20678
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4943
        |cmd|
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4944
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4945
        OperatingSystem isOSXlike ifTrue:[
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4946
            cmd := '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal '
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4947
        ] ifFalse:[
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4948
            OperatingSystem isMSWINDOWSlike ifTrue:[
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4949
                cmd := #('c:\windows\System32\cmd.exe')
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4950
            ] ifFalse:[
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4951
                "/ VT100TerminalView openShellIn:self pathName
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4952
                cmd := 'xterm'
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4953
            ]
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4954
        ].
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4955
        OperatingSystem
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4956
            executeCommand:cmd
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4957
            inDirectory:self pathName
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4958
            showWindow:#default.
14941
0793160108eb class: Filename
Claus Gittinger <cg@exept.de>
parents: 14932
diff changeset
  4959
    ] fork
20678
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4960
2c8899eebf88 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 20533
diff changeset
  4961
    "Modified: / 18-10-2016 / 16:08:15 / cg"
14232
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4962
! !
001979aa0214 added: #openExplorer
Claus Gittinger <cg@exept.de>
parents: 14220
diff changeset
  4963
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4964
!Filename methodsFor:'printing & storing'!
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4965
21496
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4966
displayOn:aStream
4392
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  4967
    "append a user printed representation of the receiver to aStream.
26fb48f04e1b comment
Claus Gittinger <cg@exept.de>
parents: 4373
diff changeset
  4968
     The format is suitable for a human - not meant to be read back."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  4969
24382
b6d7add521a9 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24379
diff changeset
  4970
    aStream nextPutAll:(self className).
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4971
    aStream nextPutAll:'('''.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4972
    nameString printOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4973
    aStream nextPutAll:''')'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  4974
21496
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4975
    "Created: / 21-02-2017 / 09:02:34 / cg"
24382
b6d7add521a9 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 24379
diff changeset
  4976
    "Modified: / 28-06-2019 / 08:43:42 / Claus Gittinger"
21496
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4977
!
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4978
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4979
printOn:aStream
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4980
    "append a user printed representation of the receiver to aStream.
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4981
     The format is suitable for a human - not meant to be read back.
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4982
     Here, I print myself as a string, so I can be easily embedded in bind-with strings."
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4983
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4984
    "/ aStream nextPutAll:(self class name).
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4985
    "/ aStream nextPutAll:'('''.
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4986
    nameString printOn:aStream.
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4987
    "/ aStream nextPutAll:''')'
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4988
5ee730b45687 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 21441
diff changeset
  4989
    "Modified (comment): / 21-02-2017 / 09:03:57 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4990
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4991
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4992
storeOn:aStream
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4993
    "append a printed representation of the receiver to aStream,
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4994
     which allows reconstructing it via readFrom:"
328
claus
parents: 326
diff changeset
  4995
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4996
    aStream nextPut:$(.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4997
    nameString storeOn:aStream.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  4998
    aStream nextPutAll:' asFilename)'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  4999
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5000
7258
9ccdbee7d1ad method category rename
Claus Gittinger <cg@exept.de>
parents: 7236
diff changeset
  5001
!Filename methodsFor:'private-accessing'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5002
6227
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  5003
getName
21263
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5004
    <resource: #obsolete>
6227
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  5005
    "get the raw filename"
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  5006
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5007
    ^ nameString
6227
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  5008
!
09f773ce40d9 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 6223
diff changeset
  5009
21263
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5010
nameString
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5011
    "raw access to nameString - req'd for xml-store/reload"
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5012
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5013
    ^ nameString
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5014
!
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5015
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5016
nameString:aString
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5017
    "raw access to nameString - req'd for xml-store/reload"
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5018
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5019
    nameString := aString
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5020
!
402b77c345ec #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 21071
diff changeset
  5021
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5022
setName:aString
38
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  5023
    "set the filename"
454b1b94a48e *** empty log message ***
claus
parents: 5
diff changeset
  5024
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5025
    nameString := aString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  5026
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  5027
    "Modified: / 21.7.1998 / 10:44:18 / cg"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5028
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  5029
2
claus
parents: 1
diff changeset
  5030
!Filename methodsFor:'queries'!
claus
parents: 1
diff changeset
  5031
23393
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5032
directories
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5033
    "return a collection of directories contained in the directory represented by the receiver."
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5034
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5035
    ^ OrderedCollection withCollectedContents:[:coll |
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5036
        self directoriesDo:[:eachDirectory | coll add:eachDirectory]]
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5037
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5038
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5039
     '.' asFilename directories.
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5040
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5041
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5042
    "Modified: / 29-05-2007 / 12:02:56 / cg"
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5043
!
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5044
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5045
exists
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  5046
    "return true, if such a file exists."
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5047
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  5048
    ^ OperatingSystem isValidPath:(self osNameForAccess)
68
59faa75185ba *** empty log message ***
claus
parents: 54
diff changeset
  5049
85
claus
parents: 77
diff changeset
  5050
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5051
     '/foo/bar' asFilename exists
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5052
     '/tmp' asFilename exists
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5053
     'Makefile' asFilename exists
85
claus
parents: 77
diff changeset
  5054
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5055
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  5056
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5057
filenamesMatching:aPattern
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5058
    "VW compatibility"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5059
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5060
    ^ (self filesMatching:aPattern)
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5061
            collect:[:eachName | self construct:eachName].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5062
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5063
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5064
     '/etc' asFilename filenamesMatching:'a*;c*'
5928
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5065
    "
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5066
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5067
    "Created: / 15.4.1997 / 15:40:02 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5068
    "Modified: / 3.8.1998 / 21:22:15 / cg"
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5069
!
77964582cb35 added #filenamesMatching:
Claus Gittinger <cg@exept.de>
parents: 5890
diff changeset
  5070
23393
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5071
files
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5072
    "return a collection of regular files
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5073
     contained in the directory represented by the receiver."
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5074
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5075
    ^ OrderedCollection withCollectedContents:[:coll |
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5076
        self filesDo:[:eachFileName | coll add:eachFileName]].
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5077
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5078
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5079
     '.' asFilename files.
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5080
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5081
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5082
    "Modified: / 29-05-2007 / 12:02:15 / cg"
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5083
!
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5084
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  5085
filesMatching:aPattern
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5086
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5087
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5088
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5089
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5090
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5091
    ^ OrderedCollection withCollectedContents:[:coll |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5092
        self filesMatching:aPattern do:[:fn | coll add:fn]]
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5093
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5094
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5095
     '/etc' asFilename filesMatching:'a*;c*'
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  5096
    "
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  5097
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  5098
    "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
  5099
    "Modified: / 3.8.1998 / 21:22:15 / cg"
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5100
!
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5101
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5102
filesMatching:aPattern caseSensitive:caseSensitive do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5103
    "given the receiver, representing a directory;
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5104
     evaluate aBlock for files which match a pattern.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5105
     The pattern may be a simple matchPattern, or a set of
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5106
     multiple patterns separated by semicolons."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5107
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5108
    |matchers|
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5109
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5110
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5111
    self directoryContentsDo:[:name |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5112
        (matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5113
            aBlock value:name
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5114
        ]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5115
    ].    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5116
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5117
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5118
     '/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5119
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5120
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5121
    "Created: / 15.4.1997 / 15:40:02 / cg"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5122
    "Modified: / 3.8.1998 / 21:22:15 / cg"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5123
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5124
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5125
filesMatching:aPattern do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5126
    "given the receiver, representing a directory;
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5127
     evaluate aBlock for files which match a pattern.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5128
     The pattern may be a simple matchPattern, or a set of
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5129
     multiple patterns separated by semicolons."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5130
23393
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5131
    self filesMatching:aPattern caseSensitive:(self species isCaseSensitive) do:aBlock
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5132
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5133
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5134
     '/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f]
23393
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5135
     '/etc' asFilename filesMatching:'a*;c*'
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5136
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5137
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5138
    "Created: / 15-04-1997 / 15:40:02 / cg"
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5139
    "Modified: / 03-08-1998 / 21:22:15 / cg"
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5140
    "Modified (comment): / 30-09-2018 / 11:01:40 / Claus Gittinger"
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5141
!
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5142
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5143
filesMatchingGLOB
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5144
    "Interpreting myself as a GLOB pattern,
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5145
     Return filenames matching me"
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5146
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5147
    ^ Array streamContents:[:s | self filesMatchingGLOBDo:[:each | s nextPut:each]].
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5148
    
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5149
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5150
     '../../*/A*' asFilename filesMatchingGLOB.
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5151
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5152
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5153
    "Created: / 30-09-2018 / 10:56:42 / Claus Gittinger"
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5154
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5155
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5156
filesMatchingWithoutDotDirs:aPattern
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5157
    "given the receiver, representing a directory;
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5158
     return a collection of files matching a pattern.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5159
     Exclude '.' and '..' from the returned list.
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5160
     The pattern may be a simple matchPattern, or a set of
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5161
     multiple patterns separated by semicolons."
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5162
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5163
    ^ OrderedCollection withCollectedContents:[:coll |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5164
        self filesMatchingWithoutDotDirs:aPattern do:[:fn | coll add:fn]]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5165
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5166
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5167
     Filename currentDirectory filesMatching:'.*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5168
     Filename currentDirectory filesMatchingWithoutDotDirs:'*.*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5169
     '/etc' asFilename filesMatchingWithoutDotDirs:'*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5170
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5171
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5172
    "Created: / 15.4.1997 / 12:52:10 / cg"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5173
    "Modified: / 3.8.1998 / 21:22:30 / cg"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5174
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5175
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5176
filesMatchingWithoutDotDirs:aPattern caseSensitive:caseSensitive do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5177
    "given the receiver, representing a directory;
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5178
     evaluate aBlock for files matching a pattern.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5179
     Exclude '.' and '..'.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5180
     The pattern may be a simple matchPattern, or a set of
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5181
     multiple patterns separated by semicolons."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5182
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5183
    |matchers|
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5184
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5185
    matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;.
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5186
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5187
    self directoryContentsDo:[:name |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5188
        (name ~= '.'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5189
            and:[ name ~= '..'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5190
            and:[ (matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ]])
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5191
        ifTrue:[
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5192
            aBlock value:name
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5193
        ]
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5194
    ].
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5195
    
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5196
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5197
     Filename currentDirectory filesMatching:'M*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5198
     '/etc' asFilename filesMatching:'[a-z]*'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5199
     '../../libbasic' asFilename filesMatching:'[A-D]*.st'
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5200
    "
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5201
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5202
    "Created: / 15.4.1997 / 12:52:10 / cg"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5203
    "Modified: / 3.8.1998 / 21:22:30 / cg"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5204
!
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5205
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5206
filesMatchingWithoutDotDirs:aPattern do:aBlock
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5207
    "given the receiver, representing a directory;
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5208
     evaluate aBlock for files matching a pattern.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5209
     Exclude '.' and '..'.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5210
     The pattern may be a simple matchPattern, or a set of
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5211
     multiple patterns separated by semicolons."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5212
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5213
    self filesMatchingWithoutDotDirs:aPattern caseSensitive:self species isCaseSensitive do:aBlock
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5214
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5215
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5216
     Filename currentDirectory filesMatching:'M*'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5217
     '/etc' asFilename filesMatching:'[a-z]*'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5218
     '../../libbasic' asFilename filesMatching:'[A-D]*.st'
2550
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5219
    "
0832a8bc6ec4 allow multiPatterns
Claus Gittinger <cg@exept.de>
parents: 2548
diff changeset
  5220
3719
ce88c6f64d37 ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents: 3713
diff changeset
  5221
    "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
  5222
    "Modified: / 3.8.1998 / 21:22:30 / cg"
2548
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  5223
!
b6182b559ea2 made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents: 2547
diff changeset
  5224
23393
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5225
filesWithSuffix:suffix
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5226
    "return a collection of regular files (i.e. not subdirectories)
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5227
     with a given suffix which are contained in the directory
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5228
     represented by the receiver."
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5229
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5230
    ^ OrderedCollection withCollectedContents:[:coll |
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5231
        self filesWithSuffix:suffix do:[:eachFileName | coll add:eachFileName]].
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5232
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5233
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5234
     '.' asFilename filesWithSuffix:'so'.
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5235
     'packages' asFilename filesWithSuffix:'so'.
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5236
    "
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5237
!
6f06e66359ca #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 23332
diff changeset
  5238
9206
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  5239
fullAlternativePathName
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5240
    "some filesystems (aka: windows) have alternative (short) filenames.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5241
     Those systems redefine this method to return it.
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5242
     Otherwise, the same as the regular name is returned here"
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  5243
     
9206
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  5244
    ^ nameString
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  5245
!
6f6bc408f82b +fullAlternativePathName
sr
parents: 9173
diff changeset
  5246
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5247
isExecutable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5248
    "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
  5249
     For directories, true is returned if the directory can be entered.
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5250
     See isExecutableProgram for a related check."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5251
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  5252
    ^ OperatingSystem isExecutable:(self osNameForAccess)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5253
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5254
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5255
     '/foo/bar' asFilename isExecutable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5256
     '/tmp' asFilename isExecutable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5257
     'Makefile' asFilename isExecutable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5258
     '/bin/ls' asFilename isExecutable
356
claus
parents: 328
diff changeset
  5259
    "
claus
parents: 328
diff changeset
  5260
!
claus
parents: 328
diff changeset
  5261
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5262
isExecutableProgram
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5263
    "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
  5264
     (i.e. for directories, false is returned.)"
356
claus
parents: 328
diff changeset
  5265
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5266
    |osName|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5267
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  5268
    osName := self osNameForAccess.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5269
    ^ (OperatingSystem isExecutable:osName)
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5270
      and:[(OperatingSystem isDirectory:osName) not]
356
claus
parents: 328
diff changeset
  5271
claus
parents: 328
diff changeset
  5272
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5273
     '/tmp' asFilename isExecutable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5274
     '/bin/ls' asFilename isExecutable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5275
     '/tmp' asFilename isExecutableProgram
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5276
     '/bin/ls' asFilename isExecutableProgram
20457
ba1644829195 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20453
diff changeset
  5277
     
ba1644829195 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20453
diff changeset
  5278
     'ls' asFilename isExecutableProgram
ba1644829195 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20453
diff changeset
  5279
     OperatingSystem canExecuteCommand:'ls'
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5280
    "
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5281
!
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5282
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5283
isHidden
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5284
    "return true, if the receiver represents a hidden file.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5285
     The definitions of hidden files depends on the OS used;
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5286
     on UNIX, a name starting with a period is considered hidden;
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  5287
     on MSDOS, the file's hidden attribute is also used.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5288
     VMS has no concept of hidden files."
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5289
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5290
    ^ false
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5291
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5292
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5293
isMountPoint:aPathName
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5294
    "return true, if I represent a mount-point.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5295
     Warning:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5296
        the receiver must be an absolute pathname,
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5297
        because a realPath is not used/generated for the query (to avoid automounting).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5298
        Aka: do not ask: '../../' asFilename isMountPoint;
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5299
    "
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5300
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5301
    self isAbsolute ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5302
        self error:'this query must be done on an absolute pathname'.
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5303
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5304
    ^ OperatingSystem isMountPoint:(self name)
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5305
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5306
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5307
isReadable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5308
    "return true, if such a file exists and is readable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5309
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  5310
    ^ OperatingSystem isReadable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5311
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5312
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5313
     '/foo/bar' asFilename isReadable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5314
     '/tmp' asFilename isReadable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5315
     'Makefile' asFilename isReadable
328
claus
parents: 326
diff changeset
  5316
    "
claus
parents: 326
diff changeset
  5317
!
claus
parents: 326
diff changeset
  5318
11529
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5319
isSharedLibrary
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5320
    "return true, if such a file exists and is a shared library."
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5321
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5322
    ObjectFileLoader isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5323
        "we cannot handle shared libraries, so there are no shared libraries"
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5324
        ^ false.
11529
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5325
    ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5326
    ^ (ObjectFileLoader validBinaryExtensions includes:self suffix)
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5327
        and:[self isRegularFile].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5328
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5329
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5330
     'libstx_libbasic.so' asFilename isSharedLibrary
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5331
     'libstx_libbasic.dll' asFilename isSharedLibrary
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5332
     '/tmp' asFilename isSharedLibrary
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5333
     '/tmp.dll' asFilename isSharedLibrary
11529
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5334
    "
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5335
!
3fe3af4ef5a2 new: #isSharedLibrary
Stefan Vogel <sv@exept.de>
parents: 11425
diff changeset
  5336
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5337
isValidFilename
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5338
    "return true, if the name is a valid filename"
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5339
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5340
    |separator|
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5341
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5342
    separator := self separator.
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5343
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5344
    ^ nameString notEmptyOrNil 
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5345
        and:[(nameString contains:[:eachChar| 
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5346
                            eachChar ~~ separator 
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5347
                            and:[self class isBadCharacter:eachChar]]) not].
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5348
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5349
    "
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5350
        'abc' asFilename isValidFilename
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5351
        'abc/' asFilename isValidFilename
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5352
        ('abc' copyWith:Character return) asFilename isValidFilename
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5353
    "
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5354
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5355
    "Created: / 27-07-2017 / 14:23:56 / stefan"
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5356
!
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  5357
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5358
isWritable
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5359
    "return true, if such a file exists and is writable."
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5360
2947
c579563679ed *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2946
diff changeset
  5361
    ^ OperatingSystem isWritable:(self osNameForFile)
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5362
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  5363
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5364
     '/foo/bar' asFilename isWritable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5365
     '/tmp' asFilename isWritable
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5366
     'Makefile' asFilename isWritable
328
claus
parents: 326
diff changeset
  5367
    "
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5368
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  5369
15574
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5370
isWritableDirectory
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5371
    "return true, if such a directory exists and is writable.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5372
     Don't believe #isWritable, since on an NFS mounted filesystem
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5373
     with UID mapping and attribute cache enabled, there may be false negatives."
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5374
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5375
    self isDirectory ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5376
        ^ false.
15574
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5377
    ].
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5378
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5379
    self isWritable ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5380
        "/ on an NFS mounted filesystem with UID mapping and
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5381
        "/ attribute cache enabled,
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5382
        "/ this query may fail, but creation may work actually.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5383
        "/ check again...
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5384
        [
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5385
            |tempFile|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5386
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5387
            tempFile := FileStream newTemporaryIn:self.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5388
            tempFile close.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5389
            tempFile fileName remove.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5390
        ] on:OpenError do:[:ex|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5391
            ^ false.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5392
        ].
15574
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5393
    ].
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5394
    ^ true.
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5395
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5396
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5397
     '/foo/bar' asFilename isWritableDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5398
     '/tmp' asFilename isWritableDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5399
     '/etc' asFilename isWritableDirectory
15574
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5400
     'Makefile' asFilename isWritableDirectory
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5401
     '/net/exeptn/home2/office' asFilename isWritable
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5402
     '/net/exeptn/home2/office' asFilename isWritableDirectory
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5403
    "
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5404
!
c215d2b5683a class: Filename
Stefan Vogel <sv@exept.de>
parents: 15490
diff changeset
  5405
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5406
separator
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5407
    "return the directory-separator character"
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5408
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5409
    ^ self species separator
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5410
22403
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  5411
    "
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  5412
     UnixFilename separator 
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  5413
     PCFilename separator
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  5414
    "
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  5415
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5416
    "Modified: 29.2.1996 / 20:52:01 / cg"
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5417
!
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5418
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  5419
species
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5420
    "create only new instances of the concrete OS specific class.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5421
     Redefined in AutoDeletedFilename, to not create AutoDeleted instances
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5422
     per default (from directories etc.)"
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5423
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5424
    self == Filename ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5425
        ^ ConcreteClass.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5426
    ] ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5427
        ^ self class.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5428
    ].
11781
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  5429
!
6488fd6cc498 Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents: 11763
diff changeset
  5430
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5431
withSpecialExpansions
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5432
    "return a new filename, expanding any OS specific macros.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5433
     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
  5434
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5435
    |newName|
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5436
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5437
    newName := self species nameWithSpecialExpansions:nameString.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5438
    newName = nameString ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5439
        ^ self.
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5440
    ].
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5441
    ^ self species named:newName.
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5442
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5443
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5444
     '~' asFilename withSpecialExpansions
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5445
     '~/Desktop' asFilename withSpecialExpansions
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5446
     '~stefan' asFilename withSpecialExpansions
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5447
     '~stefan/Desktop' asFilename withSpecialExpansions
8947
da598dad55a5 withSpecialExpansions
Claus Gittinger <cg@exept.de>
parents: 8946
diff changeset
  5448
    "
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5449
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5450
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5451
!Filename methodsFor:'queries-contents'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5452
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5453
mimeTypeFromName
16578
0ed0b88c0bc8 class: Filename
Claus Gittinger <cg@exept.de>
parents: 16547
diff changeset
  5454
    "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
  5455
     This could be less accurate than mimeTypeOfContents, but avoids
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5456
     reading the file (is therefore much faster).
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5457
     Also it works with non-existing files.
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5458
     Returns nil for directories and other non-regular files."
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5459
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  5460
    |mimeTypes|
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  5461
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  5462
    "/ kludge to avoid making libview a prereq. of libbasic
17112
b9ec1d0b917a class: Filename
Claus Gittinger <cg@exept.de>
parents: 17111
diff changeset
  5463
    (mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[
21693
8c474e0a692b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21496
diff changeset
  5464
        ^ mimeTypes mimeTypeForFilename:self
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  5465
    ].
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  5466
    ^ nil
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5467
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5468
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5469
     'Makefile' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5470
     '.' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5471
     '/dev/null' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5472
     '/tmp/.X11-unix/X0' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5473
     'smalltalk.rc' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5474
     'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5475
     '../../rules/stmkmf' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5476
     '/bläh' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5477
     '/x.zip' asFilename mimeTypeFromName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5478
     '/x.gz' asFilename mimeTypeFromName
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5479
    "
21693
8c474e0a692b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21496
diff changeset
  5480
8c474e0a692b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 21496
diff changeset
  5481
    "Modified: / 11-04-2017 / 09:36:30 / cg"
7291
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5482
!
54040b551489 +mimeTypeFromName
Claus Gittinger <cg@exept.de>
parents: 7261
diff changeset
  5483
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5484
mimeTypeOfContents
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5485
    "this tries to guess the mime type of contents of
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5486
     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
  5487
     or the contents is unknown.
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5488
     This is done using some heuristics, and may need some improvement"
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5489
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  5490
    |type buffer s mimeTypes|
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5491
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  5492
    type := self type.
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  5493
    type isNil ifTrue:[ ^ nil ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5494
    type == #directory ifTrue:[ ^ nil ].
11406
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  5495
    type == #characterSpecial ifTrue:[ ^ nil ].
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  5496
    type == #blockSpecial ifTrue:[ ^ nil ].
af2c2118e164 refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents: 11397
diff changeset
  5497
    type == #socket ifTrue:[ ^ nil ].
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5498
    self fileSize == 0 ifTrue:[^ nil].
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5499
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  5500
    s := self readStreamOrNil.
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  5501
    s isNil ifTrue:[^ nil].
23867
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5502
    [
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5503
        "/ read some data from the file ...
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5504
        buffer := String new:2048.
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5505
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5506
        s errorSignal catch:[
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5507
            s nextBytes:(buffer size min:self fileSize) into:buffer.
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5508
        ].
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5509
    ] ensure:[
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5510
        s close.
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5511
    ].
3c002c21cc88 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 23837
diff changeset
  5512
    
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  5513
    "/ kludge to avoid making libview a prereq. of libbasic
17111
748d567580b5 class: Filename
Claus Gittinger <cg@exept.de>
parents: 17048
diff changeset
  5514
    (mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  5515
        ^ mimeTypes mimeTypeOfData:buffer suffix:self suffix.
16755
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  5516
    ].
c71ec8d77abd class: Filename
Claus Gittinger <cg@exept.de>
parents: 16676
diff changeset
  5517
    ^ nil
5011
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5518
192fd647de07 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 4979
diff changeset
  5519
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5520
     'Makefile' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5521
     '.' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5522
     '/dev/null' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5523
     '/tmp/.X11-unix/X0' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5524
     'smalltalk.rc' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5525
     'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5526
     '../../rules/stmkmf' asFilename mimeTypeOfContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5527
     '/bläh' asFilename mimeTypeOfContents
10153
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  5528
     'C:\Dokumente und Einstellungen\cg\Favoriten\languages.lnk' asFilename mimeTypeOfContents
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5529
     'G:\A\A01.TOP' asFilename mimeTypeOfContents
24379
852be153b0ec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24235
diff changeset
  5530
     '~/work/exept/expecco/plugin/labView/docs/labview_help_371361t/lvcomm.chm' asFilename mimeTypeOfContents
10153
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  5531
    "
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  5532
73f14e708d88 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 10020
diff changeset
  5533
    "Modified: / 06-11-2006 / 11:44:58 / cg"
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  5534
    "Modified: / 06-02-2019 / 11:52:46 / Stefan Vogel"
24379
852be153b0ec #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24235
diff changeset
  5535
    "Modified (comment): / 27-06-2019 / 16:34:25 / Claus Gittinger"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5536
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5537
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5538
!Filename methodsFor:'queries-path & name'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5539
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5540
baseName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5541
    "return my baseName as a string.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5542
     - that's the file/directory name without leading parent-dirs.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5543
     (i.e. '/usr/lib/st/file' asFilename baseName -> 'file'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5544
       and '/usr/lib'         asFilename baseName -> lib).
7075
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  5545
     This method does not check if the path is valid.
b65050c754de *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7074
diff changeset
  5546
     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
  5547
     for VMS (and maybe others as well).
2911
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  5548
     See also: #pathName, #directoryName and #directoryPathName.
9964e6839a8e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2908
diff changeset
  5549
     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
  5550
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5551
    |len index sep endIdx|
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5552
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5553
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5554
    len := nameString size.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5555
    ((len == 1) and:[(nameString at:1) == sep]) ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5556
        ^ nameString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5557
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5558
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5559
    endIdx := len.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5560
    len > 1 ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5561
        (nameString at:len) == sep ifTrue:[endIdx := endIdx - 1].
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5562
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5563
    index := nameString lastIndexOf:sep startingAt:len-1.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5564
    ^ 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
  5565
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5566
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5567
     '/foo/bar' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5568
     '/foo/bar.cc' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5569
     '.' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5570
     '..' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5571
     '../..' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5572
     '../../libbasic' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5573
     '../../libpr' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5574
     '../../libbasic/Object.st' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5575
     '/' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5576
     '\' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5577
     'c:\' asFilename baseName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5578
     '\\idefix' asFilename baseName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5579
    "
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5580
3851
dff883b7d72a comments only
Claus Gittinger <cg@exept.de>
parents: 3847
diff changeset
  5581
    "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
  5582
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5583
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5584
directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5585
    "return the directory name part of the file/directory as a new filename.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5586
     - that's a filename for the directory where the file/dir represented by
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5587
       the receiver is contained in.
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5588
     (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
  5589
      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
  5590
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5591
    ^ self species named:(self directoryName)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5592
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5593
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5594
     '/foo/bar' asFilename directory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5595
     '/foo/bar' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5596
     '/foo/bar' asFilename head
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5597
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5598
     '.' asFilename directory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5599
     '..' asFilename directory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5600
     '../..' asFilename directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5601
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5602
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5603
    "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
  5604
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5605
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5606
directoryName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5607
    "return the directory name part of the file/directory as a string.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5608
     - that's the name of the directory where the file/dir represented by
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5609
       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
  5610
     This method does not check if the path is valid.
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5611
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5612
     (i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st'
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5613
       and '/usr/lib' asFilename directoryName         -> /usr').
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5614
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5615
     (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
  5616
      a string instead of a Filename instance).
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5617
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5618
     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
  5619
     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
  5620
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5621
    |index sep sepString p rest parentDirectoryString|
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5622
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5623
    sep := self separator.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5624
    sepString := sep asString.
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5625
    (nameString = sepString) ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5626
        "/
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5627
        "/ the trivial '/' case
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5628
        "/
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5629
        ^ sepString
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5630
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5631
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5632
    "/
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  5633
    "/ strip off multiple trailing slashes
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5634
    "/
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5635
    p := nameString.
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5636
    [p endsWith:sep] whileTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5637
        (p = sepString) ifTrue:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5638
            ^ sepString
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5639
        ].
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5640
        p := p copyButLast:1
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5641
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5642
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5643
    parentDirectoryString := self class parentDirectoryName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5644
24403
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5645
    "/ (p startsWith:(parentDirectoryString,sepString)) ifTrue:[
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5646
    "/     ^ parentDirectoryString, sepString, p
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5647
    "/ ].
22850
611e4d3c238b #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22685
diff changeset
  5648
3886
e6efeb877eda fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents: 3876
diff changeset
  5649
    "/ strip off trailing components
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  5650
    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
  5651
    index == 0 ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5652
        "/ no separator found
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5653
        p = '.' ifTrue:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5654
            ^ parentDirectoryString
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5655
        ].
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5656
        p = '..' ifTrue:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5657
            ^ parentDirectoryString, sepString, parentDirectoryString
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5658
        ].
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5659
        ^ '.'
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  5660
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  5661
    rest := p copyFrom:(index+1).
7342
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  5662
    (rest = '.') ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5663
        ^ p copyTo:index-1.
7342
4e9ff418113f fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents: 7332
diff changeset
  5664
    ].
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5665
    (rest = parentDirectoryString) ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5666
        ^ (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
  5667
    ].
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  5668
    index == 1 ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5669
        ^ sepString
3893
2d701f7a02db fixed #directoryName
ps
parents: 3888
diff changeset
  5670
    ].
3888
a528db31e5c0 had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents: 3886
diff changeset
  5671
    ^ p copyTo:(index - 1)
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5672
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5673
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5674
     '/home' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5675
     '/foo/bar/' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5676
     '/foo/bar/' asFilename directory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5677
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5678
     '/foo/bar' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5679
     'bitmaps' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5680
     'bitmaps' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5681
     '.' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5682
     '.' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5683
     '..' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5684
     '..' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5685
     '../..' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5686
     '../..' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5687
     '/foo/bar/baz/..' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5688
     '/foo/bar/baz/.' asFilename directoryName
21064
6e751ba6ddd3 #QUALITY by stefan
Stefan Vogel <sv@exept.de>
parents: 21045
diff changeset
  5689
     'c:\' asFilename directoryName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5690
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5691
24403
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5692
    "Modified: / 07-09-1995 / 10:42:03 / claus"
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5693
    "Modified: / 21-10-1998 / 22:52:25 / cg"
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5694
    "Modified: / 27-10-1998 / 13:19:26 / ps"
2381ea8610f7 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 24382
diff changeset
  5695
    "Modified: / 08-07-2019 / 01:30:37 / Claus Gittinger"
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5696
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5697
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5698
directoryPathName
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5699
    "return the full directory pathname part of the file/directory as a string.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  5700
     - that's the full pathname of the directory where the file/dir represented by
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5701
       the receiver is contained in.
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5702
     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
  5703
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5704
    ^ (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
  5705
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5706
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5707
     '/foo/bar/' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5708
     '/foo/bar' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5709
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5710
     '.' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5711
     '.' asFilename directoryName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5712
     '.' asFilename directory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5713
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5714
     '..' asFilename directoryPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5715
     '..' asFilename directoryName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5716
     '..' asFilename directory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5717
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5718
     '../..' asFilename directoryPathName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5719
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5720
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5721
    "Modified: 7.9.1995 / 10:42:13 / claus"
2012
d12efa0481bc commentary
Claus Gittinger <cg@exept.de>
parents: 1993
diff changeset
  5722
    "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
  5723
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5724
14567
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  5725
encodedNameString
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  5726
    "answer the name as passed to OS system calls"
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  5727
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  5728
    ^ OperatingSystem encodePath:nameString
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  5729
!
757c038e8a90 class: Filename
Stefan Vogel <sv@exept.de>
parents: 14513
diff changeset
  5730
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5731
filenameCompletion
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5732
    "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
  5733
     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
  5734
     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
  5735
       it returns a collection of matching filename objects,
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  5736
       and changes the receiver's 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
  5737
       match.
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  5738
     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
  5739
     If there is only one match, the size of the returned collection is exactly 1,
19752
eba7ee9bb48c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 19670
diff changeset
  5740
     containing the fully expanded filename and the receiver's name is changed to it."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5741
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5742
    ^ self filenameCompletionIn:nil
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5743
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5744
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5745
     'mak' asFilename filenameCompletion
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5746
     'Make' asFilename filenameCompletion
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5747
     'Makef' asFilename filenameCompletion;yourself
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5748
     '/u' asFilename filenameCompletion
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5749
     '../../libpr' asFilename inspect filenameCompletion
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5750
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5751
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  5752
    "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
  5753
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5754
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5755
filenameCompletionIn:aDirectory
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5756
    "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
  5757
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  5758
     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
  5759
     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
  5760
       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
  5761
       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
  5762
     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
  5763
     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
  5764
     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
  5765
     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
  5766
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5767
    |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
  5768
     sepString parentString prefix nMatch nm caseless lcBaseName|
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  5769
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5770
    mySpecies := self species.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5771
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5772
    caseless := mySpecies isCaseSensitive not.
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  5773
    matching := OrderedCollection new.
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  5774
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5775
    nm := mySpecies nameWithSpecialExpansions:nameString.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5776
    nm := mySpecies canonicalize:nm.
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5777
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5778
    sepString := mySpecies separatorString.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  5779
    (nm endsWith:sepString) ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5780
        "/ two exceptions here:
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5781
        "/   if there is only one file in the directory, that one must be it.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5782
        "/   otherwise, return the longest common prefix of all files.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5783
        self isDirectory ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5784
            |first longest|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5785
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5786
            first := nil.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5787
            OpenError catch:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5788
                self directoryContentsDo:[:fileName |
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5789
                    ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5790
                        matching add:fileName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5791
                        first isNil ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5792
                            first := longest := fileName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5793
                        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5794
                            "/ more than one file
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5795
                            longest := longest commonPrefixWith:fileName ignoreCase:caseless.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5796
                            longest isEmpty ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5797
                                ^ #()
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5798
                            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5799
                        ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5800
                    ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5801
                ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5802
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5803
            longest notNil ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5804
                nameString := (self constructString:longest).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5805
                 ^ matching
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5806
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5807
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5808
        ^ #()
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5809
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5810
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  5811
    parentString := mySpecies parentDirectoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5812
    baseName := self baseName.
3666
90d78fa83c50 tilde expansion.
Claus Gittinger <cg@exept.de>
parents: 3665
diff changeset
  5813
    baseName ~= nm ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5814
        prefix := self directoryName.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5815
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5816
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5817
    self isAbsolute ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5818
        dir := self directory
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5819
    ] ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5820
        aDirectory isNil ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5821
            dir := self directory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5822
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5823
            dir := (aDirectory asFilename construct:nm) directory
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5824
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5825
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5826
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  5827
    caseless ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5828
        lcBaseName := baseName asLowercase
3774
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  5829
    ].
e2a75c79c625 ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents: 3768
diff changeset
  5830
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  5831
    dir class errorReporter openErrorSignal handle:[:ex|
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5832
        ^ #().
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  5833
    ] do:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5834
        dir directoryContents do:[:fileName |
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5835
            ((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5836
                ((caseless and:[fileName asLowercase startsWith:lcBaseName])
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5837
                or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5838
                    matching add:fileName
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5839
                ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5840
            ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5841
        ].
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5842
    ].
6556
367bc84f51fc filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents: 6529
diff changeset
  5843
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5844
    (nMatch := matching size) > 1 ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5845
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5846
         find the longest common prefix
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5847
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5848
        matchLen := baseName size.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5849
        matchLen > matching first size ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5850
            try := baseName.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5851
            allMatching := false
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5852
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5853
            try := matching first copyTo:matchLen.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5854
            allMatching := true.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5855
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5856
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5857
        [allMatching] whileTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5858
            matching do:[:aName |
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5859
                ((caseless and:[aName asLowercase startsWith:try asLowercase])
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5860
                or:[caseless not and:[aName startsWith:try]]) ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5861
                    allMatching := false
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5862
                ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5863
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5864
            allMatching ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5865
                matchLen <  matching first size ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5866
                    matchLen := matchLen + 1.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5867
                    try := matching first copyTo:matchLen.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5868
                ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5869
                    allMatching := false
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5870
                ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5871
            ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5872
                try := matching first copyTo:matchLen - 1.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5873
            ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5874
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5875
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5876
         and set my name to the last full match
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5877
        "
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5878
        nameString := nm := try
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5879
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5880
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5881
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5882
     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
  5883
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5884
    prefix notNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5885
        (prefix endsWith:sepString) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5886
            "/ avoid introducing double slashes
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5887
            prefix := prefix copyButLast:(sepString size).
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5888
        ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5889
        matching := matching collect:[:n | prefix , sepString , n].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5890
        nMatch == 1 ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5891
            nameString := nm := matching first
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5892
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5893
            nMatch > 1 ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5894
                nameString := nm := prefix , sepString , nm
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5895
            ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5896
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5897
    ] ifFalse:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5898
        nMatch == 1 ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5899
            nameString := nm := matching first
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  5900
        ]
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5901
    ].
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5902
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5903
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5904
     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
  5905
     (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
  5906
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5907
    ^ matching
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5908
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5909
    " trivial cases:
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5910
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5911
     '../' asFilename filenameCompletion     -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5912
     '/' asFilename filenameCompletion       -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5913
     '/usr/' asFilename filenameCompletion   -> empty
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5914
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5915
     'mak' asFilename filenameCompletion
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5916
     'Make' asFilename filenameCompletion
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5917
     'Makef' asFilename filenameCompletion
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5918
     '/u' asFilename filenameCompletion
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  5919
     '../../libpr' asFilename filenameCompletion
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  5920
     '/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
  5921
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5922
     '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
  5923
     'c:\pr' asFilename filenameCompletion; yourself   -> side effect: name changed to longest match
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5924
     'c:\p' asFilename filenameCompletion
11341
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5925
     'c:\' asFilename filenameCompletion  -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5926
     'c:' asFilename filenameCompletion   -> empty
22494c109161 fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents: 11192
diff changeset
  5927
     '\' asFilename filenameCompletion    -> empty
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5928
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5929
10793
0475c364e80a care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents: 10780
diff changeset
  5930
    "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
  5931
    "Modified: / 17-11-2007 / 14:31:08 / cg"
2903
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  5932
!
e64704e86cce various VMS changes
Claus Gittinger <cg@exept.de>
parents: 2896
diff changeset
  5933
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5934
head
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5935
    "return the directory name as a string.
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5936
     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
  5937
     (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
  5938
      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
  5939
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5940
    ^ self directoryName
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
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5943
     Filename currentDirectory head
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5944
     'Makefile' asFilename head
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5945
     '/foo/bar/baz.st' asFilename head
1049
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
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5948
    "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
  5949
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  5950
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5951
isAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5952
    "return true, if the receiver represents an absolute pathname
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5953
     (in contrast to one relative to the current directory)."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5954
23506
757d14838de2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23420
diff changeset
  5955
    ^ ((self osNameForAccess startsWith:self species separator) 
757d14838de2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23420
diff changeset
  5956
       or:[self isVolumeAbsolute]) 
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5957
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5958
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5959
     '/foo/bar' asFilename isAbsolute
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  5960
     '~/bla' asFilename isAbsolute
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5961
     '..' asFilename isAbsolute
20459
bcf7672c33ad #DOCUMENTATION by mawalch
mawalch
parents: 20457
diff changeset
  5962
     '..' asFilename asAbsoluteFilename isAbsolute
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5963
     'source/SBrowser.st' asFilename isAbsolute
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5964
     'source/SBrowser.st' asFilename isRelative
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5965
     'SBrowser.st' asFilename isRelative
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5966
    "
23506
757d14838de2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23420
diff changeset
  5967
757d14838de2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23420
diff changeset
  5968
    "Modified: / 05-11-2018 / 11:08:34 / Stefan Vogel"
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5969
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5970
21390
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5971
isBackupFilename
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5972
    "return true, if this name is an for a backup file"
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5973
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5974
    ^ nameString last == $~ or:[self hasSuffix:'bak'].
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5975
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5976
    "Created: / 09-02-2017 / 13:57:03 / stefan"
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5977
!
c3b93c1dad80 #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 21263
diff changeset
  5978
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5979
isExplicitRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5980
    "return true, if this name is an explicit relative name
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5981
     (i.e. starts with './' or '../', to avoid path-prepending)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5982
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5983
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5984
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5985
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5986
isImplicit
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5987
    "return true, if the receiver represents a builtin file.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5988
     The definitions of builtin files depends on the OS used;
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5989
     on UNIX, '.' and '..' are builtin names."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5990
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5991
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5992
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5993
    "Created: 18.9.1997 / 18:04:51 / stefan"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5994
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  5995
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  5996
isParentDirectoryOf:aFilenameOrString
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5997
    "Answer true, if myself is a parent directory of aFilenameOrString.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  5998
     Unexpected results may be returned, if one of myself or aFilenameOrString does
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  5999
     not exist and relative and absolute path names are mixed
18686
a2af6c2de3ec class: Filename
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  6000
     ('/' asFilename isParentDirectoryOf:'../noExistent' -> false)
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6001
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6002
     Warning: maybe symbolic links must be resolved which could lead to automounting"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6003
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6004
    |filenameArg otherNames myNames myName|
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6005
7236
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  6006
    filenameArg := aFilenameOrString asFilename.
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6007
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6008
    "first do a simple comparison"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6009
    otherNames := self class canonicalizedNameComponents:filenameArg name.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6010
    myNames := self class canonicalizedNameComponents:self name.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6011
    ((otherNames startsWith:myNames) and:[myNames first ~= self class parentDirectoryName]) ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6012
        ^ otherNames ~= myNames
7236
2b8b8680f5b9 isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents: 7134
diff changeset
  6013
    ].
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6014
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6015
    "fall back - try it again with ~ substitution and symbolic links resolved"
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6016
    otherNames := self class canonicalizedNameComponents:filenameArg pathName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6017
    myNames := self class canonicalizedNameComponents:self pathName.
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6018
    (otherNames startsWith:myNames) ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6019
        ^ otherNames ~= myNames
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6020
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6021
16389
ea2d1cc54f21 class: Filename
Stefan Vogel <sv@exept.de>
parents: 16382
diff changeset
  6022
    myName := self class nameFromComponents:myNames.
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6023
    filenameArg allParentDirectoriesDo:[:parent |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6024
        parent pathName = myName ifTrue:[^ true].
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6025
    ].
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6026
    ^ false.
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6027
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6028
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6029
     '/etc' asFilename isParentDirectoryOf:'/etc/passwd'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6030
     'etc' asFilename isParentDirectoryOf:'etc/passwd'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6031
     '/etc' asFilename isParentDirectoryOf:'/etc/'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6032
     '/etc' asFilename isParentDirectoryOf:'/etc'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6033
     '/et' asFilename isParentDirectoryOf:'/etc'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6034
     '/home' asFilename isParentDirectoryOf:Filename currentDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6035
     '~' asFilename isParentDirectoryOf:Filename currentDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6036
     '~' asFilename isParentDirectoryOf:'.'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6037
     '~' asFilename isParentDirectoryOf:'..'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6038
     '~' asFilename isParentDirectoryOf:'../smalltalk'
18686
a2af6c2de3ec class: Filename
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  6039
     '../..' asFilename isParentDirectoryOf:'../nonExistent'
a2af6c2de3ec class: Filename
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  6040
     '..' asFilename isParentDirectoryOf:'../../nonExistent'
a2af6c2de3ec class: Filename
Claus Gittinger <cg@exept.de>
parents: 18667
diff changeset
  6041
     '/' asFilename isParentDirectoryOf:'../nonExistent'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6042
     '/' asFilename isParentDirectoryOf:'/phys/qnx'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6043
    "
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6044
!
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6045
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6046
isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6047
    "return true, if this name is interpreted relative to some
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6048
     directory (opposite of absolute)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6049
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6050
    ^ self isAbsolute not
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6051
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6052
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6053
     './foo/bar' asFilename isRelative
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6054
     '../../foo/bar' asFilename isRelative
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6055
     '/foo/bar' asFilename isRelative
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6056
     'bar' asFilename isRelative
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6057
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6058
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6059
    "Modified: 16.1.1997 / 01:19:14 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6060
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6061
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6062
isRootDirectory
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6063
    "return true, if I represent the root directory
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6064
     (i.e. I have no parentDir)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6065
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6066
    "/ mhmh - should we use:
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6067
    "/
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6068
    "/ parentDir := self construct:'..'.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6069
    "/ (parentDir exists
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6070
    "/ and:[parentDir isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6071
    "/ and:[parentDir id ~= self id]]) ifTrue:[
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6072
    "/    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6073
    "/ ].
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6074
    "/ ^ true
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6075
    "/
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6076
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  6077
    ^ self pathName = self class rootDirectory pathName
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  6078
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  6079
    "Modified: / 23-10-1997 / 00:38:35 / cg"
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  6080
    "Modified: / 06-02-2019 / 11:56:36 / Stefan Vogel"
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6081
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6082
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6083
isVolumeAbsolute
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6084
    "return true, if the receiver represents an absolute pathname
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6085
     on some disk volume (MSDOS only)"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6086
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6087
    ^ false
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6088
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6089
    "Modified: 7.9.1997 / 23:54:33 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6090
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6091
2987
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6092
localPathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6093
    "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
  6094
     but without any volume information.
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6095
     Only makes a difference on MSDOS & VMS systems."
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6096
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6097
    ^ self pathName
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6098
!
87a7ad1f4519 Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents: 2982
diff changeset
  6099
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6100
name
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6101
    "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
  6102
     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
  6103
     See also: pathName"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6104
6773
26415b61ad09 isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents: 6771
diff changeset
  6105
"/    self isAbsolute ifTrue:[^ self pathName].
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6106
    ^ nameString
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6107
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6108
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6109
     '/foo/bar' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6110
     '/foo/bar' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6111
     '.' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6112
     '.' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6113
     '../..' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6114
     '../..' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6115
     'bitmaps' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6116
     'bitmaps' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6117
     '/tmp/../usr' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6118
     '/tmp/../usr' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6119
     'source/..' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6120
     'source/..' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6121
     '/tmp/..' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6122
     '/tmp/..' asFilename pathName
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  6123
    "
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  6124
883
78d6c8b2b9f0 commentary
Claus Gittinger <cg@exept.de>
parents: 845
diff changeset
  6125
    "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
  6126
!
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  6127
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6128
pathName
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6129
    "return the full pathname of the file represented by the receiver,
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6130
     as a string. This will not include ..'s.
1317
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  6131
     If the path represented by the receiver does NOT represent a valid path,
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  6132
     no compression will be done (for now; this may change).
cc737e0fdf48 examples
Claus Gittinger <cg@exept.de>
parents: 1286
diff changeset
  6133
     See also: name"
538
b9337c6c55bb added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents: 530
diff changeset
  6134
23630
484d0fd2e425 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23623
diff changeset
  6135
    ^ OperatingSystem pathNameOf:(self osNameForFile).
2
claus
parents: 1
diff changeset
  6136
92
0c73b48551ac *** empty log message ***
claus
parents: 88
diff changeset
  6137
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6138
     '/foo/bar' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6139
     '.' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6140
     '../..' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6141
     '../..' asFilename name
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6142
     '/tmp/../usr' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6143
     '/././usr' asFilename pathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6144
     '~/..' asFilename pathName
23601
07a4b950046b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23587
diff changeset
  6145
     '$JAVA_HOME/bin/java' asFilename pathName
07a4b950046b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23587
diff changeset
  6146
    "
07a4b950046b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23587
diff changeset
  6147
07a4b950046b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23587
diff changeset
  6148
    "Modified: / 27-04-1996 / 18:19:52 / cg"
23630
484d0fd2e425 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 23623
diff changeset
  6149
    "Modified: / 22-01-2019 / 14:49:43 / Stefan Vogel"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6150
!
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6151
22403
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6152
pathNameRelativeFrom:anotherDirectoriesFilename
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6153
    "return the pathname of the receiver,
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6154
     but relative from another directory.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6155
     I.e. if the receiver is /a/b/c
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6156
     and the argument is /a/x/y,
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6157
     then the relative path to the receiver as seen from the argument is ../../b/c"
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6158
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6159
    |myPath otherDir otherPath rest prefix|
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6160
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6161
    myPath := self pathName.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6162
    otherDir := anotherDirectoriesFilename asFilename.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6163
    prefix := ''.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6164
    [
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6165
        otherPath := otherDir pathName.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6166
        "/ if I am below:
23570
d1014cb93286 #BUGFIX by sr
sr
parents: 23506
diff changeset
  6167
        (myPath startsWith:otherPath caseSensitive:self class isCaseSensitive) ifTrue:[
22403
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6168
            rest := (myPath copyFrom:otherPath size+1).
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6169
            rest isEmpty ifTrue:[^ prefix,'.' ].
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6170
            (rest startsWith:self separator) ifTrue:[^ prefix,(rest copyFrom:2) ].
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6171
            ^ prefix,rest
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6172
        ].
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6173
        prefix := prefix,'..',self separator.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6174
        otherDir := otherDir directory.
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6175
    ] loop
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6176
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6177
    "
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6178
     self assert:('/a' asFilename pathNameRelativeFrom:'/') = 'a'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6179
     self assert:('/a/b' asFilename pathNameRelativeFrom:'/') = 'a/b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6180
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6181
     self assert:('/a' asFilename pathNameRelativeFrom:'/a') = '.'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6182
     self assert:('/a/b' asFilename pathNameRelativeFrom:'/a') = 'b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6183
     self assert:('/a/b/c' asFilename pathNameRelativeFrom:'/a') = 'b/c'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6184
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6185
     self assert:('/a/' asFilename pathNameRelativeFrom:'/a') = '.'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6186
     self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a') = 'b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6187
     self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a') = 'b/c'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6188
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6189
     self assert:('/a' asFilename pathNameRelativeFrom:'/a/') = '.'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6190
     self assert:('/a/b' asFilename pathNameRelativeFrom:'/a/') = 'b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6191
     self assert:('/a/b/c' asFilename pathNameRelativeFrom:'/a/') = ''b/c''  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6192
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6193
     self assert:('/a/' asFilename pathNameRelativeFrom:'/a/') = '.'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6194
     self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a/') = 'b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6195
     self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a/') = 'b/c'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6196
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6197
     self assert:('/a' asFilename pathNameRelativeFrom:'/b') = '../a'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6198
     self assert:('/a/b/' asFilename pathNameRelativeFrom:'/b') = '../a/b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6199
     self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/b') = '../a/b/c'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6200
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6201
     self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a') = 'b'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6202
     self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a') = 'b/c'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6203
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6204
     self assert:('/a/b/c/d' asFilename pathNameRelativeFrom:'/a/x/y/z') = '../../../b/c/d'  
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6205
    "
23570
d1014cb93286 #BUGFIX by sr
sr
parents: 23506
diff changeset
  6206
d1014cb93286 #BUGFIX by sr
sr
parents: 23506
diff changeset
  6207
    "Modified: / 19-12-2018 / 11:17:07 / sr"
22403
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6208
!
a4396e2a038e #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22401
diff changeset
  6209
11658
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6210
physicalFilename
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6211
    "return the fileName representing the physical file as represented by the receiver,
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6212
     If the receiver represents a symbolic link, that's the fileName of the
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  6213
     final target. Otherwise, its the receiver's pathName itself.
11658
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6214
     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
  6215
     nil is returned."
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6216
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6217
    |pathOrNil|
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6218
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6219
    pathOrNil := self physicalPathName.
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6220
    pathOrNil isNil ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6221
        ^ nil
11658
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6222
    ].
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6223
    ^ pathOrNil asFilename
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6224
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6225
    "
20708
652af4edc84a #DOCUMENTATION by mawalch
mawalch
parents: 20694
diff changeset
  6226
     '/foo/bar' asFilename physicalFilename
11658
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6227
    "
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6228
!
eea5b22770f5 +physicalFilename
Claus Gittinger <cg@exept.de>
parents: 11657
diff changeset
  6229
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6230
physicalPathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6231
    "return the full pathname of the physical file represented by the receiver,
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6232
     If the receiver represents a symbolic link, that's the fileName of the
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  6233
     final target. Otherwise, its the receiver's pathName itself.
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6234
     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
  6235
     nil is returned."
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6236
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  6237
    |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
  6238
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  6239
    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
  6240
    info isNil ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6241
        " I do not exist"
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6242
        ^ nil.
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6243
    ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  6244
    info isSymbolicLink ifFalse:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6245
        ^ self pathName
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  6246
    ].
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  6247
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6248
    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
  6249
    [
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6250
        path := info path.
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6251
        path isNil ifTrue:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6252
            "/ cannot happen
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6253
            ^ nil
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6254
        ].
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6255
        path asFilename isAbsolute ifTrue:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6256
            t := path asFilename
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6257
        ] ifFalse:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6258
            t := (self species named:t directoryName) construct:path.
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6259
        ].
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6260
        info := t linkInfo.
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6261
        info isNil ifTrue:[
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6262
            "t does not exist"
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6263
             ^ nil
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6264
        ].
8477
c962d56c1973 #linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents: 8280
diff changeset
  6265
    ] 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
  6266
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6267
    ^ t pathName
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6268
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6269
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6270
     '/foo/bar' asFilename physicalPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6271
     '.' asFilename physicalPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6272
     '../..' asFilename physicalPathName
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6273
     '/usr/tmp' asFilename physicalPathName
2013
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6274
    "
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6275
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6276
    "Modified: 21.12.1996 / 15:29:50 / cg"
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6277
!
5053effe0156 commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents: 2012
diff changeset
  6278
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6279
tail
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6280
    "the file's name without directory prefix as a string.
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6281
     An alias for baseName, for ST-80 compatiblity."
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  6282
615
e9d0e782206d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 545
diff changeset
  6283
    ^ self baseName
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6284
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6285
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6286
     Filename currentDirectory tail
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6287
     'Makefile' asFilename tail
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6288
     '/foo/bar/baz.st' asFilename tail
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6289
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6290
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6291
    "Modified: 29.2.1996 / 20:19:50 / cg"
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  6292
!
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  6293
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6294
tail:nComponents
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6295
    "return the last n components of myself.
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6296
     - that's the file/directory name without leading parent-dirs.
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6297
     (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
  6298
       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
  6299
     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
  6300
     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
  6301
     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
  6302
     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
  6303
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6304
    |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
  6305
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  6306
    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
  6307
    components := self components.
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6308
    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
  6309
    start < 1 ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6310
        start := 1.
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6311
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6312
    start = 1 ifTrue:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6313
        tail := ''
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6314
    ] ifFalse:[
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6315
        tail := components at:start.
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6316
    ].
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6317
    start+1 to:components size do:[:i|
20413
f3058cc528c2 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 20293
diff changeset
  6318
        tail := tail, sep, (components at:i).
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6319
    ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6320
    ^ tail.
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6321
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6322
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6323
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6324
     '/foo/bar' asFilename tail:1
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6325
     '/foo/bar' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6326
     '/foo/bar' asFilename tail:3
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6327
     '/foo/bar.cc' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6328
     '.' asFilename tail:3
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6329
     '..' asFilename tail:3
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6330
     '../..' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6331
     '../../libbasic' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6332
     '../../libbasic' asFilename asCanonicalizedFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6333
     '../../libpr' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6334
     '../../libbasic/Object.st' asFilename asCanonicalizedFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6335
     '/' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6336
     '\' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6337
     'c:\' asFilename tail:2
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6338
     '\\idefix' asFilename tail:2
7307
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6339
    "
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6340
!
9cae11d1fea1 new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents: 7291
diff changeset
  6341
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  6342
volume
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  6343
    "return the disc volume part of the name or an empty string.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6344
     This is only used with MSDOS and VMS filenames
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6345
     - by default (and on unix), an empty string is returned"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6346
2629
38fb6d7bfeb2 volume stuff for windows
Claus Gittinger <cg@exept.de>
parents: 2601
diff changeset
  6347
    ^ ''
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6348
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6349
    "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
  6350
! !
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6351
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6352
!Filename methodsFor:'queries-type'!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6353
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6354
isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6355
    "return true, if the receiver represents an existing,
23420
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6356
     readable directories pathname.
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6357
     Symbolic links pointing to a directory answer true."
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6358
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6359
    ^ OperatingSystem isDirectory:(self osNameForAccess)
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6360
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6361
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6362
     '/foo/bar' asFilename isDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6363
     '/tmp' asFilename isDirectory
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6364
     'Makefile' asFilename isDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6365
     'c:\' asFilename isDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6366
     'd:\' asFilename isDirectory
23632
5b8f61358650 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23630
diff changeset
  6367
     '\\host\dir' asFilename isDirectory
5b8f61358650 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23630
diff changeset
  6368
     OperatingSystem isDirectory:'\\host\dir'
5b8f61358650 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23630
diff changeset
  6369
    "
5b8f61358650 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23630
diff changeset
  6370
5b8f61358650 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23630
diff changeset
  6371
    "Modified: / 21-09-1998 / 15:53:10 / cg"
5b8f61358650 #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23630
diff changeset
  6372
    "Modified (comment): / 22-01-2019 / 15:14:45 / Stefan Vogel"
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6373
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6374
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6375
isNonEmptyDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6376
    "return true, if the receiver represents an existing,
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6377
     readable directories pathname, and the directory is not empty."
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6378
8280
0caa2f092e45 avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents: 8243
diff changeset
  6379
    FileStream openErrorSignal
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6380
        handle:[:ex| ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6381
        do:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6382
            self directoryContentsDo:[:pathString|^ true].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6383
        ].
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6384
    ^ false.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6385
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6386
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6387
     '/foo/bar' asFilename isNonEmptyDirectory
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6388
     '/tmp' asFilename isNonEmptyDirectory
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6389
     '/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6390
     '/tmp/empty' asFilename removeDirectory.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6391
     'Makefile' asFilename isNonEmptyDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6392
     'c:\' asFilename isNonEmptyDirectory
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6393
     'd:\' asFilename isNonEmptyDirectory
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6394
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6395
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6396
    "Modified: / 21.9.1998 / 15:53:10 / cg"
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6397
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6398
8836
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6399
isRegularFile
23420
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6400
    "return true, if the receiver represents a plain, regular file.
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6401
     Symbolic links pointing to a regular file answer true."
8836
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6402
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6403
    ^ self type == #regular
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6404
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6405
    "
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6406
     '/foo/bar' asFilename isRegularFile
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6407
     '/tmp' asFilename isRegularFile
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6408
     'Makefile' asFilename isRegularFile
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6409
     'c:\' asFilename isRegularFile
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6410
     'd:\' asFilename isRegularFile
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6411
     '/dev/null' asFilename isRegularFile
8836
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6412
    "
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6413
!
e442467b2c69 New: #isRegularFile
Stefan Vogel <sv@exept.de>
parents: 8771
diff changeset
  6414
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6415
isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6416
    "return true, if the receiver represents a socket, named pipe, fifo
23420
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6417
     or device special file (i.e. anything non regular and non-directory).
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6418
     Symbolic links pointing to a special file answer true."
55aa94bc649b #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 23407
diff changeset
  6419
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6420
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6421
    |t|
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6422
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6423
    t := self type.
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6424
    ^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]])
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6425
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6426
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6427
     '/foo/bar' asFilename isSpecialFile
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6428
     '/tmp' asFilename isSpecialFile
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6429
     'Makefile' asFilename isSpecialFile
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6430
     'c:\' asFilename isSpecialFile
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6431
     'd:\' asFilename isSpecialFile
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6432
     '/dev/null' asFilename isSpecialFile
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6433
    "
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6434
!
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6435
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6436
isSymbolicLink
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6437
    "return true, if the file represented by the receiver is a symbolic
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  6438
     link. Notice that not all OS's support symbolic links; 
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  6439
     those that do not will always return false."
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6440
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6441
    ^ OperatingSystem isSymbolicLink:(self osNameForFile)
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6442
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6443
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6444
     'Make.proto' asFilename isSymbolicLink
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6445
     'Makefile' asFilename isSymbolicLink
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6446
    "
22127
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  6447
831363a08ccd #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 21779
diff changeset
  6448
    "Modified (comment): / 27-07-2017 / 16:03:43 / stefan"
7120
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6449
! !
da18863f943b category changes
Claus Gittinger <cg@exept.de>
parents: 7115
diff changeset
  6450
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6451
!Filename methodsFor:'reading-directories'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6452
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6453
directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6454
    "return the contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6455
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6456
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6457
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6458
     So users of this method better test for existing directory before.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6459
     Notice:
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6460
        this returns the file-names as strings;
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6461
        see also #directoryContentsAsFilenames, which returns fileName instances."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6462
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6463
    ^ OrderedCollection withCollectedContents:[:coll |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6464
        self directoryContentsDo:[:each | coll add:each]] 
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6465
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6466
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6467
     '.' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6468
     '/XXXdoesNotExist' asFilename directoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6469
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6470
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6471
    "Modified: / 18.9.1997 / 18:42:23 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6472
    "Modified: / 3.8.1998 / 21:36:21 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6473
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6474
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6475
directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6476
    "return the contents of the directory as a collection of filenames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6477
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6478
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6479
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6480
     So users of this method better test for existing directory before.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6481
     Notice:
19821
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6482
        this returns the file-names as fileName instances;
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6483
        see also #directoryContents, which returns strings."
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6484
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6485
    ^ OrderedCollection withCollectedContents:[:coll |
1d873302be8b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19752
diff changeset
  6486
        self directoryContentsAsFilenamesDo:[:each | coll add:each]] 
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6487
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6488
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6489
     '.' asFilename directoryContentsAsFilenames
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6490
     '/XXXdoesNotExist' asFilename directoryContentsAsFilenames
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6491
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6492
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6493
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6494
fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6495
    "return the full contents of the directory as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6496
     This is much like #directoryContents, but includes an entry for the
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6497
     parent directory, if there is one.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6498
     Returns nil for non-existing directories; however, this behavior
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6499
     may be changed in the near future, to raise an exception instead.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6500
     So users of this method better test for existing directory before."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6501
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6502
    |files|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6503
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  6504
    "here we get the files without '.' and '..'"
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6505
    files := self directoryContents.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6506
    files isNil ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6507
        "/ mhmh - that one does not exist
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6508
        ^ files
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6509
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6510
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  6511
    files addFirst:'..'.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6512
    ^ files
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6513
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6514
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6515
     '.' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6516
     '/XXXdoesNotExist' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6517
     'd:\FET' asFilename fullDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6518
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6519
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6520
    "Modified: / 21.9.1998 / 15:33:07 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6521
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6522
23332
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6523
isEmptyDirectory
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6524
    "answer true, if this is an empty directory.
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6525
     Raise an exception, if this is not a directory."
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6526
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6527
    self directoryContentsDo:[:each | ^ false].
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6528
    ^ true
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6529
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6530
    "
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6531
     '.' asFilename isEmptyDirectory
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6532
     'Make.proto' asFilename isEmptyDirectory
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6533
     '/XXXdoesNotExist' asFilename isEmptyDirectory
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6534
    "
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6535
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6536
    "Created: / 12-09-2018 / 14:29:12 / Stefan Vogel"
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6537
!
92a3564b47ab #FEATURE by stefan
Stefan Vogel <sv@exept.de>
parents: 23253
diff changeset
  6538
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6539
recursiveDirectoryContents
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6540
    "return the contents of the directory and all subdirectories
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6541
     as a collection of strings.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6542
     This excludes any entries for '.' or '..'.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6543
     Subdirectory files are included with a relative pathname.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6544
     Notice:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6545
        this returns the file-names as strings;
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6546
        see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6547
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6548
     Warning: this may take a long time to execute."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6549
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6550
    |fileNames dirNames|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6551
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6552
    fileNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6553
    dirNames := OrderedCollection new.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6554
    self directoryContents do:[:f |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6555
        (self construct:f) isDirectory ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6556
            dirNames add:f
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6557
        ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6558
            fileNames add:f
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6559
        ]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6560
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6561
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6562
    dirNames do:[:dN |
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6563
        |dd subFiles|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6564
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6565
        dd := dN asFilename.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6566
        subFiles := (self construct:dN) recursiveDirectoryContents.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6567
        fileNames addAll:(subFiles collect:[:f | dd constructString:f])
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6568
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6569
    ^ fileNames.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6570
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6571
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6572
     '.' asFilename recursiveDirectoryContents
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6573
     '../../clients' asFilename recursiveDirectoryContents
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6574
    "
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6575
!
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6576
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6577
recursiveDirectoryContentsAsFilenames
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6578
    "return the contents of the directory and all subdirectories
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6579
     as a collection of filenames.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6580
     This excludes any entries for '.' or '..'.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6581
     Returns nil for non-existing directories; however, this behavior
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6582
     may be changed in the near future, to raise an exception instead.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6583
     So users of this method better test for existing directory before.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6584
     Notice:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6585
        this returns the file-names as fileName instances;
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6586
        see also #recursiveDirectoryContents, which returns strings.
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6587
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6588
     Warning: this may take a long time to execute."
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6589
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6590
    |names|
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6591
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6592
    names := self recursiveDirectoryContents.
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6593
    names isNil ifTrue:[^ nil].
12910
8d6cd403131f changed:
Stefan Vogel <sv@exept.de>
parents: 12617
diff changeset
  6594
    ^ names collect:[:entry | self construct:entry].
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6595
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6596
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6597
     '.' asFilename recursiveDirectoryContentsAsFilenames
7697
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6598
     '/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames
1cb1a31cd2c2 recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents: 7685
diff changeset
  6599
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6600
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6601
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6602
!Filename methodsFor:'reading-files'!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6603
22685
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6604
binaryContents
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6605
    "an alias.
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6606
     return the binary contents of the file (as a byteArray);
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6607
     Raises an error, if the file is unreadable/non-existing."
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6608
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6609
    ^ self binaryContentsOfEntireFile
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6610
!
fc5c7d36f46f #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 22676
diff changeset
  6611
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6612
binaryContentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6613
    "return the binary contents of the file (as a byteArray);
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  6614
     Raises an error, if the file is unreadable/non-existing."
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6615
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6616
    ^ self
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6617
        readingFileDo:[:s |
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6618
            |nBytes bytes n result|
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6619
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6620
            s binary.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6621
            nBytes := self fileSize.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6622
            (nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6623
                bytes := ByteArray uninitializedNew:nBytes.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6624
                n := s nextBytes:nBytes into:bytes startingAt:1.
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6625
                n == nBytes ifTrue:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6626
                    result := bytes
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6627
                ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6628
                    result := bytes copyTo:n
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6629
                ]
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6630
            ] ifFalse:[
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6631
                result := s contentsOfEntireFile
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6632
            ].
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6633
            result
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6634
        ]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6635
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6636
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6637
     'Makefile' asFilename binaryContentsOfEntireFile
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6638
     'foobar' asFilename binaryContentsOfEntireFile
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6639
    "
14446
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  6640
479f02b4c705 changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents: 14306
diff changeset
  6641
    "Modified: / 27-10-2012 / 19:42:07 / cg"
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6642
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6643
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6644
contents
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6645
    "Return the contents of the file as a collection of lines.
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6646
     Raise an error if the file is unreadable/non-existing.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6647
     See also #contentsOfEntireFile, which returns a string for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6648
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6649
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  6650
    ^ self readingFileDo:[:s | s contents].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6651
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6652
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6653
     'Makefile' asFilename contents
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6654
     'foobar' asFilename contents
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6655
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6656
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6657
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6658
    "Created: / 11.7.1996 / 14:09:11 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6659
    "Modified: / 15.10.1998 / 11:41:45 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6660
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6661
10780
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6662
contentsAsString
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6663
    "to compensate for the bad naming, use this to make things explicit.
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6664
     See also #contents, which returns the lines as stringCollection for textFiles."
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6665
11397
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  6666
    ^ self contentsOfEntireFile
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  6667
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  6668
    "
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  6669
     'Makefile' asFilename contentsAsString
872cd41bbe05 oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents: 11341
diff changeset
  6670
     'foobar' asFilename contentsAsString
10780
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6671
    "
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6672
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6673
    "Modified: / 02-07-1996 / 12:49:45 / stefan"
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6674
    "Created: / 08-11-2007 / 13:29:59 / cg"
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6675
!
6223f4f77b47 +contentsAsString
Claus Gittinger <cg@exept.de>
parents: 10779
diff changeset
  6676
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6677
contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6678
    "return the contents of the file as a string;
7680
38ac8980d896 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 7666
diff changeset
  6679
     Raises an error, if the file is unreadable/non-existing.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6680
     See also #contents, which returns the lines as stringCollection for textFiles.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6681
     CAVEAT: bad naming - but req'd for VW compatibility."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6682
7888
e76fa60251dc Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents: 7846
diff changeset
  6683
    ^ self readingFileDo:[:s | s contentsOfEntireFile].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6684
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6685
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6686
     'Makefile' asFilename contentsOfEntireFile
19043
c002993cc630 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 18952
diff changeset
  6687
     'smalltalk.rc' asFilename contentsOfEntireFile
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6688
     'foobar' asFilename contentsOfEntireFile
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6689
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6690
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6691
    "Modified: / 2.7.1996 / 12:49:45 / stefan"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6692
    "Modified: / 15.10.1998 / 11:42:05 / cg"
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6693
!
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6694
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6695
readingFileDo:aBlock
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6696
    "Create a read stream on the receiver file, evaluate aBlock, passing that stream as arg,
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6697
     and return the block's value.
7088
cc3233554827 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 7075
diff changeset
  6698
     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
  6699
     (old behavior, will vanish:)the block is evaluated with a nil argument.
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6700
     Ensures that the stream is closed."
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6701
22497
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6702
    |stream|
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6703
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6704
    stream := self readStream.
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6705
    ^ [
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6706
        aBlock value:stream
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6707
    ] ensure:[
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6708
        stream notNil ifTrue:[stream close]
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6709
    ].
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6710
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6711
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6712
     read the first line from some file:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6713
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6714
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6715
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6716
     rslt :=
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6717
        '/etc/passwd' asFilename
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6718
            readingFileDo:[:s |
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6719
                s nextLine
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6720
            ].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6721
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6722
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6723
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6724
    "
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6725
     find all used shells in /etc/passwd and count their usage:
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6726
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6727
     |rslt|
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6728
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6729
     rslt :=
20156
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6730
        '/etc/passwd' asFilename
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6731
            readingFileDo:
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6732
                [:s |
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6733
                    |shells|
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6734
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6735
                    shells := Bag new.
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6736
                    s linesDo:
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6737
                        [:line |
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6738
                            |parts|
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6739
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6740
                            parts := line asCollectionOfSubstringsSeparatedBy:$:.
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6741
                            shells add:(parts seventh).
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6742
                        ].
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6743
                    shells contents
3974eeb5115f #OTHER by mawalch
mawalch
parents: 20069
diff changeset
  6744
                ].
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6745
     Transcript showCR:rslt.
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6746
    "
22497
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6747
bf423cee57dd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 22448
diff changeset
  6748
    "Modified: / 12-01-2018 / 18:21:32 / stefan"
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6749
!
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6750
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6751
readingLinesDo:aBlock
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6752
    "Create a read stream on the receiver file and
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6753
     evaluate aBlock for each line read from the stream.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6754
     If the file cannot be opened, an error is raised.
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6755
     Ensures that the stream is closed."
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6756
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6757
    self readingFileDo:[:stream |
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6758
        stream linesDo:aBlock
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6759
    ].
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6760
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6761
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6762
    '/etc/passwd' asFilename
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6763
        readingLinesDo:[:eachLine |
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6764
            Transcript showCR:eachLine.
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6765
        ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6766
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6767
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6768
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6769
    '/etc/xxxxx' asFilename
20158
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6770
        readingLinesDo:[:eachLine |
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6771
            Transcript showCR:eachLine.
2e4c6347ef0b #DOCUMENTATION by mawalch
mawalch
parents: 20156
diff changeset
  6772
        ].
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  6773
    "
6529
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6774
! !
1d928f8c721a +readingFileDo:
Claus Gittinger <cg@exept.de>
parents: 6454
diff changeset
  6775
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6776
!Filename methodsFor:'special accessing'!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6777
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6778
osName
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6779
    "special - return the OS's name for the receiver.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6780
     Note: this may return an absolute pathName, if there are
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6781
           place holders in the name.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6782
           Otherwise it keeps the name relative or absolute as it is."
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6783
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6784
    self isDirectory ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6785
        ^ self osNameForDirectory
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6786
    ].
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6787
    ^ self osNameForFile
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6788
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6789
    "Modified (comment): / 12-04-2019 / 11:51:00 / Stefan Vogel"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6790
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6791
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  6792
osNameForAccess
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  6793
    "internal - return the OS's name for the receiver to
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  6794
     access its fileInfo.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  6795
     This may be redefined for systems, where a special suffix must be
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  6796
     added in order to access directories (or others) as a file.
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  6797
     (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
  6798
7064
e714c0a0dbbc long fileName (from DOS filename)
penk
parents: 6997
diff changeset
  6799
    ^ self osNameForFile
3665
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  6800
c73006c16a6f comments;
Claus Gittinger <cg@exept.de>
parents: 3658
diff changeset
  6801
    "Modified: / 21.7.1998 / 10:40:40 / cg"
2978
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  6802
!
e466e478fa43 Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents: 2977
diff changeset
  6803
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6804
osNameForDirectory
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  6805
    "internal - return the OS's name for the receiver to
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6806
     access it as a directory.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6807
     Note: this may return an absolute pathName, if there are
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6808
           place holders in the name.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6809
           Otherwise it keeps the name relative or absolute as it is."
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6810
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6811
14218
c87235c8bc2b changed:
Stefan Vogel <sv@exept.de>
parents: 14072
diff changeset
  6812
    ^ self osNameForFile
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  6813
24060
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6814
    "
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6815
        '.' asFilename osNameForDirectory
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6816
        '.' asFilename pathName
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6817
    "
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6818
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6819
    "Modified: / 12-08-1998 / 14:44:32 / cg"
8b906a9efccc #DOCUMENTATION by stefan
Stefan Vogel <sv@exept.de>
parents: 24049
diff changeset
  6820
    "Modified (comment): / 11-04-2019 / 18:13:09 / Stefan Vogel"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6821
!
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6822
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  6823
osNameForDirectoryContents
3753
20eb9177749b comments
Claus Gittinger <cg@exept.de>
parents: 3752
diff changeset
  6824
    "internal - return the OS's name for the receiver to
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6825
     access it as a directory when reading its contents.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6826
     Note: this may return an absolute pathName, if there are
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6827
           place holders in the name.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6828
           Otherwise it keeps the name relative or absolute as it is."
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  6829
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  6830
    ^ self osNameForDirectory
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  6831
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6832
    "Created: / 03-08-1998 / 21:36:06 / cg"
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6833
    "Modified: / 12-08-1998 / 14:44:34 / cg"
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6834
    "Modified (comment): / 12-04-2019 / 11:51:57 / Stefan Vogel"
3720
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  6835
!
d2529646d235 oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents: 3719
diff changeset
  6836
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6837
osNameForFile
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6838
    "internal - return the OS's name for the receiver to
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6839
     access it as a file.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6840
     Note: this may return an absolute pathName, if there are
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6841
           place holders in the name.
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6842
           Otherwise it keeps the name relative or absolute as it is."
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6843
19670
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  6844
    (nameString startsWith:$~) ifFalse:[
113d38592c9b #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 19665
diff changeset
  6845
        ^ nameString.
14220
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  6846
    ].
2a3457b016be Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents: 14218
diff changeset
  6847
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6848
    ^ self species nameWithSpecialExpansions:nameString.
24066
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6849
5869861d9c86 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 24060
diff changeset
  6850
    "Modified (comment): / 12-04-2019 / 11:50:45 / Stefan Vogel"
2922
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6851
! !
e9ae6bea98cd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2911
diff changeset
  6852
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6853
!Filename methodsFor:'suffixes'!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6854
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6855
addSuffix:aSuffix
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  6856
    "return a new filename for the receiver's name with a additional suffix.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6857
     The new suffix is simply appended to the name,
14306
f41ca29d9b54 comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 14232
diff changeset
  6858
     regardless whether there is already an existing suffix.
f41ca29d9b54 comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 14232
diff changeset
  6859
     See also #withSuffix:"
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6860
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6861
    aSuffix isEmptyOrNil ifTrue:[
24013
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  6862
        ^ self.
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6863
    ].
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6864
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  6865
    ^ self species named:
24013
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  6866
        (self name
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  6867
         , self species suffixSeparator asString
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  6868
         , aSuffix asString)
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6869
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6870
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6871
     'abc.st' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6872
     'a.b.c' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6873
     '.b.c.' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6874
     '.b.c' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6875
     '.c.' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6876
     '.c' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6877
     'c.' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6878
     '.' asFilename addSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6879
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6880
     'abc.st' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6881
     'abc' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6882
     'a.b.c' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6883
     'a.b.c.' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6884
     '.b.c.' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6885
     '.c.' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6886
     '.c' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6887
     'c.' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6888
     '.' asFilename addSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6889
     '/foo/bar/baz.st' asFilename addSuffix:'c'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6890
     '/foo/bar/baz.c' asFilename addSuffix:'st'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6891
     '/foo/bar.c/baz.c' asFilename addSuffix:'st'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6892
     '/foo/bar.c/baz' asFilename addSuffix:'st'
11748
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6893
    "
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6894
!
667e665eaafe new: #addSuffix:
Stefan Vogel <sv@exept.de>
parents: 11658
diff changeset
  6895
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6896
hasSuffix:aSuffixString
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6897
    "return true if my suffix is the same as aString.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6898
     This cares for systems, where case is ignored in filenames"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6899
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6900
    |mySuffix|
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6901
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6902
    mySuffix := self suffix.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  6903
    self species isCaseSensitive ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6904
        ^ mySuffix = aSuffixString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6905
    ].
24101
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
diff changeset
  6906
    ^ mySuffix sameAs:aSuffixString
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6907
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6908
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6909
     'abc.st' asFilename hasSuffix:'st'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6910
     'abc.ST' asFilename hasSuffix:'st'
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  6911
     '.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
  6912
     '.foorc' asFilename hasSuffix:'foorc'        -- false expected here
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6913
     '.foorc.sav' asFilename hasSuffix:'sav'
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6914
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6915
24101
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
diff changeset
  6916
    "Modified: / 07-09-1997 / 02:55:25 / cg"
0bbf8d6ed48a #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 24066
diff changeset
  6917
    "Modified: / 01-05-2019 / 11:22:37 / Claus Gittinger"
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6918
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  6919
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6920
nameWithoutSuffix
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  6921
    "return the receiver's name without the suffix.
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6922
     If the name has no suffix, the original name is returned."
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6923
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6924
    |nm idx idxFromEnd|
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6925
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6926
    nm := self baseName.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  6927
    idx := nm lastIndexOf:(self species suffixSeparator).
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6928
    (idx == 0) ifTrue:[^ nameString].
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6929
    "/ be careful: if the name consists only of suffix (i.e '.foo'),
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6930
    "/ the suffix is considered empty.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6931
    (idx == 1) ifTrue:[^ nameString].
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6932
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6933
    idxFromEnd := nm size - idx.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6934
    idx := nameString size - idxFromEnd.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6935
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6936
    ^ nameString copyTo:(idx - 1)
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6937
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6938
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6939
     'abc.st' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6940
     'abc' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6941
     '/abc' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6942
     '/abc.d' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6943
     './abc' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6944
     './abc.d' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6945
     './.abc' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6946
     'a.b.c' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6947
     'a.b.' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6948
     '.b.c' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6949
     '.b.' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6950
     '.b' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6951
     '/foo/bar/baz.c' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6952
     '/foo/bar.x/baz.c' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6953
     '/foo/bar.x/baz' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6954
     '/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6955
     '/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6956
    "
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6957
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6958
    "Modified: / 07-09-1995 / 11:15:42 / claus"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6959
    "Created: / 07-11-2006 / 13:55:18 / cg"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6960
!
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  6961
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6962
prefix
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6963
    "return my prefix.
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6964
     The suffix is the namepart after the final period character,
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6965
     or the empty string, if the name does not contain a period."
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6966
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6967
    ^ self prefixAndSuffix at:1
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6968
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6969
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6970
     'abc.st' asFilename prefix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6971
     'abc' asFilename prefix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6972
     'a.b.c' asFilename prefix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6973
     'a.b.c' asFilename prefix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6974
     'a.' asFilename prefix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6975
     '.a' asFilename prefix
9453
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6976
    "
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6977
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6978
    "Modified: / 07-09-1995 / 11:09:03 / claus"
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6979
    "Created: / 13-07-2006 / 10:27:19 / fm"
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6980
!
826ef60b7d02 +prefix
fm
parents: 9383
diff changeset
  6981
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6982
prefixAndSuffix
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6983
    "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
  6984
     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
  6985
     the prefix everything before, except for the period.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  6986
     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
  6987
     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
  6988
     (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
  6989
     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
  6990
     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
  6991
     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
  6992
     '.foorc'.
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  6993
     See also: #withoutSuffix and #withSuffix
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  6994
     Notice:
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6995
        there is currently no known system which uses other than
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  6996
        the period character as suffixCharacter."
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6997
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6998
    |nm idx|
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  6999
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7000
    nm := self baseName.
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  7001
    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
  7002
    "/ 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
  7003
    "/ the suffix is considered empty.
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  7004
    ((idx == 1) or:[ idx == 0 ]) ifTrue:[
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  7005
        ^ Array with:nm with:''
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7006
    ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7007
    ^ Array
24017
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  7008
        with:(nm copyTo:idx-1)
8da6aa16509d #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 24016
diff changeset
  7009
        with:(nm copyFrom:idx+1)
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7010
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7011
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7012
     'abc.st' asFilename prefixAndSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7013
     'abc' asFilename prefixAndSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7014
     'a.b.c' asFilename prefixAndSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7015
     '/foo/bar.c/baz.c' asFilename prefixAndSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7016
     'a.' asFilename prefixAndSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7017
     '.a' asFilename prefixAndSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7018
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7019
     |parts|
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7020
     parts := 'Object.st' asFilename prefixAndSuffix.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7021
     ((parts at:1) , '.o') asFilename
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7022
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7023
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7024
    "Modified: 7.9.1995 / 11:15:42 / claus"
1517
bf555091f8d4 commentary
Claus Gittinger <cg@exept.de>
parents: 1516
diff changeset
  7025
    "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
  7026
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7027
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7028
suffix
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7029
    "return my suffix.
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7030
     The suffix is the namepart after the final period character,
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7031
     or the empty string, if the name does not contain a period."
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7032
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7033
    ^ self prefixAndSuffix at:2
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7034
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7035
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7036
     'abc.st' asFilename suffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7037
     'abc' asFilename suffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7038
     'a.b.c' asFilename suffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7039
     'a.b.c' asFilename suffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7040
     'a.' asFilename suffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7041
     '.a' asFilename suffix
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7042
    "
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7043
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7044
    "Modified: 7.9.1995 / 11:09:03 / claus"
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7045
!
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7046
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7047
withSuffix:aSuffix
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  7048
    "return a new filename for the receiver's name with a different suffix.
6256
4ed471104283 URI support
Stefan Vogel <sv@exept.de>
parents: 6247
diff changeset
  7049
     If the name already has a suffix, the new suffix replaces it;
1993
a099e396ab6d commentary
Claus Gittinger <cg@exept.de>
parents: 1970
diff changeset
  7050
     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
  7051
7115
dea26def3167 prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents: 7088
diff changeset
  7052
    aSuffix isEmptyOrNil ifTrue:[
24013
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  7053
        ^ self.
6262
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  7054
    ].
46ef3c6b95dd allow withSuffix:nil
Claus Gittinger <cg@exept.de>
parents: 6256
diff changeset
  7055
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  7056
    ^ self species named:
24013
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  7057
        (self nameWithoutSuffix
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  7058
         , self class suffixSeparator asString
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  7059
         , aSuffix asString)
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7060
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7061
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7062
     'abc.st' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7063
     'a.b.c' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7064
     '.b.c.' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7065
     '.b.c' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7066
     '.c.' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7067
     '.c' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7068
     'c.' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7069
     '.' asFilename withSuffix:nil
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7070
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7071
     'abc.st' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7072
     'abc' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7073
     'a.b.c' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7074
     'a.b.c.' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7075
     '.b.c.' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7076
     '.c.' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7077
     '.c' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7078
     'c.' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7079
     '.' asFilename withSuffix:'o'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7080
     '/foo/bar/baz.st' asFilename withSuffix:'c'
24013
29c78a0786cd #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 24008
diff changeset
  7081
     '/foo/bar/baz.c' asFilename withSuffix:'.st'
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7082
     '/foo/bar.c/baz.c' asFilename withSuffix:'st'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7083
     '/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
  7084
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7085
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7086
    "Modified: / 07-09-1995 / 11:15:42 / claus"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7087
    "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
  7088
!
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7089
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7090
withoutSuffix
19440
10dcec541744 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19362
diff changeset
  7091
    "return a new filename for the receiver's name without the suffix.
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7092
     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
  7093
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7094
    |n|
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7095
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7096
    n := self nameWithoutSuffix.
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7097
    n = nameString ifTrue:[^ self].
15811
7d3cc7a1961f class: Filename
Stefan Vogel <sv@exept.de>
parents: 15737
diff changeset
  7098
    ^ self species named:n
1049
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7099
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7100
    "
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7101
     'abc.st' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7102
     'abc' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7103
     '/abc' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7104
     '/abc.d' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7105
     './abc' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7106
     './abc.d' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7107
     './.abc' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7108
     'a.b.c' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7109
     'a.b.' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7110
     '.b.c' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7111
     '.b.' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7112
     '.b' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7113
     '/foo/bar/baz.c' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7114
     '/foo/bar.x/baz.c' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7115
     '/foo/bar.x/baz' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7116
     '/foo/bar/baz/foo.c/bar' asFilename withoutSuffix
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7117
     '/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
  7118
    "
6f7b6c18a748 new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents: 932
diff changeset
  7119
10155
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7120
    "Modified: / 07-09-1995 / 11:15:42 / claus"
3cbef777449f +nameWithoutSuffix
Claus Gittinger <cg@exept.de>
parents: 10153
diff changeset
  7121
    "Modified: / 07-11-2006 / 13:57:45 / cg"
174
9e273c60e785 more functions
claus
parents: 159
diff changeset
  7122
! !
9e273c60e785 more functions
claus
parents: 159
diff changeset
  7123
5597
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7124
!Filename methodsFor:'testing'!
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7125
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7126
isFilename
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7127
    "return true, if the receiver is some kind of filename;
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7128
     false is returned here - the method is redefined from Object."
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7129
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7130
    ^true
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7131
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7132
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7133
! !
8a78f65b2df1 added isFilename query
Claus Gittinger <cg@exept.de>
parents: 5596
diff changeset
  7134
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7135
!Filename methodsFor:'writing-files'!
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7136
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7137
appendingFileDo:aBlock
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7138
    "create a append-stream on the receiver file, evaluate aBlock, passing that stream as arg,
19088
880729a47f59 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19043
diff changeset
  7139
     and return the block's value.
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7140
     If the file cannot be opened, an exception is raised.
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7141
     Ensures that the stream is closed."
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7142
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7143
    |stream|
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7144
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7145
    stream := self appendStream.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7146
    ^ [
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7147
        aBlock value:stream
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7148
    ] ensure:[
22448
7f0bc44b4082 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22403
diff changeset
  7149
        stream close
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7150
    ].
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7151
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7152
    "
14513
c0a090b81917 comment/format in: #appendingFileDo:
sr
parents: 14512
diff changeset
  7153
     'ttt' asFilename appendingFileDo:[:s |
22448
7f0bc44b4082 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22403
diff changeset
  7154
        s nextPutLine:'hello'.
7f0bc44b4082 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22403
diff changeset
  7155
        s nextPutLine:'world'.
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7156
     ]
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7157
    "
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7158
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7159
    "Created: / 09-11-2012 / 10:07:41 / sr"
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7160
    "Modified: / 06-02-2019 / 11:37:58 / Stefan Vogel"
14512
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7161
!
1e72c974298e added: #appendingFileDo:
sr
parents: 14446
diff changeset
  7162
23253
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7163
contents:aStringOrByteArrayOrCollectionOfLines
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7164
    "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
  7165
     Raises an error, if the file is unwritable."
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7166
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7167
    ^ self
23253
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7168
        writingFileDo:[:s |
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7169
            aStringOrByteArrayOrCollectionOfLines isNonByteCollection ifTrue:[
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7170
                "a StringCollection or a collection of lines"
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7171
                aStringOrByteArrayOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')]
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7172
            ] ifFalse:[
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7173
                "something string-like"
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7174
                aStringOrByteArrayOrCollectionOfLines isString ifFalse:[
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7175
                    s binary
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7176
                ].
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7177
                s nextPutAll:aStringOrByteArrayOrCollectionOfLines
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7178
            ]
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7179
        ].
18667
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7180
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7181
    "
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7182
     'foo1' asFilename contents:#('one' 'two' 'three')
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7183
     'foo2' asFilename contents:'Hello world'
ed22f49c33f1 temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents: 18659
diff changeset
  7184
     'foo3' asFilename contents:#[1 2 3 4 5]
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7185
    "
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7186
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7187
    "Created: / 11-12-2006 / 14:11:21 / cg"
10779
5e5c30426664 changed #contents:
Claus Gittinger <cg@exept.de>
parents: 10769
diff changeset
  7188
    "Modified: / 08-11-2007 / 13:28:41 / cg"
23253
a561f83a8287 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23159
diff changeset
  7189
    "Modified (format): / 01-08-2018 / 18:11:58 / Claus Gittinger"
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7190
!
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7191
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7192
writingFileDo:aBlock
23939
3ec50a9816fd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23911
diff changeset
  7193
    "create a write-stream on the receiver file, evaluate aBlock, 
3ec50a9816fd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23911
diff changeset
  7194
     passing that stream as arg,
19088
880729a47f59 #DOCUMENTATION
Claus Gittinger <cg@exept.de>
parents: 19043
diff changeset
  7195
     and return the block's value.
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7196
     If the file cannot be opened, an exception is raised.
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7197
     Ensures that the stream is closed."
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7198
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7199
    |stream|
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7200
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7201
    stream := self writeStream.
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7202
    ^ [
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7203
        aBlock value:stream
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7204
    ] ensure:[
22448
7f0bc44b4082 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22403
diff changeset
  7205
        stream close
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7206
    ].
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7207
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7208
    "
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7209
     'ttt' asFilename writingFileDo:[:s |
22448
7f0bc44b4082 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22403
diff changeset
  7210
        s nextPutLine:'hello'.
7f0bc44b4082 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 22403
diff changeset
  7211
        s nextPutLine:'world'.
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7212
     ]
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7213
    "
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7214
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7215
    "Created: / 11-12-2006 / 14:09:39 / cg"
23667
8fd82341af73 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 23664
diff changeset
  7216
    "Modified: / 06-02-2019 / 11:37:37 / Stefan Vogel"
23939
3ec50a9816fd #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 23911
diff changeset
  7217
    "Modified (comment): / 18-03-2019 / 11:29:44 / Claus Gittinger"
10271
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7218
! !
9d6d37936af9 file write utilities added
Claus Gittinger <cg@exept.de>
parents: 10155
diff changeset
  7219
1859
7f6040320daf changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents: 1614
diff changeset
  7220
!Filename class methodsFor:'documentation'!
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  7221
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  7222
version
18490
ec5c1c050681 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18272
diff changeset
  7223
    ^ '$Header$'
12318
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  7224
!
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  7225
4f6015c61baa changed: #renameTo:
Claus Gittinger <cg@exept.de>
parents: 11877
diff changeset
  7226
version_CVS
18490
ec5c1c050681 class: Filename
Claus Gittinger <cg@exept.de>
parents: 18272
diff changeset
  7227
    ^ '$Header$'
630
b785d23d7c5b version at the end
Claus Gittinger <cg@exept.de>
parents: 615
diff changeset
  7228
! !
6771
997fec197366 readingLinesDO:
penk
parents: 6753
diff changeset
  7229
14628
d6bf1fd719f6 class: Filename
Claus Gittinger <cg@exept.de>
parents: 14567
diff changeset
  7230
2906
4cb3c10499a7 VMS changes
Claus Gittinger <cg@exept.de>
parents: 2903
diff changeset
  7231
Filename initialize!