1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#Filename
|
68
|
14 |
instanceVariableNames:'nameString'
|
1
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'ST-80 compatibility'!
|
|
18 |
|
|
19 |
Filename comment:'
|
|
20 |
|
5
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
22 |
All Rights Reserved
|
|
23 |
|
2
|
24 |
Filenames; originally added for ST-80 compatibility, is
|
|
25 |
taking over functionality from other classes (FileDirectory).
|
1
|
26 |
|
68
|
27 |
$Header: /cvs/stx/stx/libbasic/Filename.st,v 1.7 1994-03-30 09:32:02 claus Exp $
|
1
|
28 |
'!
|
|
29 |
|
|
30 |
!Filename class methodsFor:'instance creation'!
|
|
31 |
|
2
|
32 |
currentDirectory
|
38
|
33 |
"return a filename for the current directory"
|
|
34 |
|
68
|
35 |
^ (self basicNew) setName:(FileDirectory currentDirectory pathName)
|
38
|
36 |
|
|
37 |
"Filename currentDirectory"
|
2
|
38 |
!
|
|
39 |
|
1
|
40 |
named:aString
|
38
|
41 |
"return a filename for a directory named aString"
|
|
42 |
|
68
|
43 |
^ (self basicNew) setName:aString
|
38
|
44 |
|
|
45 |
"Filename named:'/tmp/fooBar'"
|
1
|
46 |
! !
|
|
47 |
|
2
|
48 |
!Filename class methodsFor:'queries'!
|
|
49 |
|
|
50 |
separator
|
|
51 |
"return the file/directory separator."
|
|
52 |
|
|
53 |
^ OperatingSystem fileSeparator
|
38
|
54 |
|
|
55 |
"Filename separator"
|
2
|
56 |
! !
|
|
57 |
|
|
58 |
!Filename methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
construct:subname
|
38
|
61 |
"taking the receiver as a directory name, construct a new
|
|
62 |
filename for an entry within this directory (i.e. for a file
|
|
63 |
or a subdirectory in that directory)."
|
|
64 |
|
68
|
65 |
^ (self class basicNew) setName:(nameString , self class separator asString , subname)
|
38
|
66 |
|
|
67 |
"('/tmp' asFilename construct:'foo') asString"
|
2
|
68 |
! !
|
|
69 |
|
1
|
70 |
!Filename methodsFor:'converting'!
|
|
71 |
|
|
72 |
asString
|
38
|
73 |
"return the receiver converted to a string"
|
|
74 |
|
68
|
75 |
^ nameString
|
1
|
76 |
!
|
|
77 |
|
|
78 |
asFilename
|
68
|
79 |
"return the receiver converted to a filename."
|
38
|
80 |
|
68
|
81 |
"Thats pretty easy here :-)"
|
1
|
82 |
^ self
|
|
83 |
! !
|
|
84 |
|
68
|
85 |
!Filename privateMethodsFor:'private accessing'!
|
1
|
86 |
|
68
|
87 |
setName:aString
|
38
|
88 |
"set the filename"
|
|
89 |
|
68
|
90 |
nameString := aString
|
1
|
91 |
! !
|
|
92 |
|
2
|
93 |
!Filename methodsFor:'queries'!
|
|
94 |
|
|
95 |
directoryName
|
|
96 |
"return the directoryName of the argument, aPath
|
|
97 |
- thats the name of the directory where aPath is"
|
|
98 |
|
68
|
99 |
^ OperatingSystem directoryNameOf:nameString
|
|
100 |
|
|
101 |
"/foo/bar' asFilename directoryName"
|
2
|
102 |
!
|
|
103 |
|
|
104 |
baseName
|
|
105 |
"return my baseName
|
|
106 |
- thats the file/directory name without leading parent-dirs"
|
|
107 |
|
68
|
108 |
^ OperatingSystem baseNameOf:nameString
|
|
109 |
|
|
110 |
"/foo/bar' asFilename baseName"
|
|
111 |
!
|
|
112 |
|
|
113 |
isAbsolute
|
|
114 |
"return true, if the receiver represents an absolute pathname
|
|
115 |
(in contrast to one relative to the current directory)"
|
|
116 |
|
|
117 |
^ (nameString startsWith:self separator)
|
|
118 |
|
|
119 |
"/foo/bar' asFilename isAbsolute"
|
|
120 |
"'..' asFilename isAbsolute"
|
|
121 |
"'source/SBrowser.st' asFilename isAbsolute"
|
|
122 |
!
|
|
123 |
|
|
124 |
exists
|
|
125 |
"return true, if such a file exists"
|
|
126 |
|
|
127 |
^ OperatingSystem isValidPath:nameString
|
|
128 |
|
|
129 |
"'/foo/bar' asFilename exists"
|
|
130 |
"'/tmp' asFilename exists"
|
2
|
131 |
! !
|
|
132 |
|
1
|
133 |
!Filename methodsFor:'file access'!
|
|
134 |
|
2
|
135 |
renameTo:newName
|
|
136 |
"rename the file - the argument must be convertable to a String"
|
|
137 |
|
68
|
138 |
^ OperatingSystem renameFile:nameString to:(newName asString)
|
2
|
139 |
|
|
140 |
"'/tmp/foo asFileName renameTo:'/tmp/bar'"
|
|
141 |
!
|
|
142 |
|
68
|
143 |
copyTo:newName
|
|
144 |
"copy the file - the argument must be convertable to a String"
|
1
|
145 |
|
68
|
146 |
^ OperatingSystem copyFile:nameString to:(newName asString)
|
1
|
147 |
!
|
|
148 |
|
|
149 |
fileIn
|
2
|
150 |
"load smalltalk code from the file"
|
|
151 |
|
|
152 |
^ self readStream fileIn
|
1
|
153 |
!
|
|
154 |
|
|
155 |
readStream
|
2
|
156 |
"return a stream for reading"
|
|
157 |
|
68
|
158 |
^ FileStream readonlyFileNamed:nameString
|
1
|
159 |
!
|
|
160 |
|
|
161 |
writeStream
|
2
|
162 |
"return a stream for writing"
|
|
163 |
|
68
|
164 |
^ FileStream newFileNamed:nameString
|
1
|
165 |
! !
|