author | Claus Gittinger <cg@exept.de> |
Fri, 13 Dec 2019 15:12:31 +0100 | |
changeset 25111 | 457334bdb9eb |
parent 25075 | 5f8d55a5a56f |
child 25201 | 77076599ba0c |
permissions | -rw-r--r-- |
25075 | 1 |
"{ Encoding: utf8 }" |
2 |
||
3336 | 3 |
" |
4 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3570 | 5 |
All Rights Reserved |
3336 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5826 | 14 |
"{ Package: 'stx:libbasic' }" |
15 |
||
20247 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
3336 | 18 |
Filename subclass:#PCFilename |
19 |
instanceVariableNames:'' |
|
20001 | 20 |
classVariableNames:'StandardSuffixTable NextTempFilenameIndex' |
3336 | 21 |
poolDictionaries:'' |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
22 |
category:'OS-Windows' |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
23 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
24 |
|
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
25 |
!PCFilename class methodsFor:'documentation'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
26 |
|
3336 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3570 | 30 |
All Rights Reserved |
3336 | 31 |
|
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
39 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
40 |
|
3336 | 41 |
documentation |
42 |
" |
|
43 |
Filenames in Windows-NT / Win95. |
|
44 |
" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
45 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
46 |
|
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
47 |
!PCFilename class methodsFor:'initialization'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
48 |
|
3336 | 49 |
initStandardSuffixTable |
50 |
"since there is no 'file' command to extract the type, |
|
51 |
return a guess based upon the files suffix. The following |
|
52 |
table defines what is returned." |
|
53 |
||
54 |
StandardSuffixTable := Dictionary new. |
|
16562 | 55 |
#( |
3570 | 56 |
'COM' 'executable' |
57 |
'DIR' 'directory' |
|
58 |
'EXE' 'executable' |
|
59 |
'LST' 'listing' |
|
60 |
'OBJ' 'object file' |
|
61 |
'TMP' 'temporary' |
|
62 |
'BAS' 'basic source' |
|
63 |
'C' 'c source' |
|
64 |
'COB' 'cobol source' |
|
65 |
'FOR' 'fortran source' |
|
66 |
'PAS' 'pascal source' |
|
67 |
'PL1' 'PL/1 source' |
|
68 |
'ST' 'smalltalk source' |
|
69 |
'STH' 'stc generated header' |
|
70 |
'DLL' 'dynamic link library' |
|
3336 | 71 |
) pairWiseDo:[:k :v | |
3570 | 72 |
StandardSuffixTable at:k put:v |
3336 | 73 |
] |
74 |
||
75 |
" |
|
76 |
StandardSuffixTable := nil. |
|
77 |
self initStandardSuffixTable |
|
78 |
" |
|
79 |
||
80 |
"Modified: 16.10.1997 / 13:12:39 / cg" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
81 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
82 |
|
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
83 |
!PCFilename class methodsFor:'instance creation'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
84 |
|
3336 | 85 |
newTemporaryIn:aDirectoryPrefix |
86 |
"return a new unique filename - use this for temporary files. |
|
87 |
redefined to always return an MSDOS 8+3 fileName, |
|
88 |
in case the tempFile is passed to an OLD dos utility.." |
|
89 |
||
90 |
|pid nr nameString| |
|
91 |
||
92 |
NextTempFilenameIndex isNil ifTrue:[ |
|
16562 | 93 |
NextTempFilenameIndex := 1. |
3336 | 94 |
]. |
95 |
||
96 |
pid := OperatingSystem getProcessId printString. |
|
97 |
pid := pid copyLast:(3 min:pid size). |
|
98 |
nr := NextTempFilenameIndex printString. |
|
99 |
nr := nr copyLast:(3 min:nr size). |
|
13321
3721cb08c3b0
comment/format in: #newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
13158
diff
changeset
|
100 |
nameString := (self tempFileNameTemplate) bindWith:pid with:nr. |
3336 | 101 |
NextTempFilenameIndex := NextTempFilenameIndex + 1. |
102 |
||
103 |
(aDirectoryPrefix isNil or:[aDirectoryPrefix asString isEmpty]) ifFalse:[ |
|
16562 | 104 |
^ aDirectoryPrefix asFilename construct:nameString |
3336 | 105 |
]. |
106 |
^ self named:nameString |
|
107 |
||
108 |
"temp files in '/tmp': |
|
109 |
||
16562 | 110 |
Filename newTemporary |
3336 | 111 |
" |
112 |
||
16562 | 113 |
"temp files somewhere |
3336 | 114 |
(not recommended - use above since it can be controlled via shell variables): |
115 |
||
16562 | 116 |
Filename newTemporaryIn:'/tmp' |
117 |
Filename newTemporaryIn:'/tmp' |
|
118 |
Filename newTemporaryIn:'/usr/tmp' |
|
119 |
Filename newTemporaryIn:'/' |
|
3336 | 120 |
" |
121 |
||
122 |
"a local temp file: |
|
123 |
||
16562 | 124 |
Filename newTemporaryIn:'' |
125 |
Filename newTemporaryIn:nil |
|
126 |
Filename newTemporaryIn:'.' |
|
127 |
Filename newTemporaryIn:('source' asFilename) |
|
3336 | 128 |
" |
129 |
||
13321
3721cb08c3b0
comment/format in: #newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
13158
diff
changeset
|
130 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
3721cb08c3b0
comment/format in: #newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
13158
diff
changeset
|
131 |
"Created: / 30-01-1998 / 11:49:33 / md" |
3721cb08c3b0
comment/format in: #newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
13158
diff
changeset
|
132 |
"Modified: / 30-01-1998 / 12:09:18 / dq" |
3721cb08c3b0
comment/format in: #newTemporaryIn:
Claus Gittinger <cg@exept.de>
parents:
13158
diff
changeset
|
133 |
"Modified: / 23-03-2011 / 16:29:34 / cg" |
3848 | 134 |
! |
135 |
||
20693 | 136 |
rootComponents:aCollectionOfDirectoryNames |
137 |
|rootDirOrVolume| |
|
138 |
||
139 |
aCollectionOfDirectoryNames notEmpty ifTrue:[ |
|
140 |
rootDirOrVolume := aCollectionOfDirectoryNames first. |
|
141 |
(rootDirOrVolume endsWith:$:) ifTrue:[ |
|
142 |
"do not add a leading \ to C:" |
|
143 |
^ self fromComponents:aCollectionOfDirectoryNames. |
|
144 |
]. |
|
145 |
]. |
|
146 |
^ super rootComponents:aCollectionOfDirectoryNames. |
|
147 |
! |
|
148 |
||
3848 | 149 |
rootDirectoryOnVolume:aVolumeName |
150 |
"return a filename for the root directory on some volume" |
|
151 |
||
3853 | 152 |
^ self named:(aVolumeName , '\') |
3848 | 153 |
|
154 |
" |
|
3853 | 155 |
Filename rootDirectoryOnVolume:'d:' |
156 |
Filename rootDirectoryOnVolume:'\\idefix\home' |
|
3848 | 157 |
" |
158 |
||
3853 | 159 |
"Modified: / 24.9.1998 / 19:06:15 / cg" |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
160 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
161 |
|
7837 | 162 |
!PCFilename class methodsFor:'defaults'! |
163 |
||
164 |
defaultTempDirectoryName |
|
165 |
"return the default temp directory as a filename. |
|
166 |
This is used, if no special preferences were defined in |
|
167 |
any of the TEMP-environment variables (see tempDirectory)." |
|
168 |
||
17046 | 169 |
|winDir vol tempDirString tempDir| |
170 |
||
171 |
"/ if no explicit temp dir environment variable has been specified, |
|
172 |
"/ use the ALLUSERS common folder and create an stx_tmp folder there. |
|
173 |
"/ this will only happen for services which are installed to run under system |
|
174 |
"/ instead of under any particular user. |
|
8661 | 175 |
|
17046 | 176 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP' 'ALLUSERSPROFILE') do:[:envVar | |
19599 | 177 |
tempDirString := OperatingSystem getEnvironment:envVar. |
178 |
tempDirString notNil ifTrue:[ |
|
179 |
"/ kludge when running cygwin: replace '/cygdrive/X/...' |
|
180 |
"/ by X:\... |
|
181 |
(tempDirString startsWith:'/cygdrive/') ifTrue:[ |
|
182 |
tempDirString := tempDirString withoutPrefix:'/cygdrive/'. |
|
183 |
tempDirString size > 2 ifTrue:[ |
|
184 |
(tempDirString at:2) == $/ ifTrue:[ |
|
185 |
tempDirString := (tempDirString at:1) asString , ':' , |
|
186 |
((tempDirString copyFrom:2) replaceAll:$/ with:$\). |
|
187 |
]. |
|
188 |
]. |
|
189 |
]. |
|
190 |
tempDir := self named:tempDirString. |
|
191 |
(tempDir exists and:[ tempDir isWritable ]) ifTrue:[ |
|
192 |
('Filename [info]: using tmp folder "%1" as specified by environment: "%2"' |
|
193 |
bindWith:tempDir pathName with:envVar) infoPrintCR. |
|
194 |
^ tempDir asFilename. |
|
195 |
]. |
|
196 |
]. |
|
8661 | 197 |
]. |
198 |
||
10851
7d9c2ac9a7c9
dont return sometimes a String, sometimes a Filename from defaultTempDirectoryName
Claus Gittinger <cg@exept.de>
parents:
10624
diff
changeset
|
199 |
winDir := OperatingSystem getWindowsDirectory asFilename. |
7d9c2ac9a7c9
dont return sometimes a String, sometimes a Filename from defaultTempDirectoryName
Claus Gittinger <cg@exept.de>
parents:
10624
diff
changeset
|
200 |
vol := winDir volume. |
16562 | 201 |
tempDir := vol asFilename construct:'temp'. |
19599 | 202 |
(tempDir exists and:[ tempDir isWritable ]) ifFalse:[ |
203 |
tempDir := vol asFilename construct:'tmp'. |
|
204 |
(tempDir exists and:[ tempDir isWritable ]) ifFalse:[ |
|
205 |
tempDir := winDir construct:'temp'. |
|
206 |
(tempDir exists and:[ tempDir isWritable ]) ifFalse:[ |
|
207 |
tempDir := '.\temp' asFilename |
|
208 |
] |
|
209 |
] |
|
17046 | 210 |
]. |
211 |
('Filename [info]: using fallback windows tmp folder: ',tempDir pathName) infoPrintCR. |
|
19599 | 212 |
^ tempDir |
7837 | 213 |
|
214 |
" |
|
16562 | 215 |
Filename defaultTempDirectoryName |
216 |
Filename defaultTempDirectoryName exists |
|
217 |
Filename defaultTempDirectoryName isWritable |
|
7837 | 218 |
" |
19599 | 219 |
! |
220 |
||
221 |
defaultVolumeName |
|
222 |
"return the default volume name." |
|
223 |
||
224 |
^ 'c:' |
|
7837 | 225 |
! ! |
226 |
||
20247 | 227 |
!PCFilename class methodsFor:'misc'! |
228 |
||
23631 | 229 |
isRootDirectoryName:nm |
230 |
"return true, if aString represents a root directory; |
|
231 |
i.e. is of the form: |
|
232 |
\ |
|
233 |
X: |
|
234 |
X:\ |
|
235 |
or: |
|
236 |
\\hostname\ |
|
237 |
\\hostname\topDir |
|
238 |
" |
|
239 |
||
240 |
|sz i| |
|
241 |
||
242 |
sz := nm size. |
|
243 |
sz == 0 ifTrue:[ |
|
244 |
^ false. |
|
245 |
]. |
|
246 |
sz == 1 ifTrue:[ |
|
247 |
^ nm = '\' "/ \ alone |
|
248 |
]. |
|
249 |
||
250 |
(sz == 2 or:[sz == 3]) ifTrue:[ |
|
251 |
^ (nm at:2) == $: |
|
252 |
and:[sz == 2 "/ <DRIVE-char>: |
|
253 |
or:[(nm at:3) == $\]. "/ <DRIVE-char>:\ |
|
254 |
]. |
|
255 |
]. |
|
256 |
||
257 |
"/ sz > 3 - check for \\<REMOTE-HOST> |
|
258 |
((nm at:1) == $\ |
|
259 |
and:[(nm at:2) == $\]) ifTrue:[ |
|
260 |
"/ something like \\hostname |
|
261 |
i := nm indexOf:$\ startingAt:4. |
|
262 |
((i == 0) or:[i == sz]) ifTrue:[ |
|
263 |
"/ \\hostname (without \dirname) - not really a root (its not readable) |
|
264 |
^ true |
|
265 |
]. |
|
266 |
i ~~ 0 ifTrue:[ |
|
267 |
"/ something like \\hostname\dirName or \\hostname\dirName\ |
|
268 |
i := nm indexOf:$\ startingAt:i+1. |
|
269 |
^ (i == 0) or:[i == sz]. "/ yeah - really a root |
|
270 |
] |
|
271 |
]. |
|
272 |
^ false |
|
273 |
||
274 |
"Modified: / 22-01-2019 / 15:41:37 / Stefan Vogel" |
|
275 |
! |
|
276 |
||
20247 | 277 |
nameWithSpecialExpansions:aString |
278 |
"return the nameString, expanding any OS specific macros. |
|
279 |
Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)" |
|
280 |
||
281 |
|expandedString| |
|
282 |
||
283 |
expandedString := aString. |
|
284 |
(expandedString includes:$%) ifTrue:[ |
|
285 |
expandedString := OperatingSystem expandEnvironmentStrings:expandedString. |
|
286 |
]. |
|
287 |
||
288 |
(expandedString startsWith:$~) ifTrue:[ |
|
289 |
^ super nameWithSpecialExpansions:expandedString. |
|
290 |
]. |
|
291 |
^ expandedString |
|
292 |
||
293 |
" |
|
25075 | 294 |
self nameWithSpecialExpansions:'c:/windows' |
295 |
self nameWithSpecialExpansions:'%ProgramFiles%\exept\expecco' |
|
296 |
self nameWithSpecialExpansions:'~\exept\expecco' |
|
297 |
self nameWithSpecialExpansions:'~stefan\exept\expecco' |
|
298 |
self nameWithSpecialExpansions:'~\work' |
|
299 |
self nameWithSpecialExpansions:'%HOMEDRIVE%%HOMEPATH%\work' |
|
20247 | 300 |
" |
301 |
! ! |
|
302 |
||
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
303 |
!PCFilename class methodsFor:'queries'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
304 |
|
3336 | 305 |
isBadCharacter:aCharacter |
306 |
"return true, if aCharacter is unallowed in a filename." |
|
307 |
||
22125 | 308 |
^ ('<>:"/\|?*' includes:aCharacter) or:[super isBadCharacter:aCharacter] |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
309 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
310 |
|
3336 | 311 |
isCaseSensitive |
312 |
"return true, if filenames are case sensitive." |
|
313 |
||
314 |
^ false |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
315 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
316 |
|
8753 | 317 |
nullFilename |
318 |
"Return the OS dependent filename for the data sink, or nil if there is none" |
|
319 |
||
320 |
^ 'nul:' |
|
321 |
! |
|
322 |
||
323 |
parentDirectoryName |
|
324 |
"return the name used for the parent directory. |
|
325 |
This is '..' for unix and dos-like systems. |
|
326 |
(there may be more in the future." |
|
327 |
||
328 |
^ '..' |
|
329 |
! |
|
330 |
||
3336 | 331 |
separator |
332 |
"return the file/directory separator." |
|
333 |
||
334 |
^ $\ |
|
335 |
||
336 |
" |
|
16562 | 337 |
Filename concreteClass separator |
3336 | 338 |
" |
339 |
||
340 |
"Modified: 8.9.1997 / 00:18:03 / cg" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
341 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
342 |
|
3336 | 343 |
tempFileNameTemplate |
344 |
"return a template for temporary files. |
|
345 |
This is expanded with the current processID and a sequenceNumber |
|
346 |
to generate a unique filename. |
|
347 |
Redefined for MSDOS 8+3 filenames" |
|
348 |
||
3749 | 349 |
^ 'st%1%2' |
3336 | 350 |
|
351 |
"Created: 30.1.1998 / 12:09:18 / dq" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
352 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
353 |
|
10624 | 354 |
!PCFilename methodsFor:'attribute setter'! |
355 |
||
23720 | 356 |
clearHidden |
357 |
"set the hidden attribute to false (unhidden). |
|
358 |
Return true on success." |
|
10624 | 359 |
|
23720 | 360 |
^ OperatingSystem clearHidden:(self osNameForFile) |
361 |
||
362 |
"Created: / 12-02-2019 / 12:30:31 / Stefan Vogel" |
|
10624 | 363 |
! |
364 |
||
23720 | 365 |
setHidden |
366 |
"return true, if the hidden attribute could be set to true" |
|
10624 | 367 |
|
23720 | 368 |
^ OperatingSystem setHidden:(self osNameForFile) |
10624 | 369 |
|
23720 | 370 |
"Modified (comment): / 12-02-2019 / 12:37:39 / Stefan Vogel" |
10624 | 371 |
! ! |
10623 | 372 |
|
3789 | 373 |
!PCFilename methodsFor:'converting'! |
374 |
||
9208 | 375 |
makeDOSName |
376 |
"convert the receivers name to be a DOS filename." |
|
377 |
||
378 |
nameString := self fullAlternativePathName. |
|
379 |
||
380 |
" |
|
381 |
'C:\Dokumente und Einstellungen\str\Desktop\output folder\' asFilename makeDOSName |
|
382 |
" |
|
383 |
! |
|
384 |
||
16562 | 385 |
makeLegalFilename |
3789 | 386 |
"convert the receivers name to be a legal filename. |
387 |
This removes/replaces invalid characters and/or compresses |
|
388 |
the name as required by Win95-WinNT." |
|
389 |
||
22125 | 390 |
|srchStart separator| |
3789 | 391 |
|
392 |
"/ there may be only one colon in the name |
|
393 |
"/ (and if present, it must be the second character) |
|
394 |
||
395 |
((nameString size >= 2) |
|
396 |
and:[(nameString at:2) == $:]) ifTrue:[ |
|
22125 | 397 |
srchStart := 3. |
3789 | 398 |
] ifFalse:[ |
22125 | 399 |
srchStart := 1 |
3789 | 400 |
]. |
401 |
||
402 |
"/ replace colons by underscore |
|
403 |
"/ may need more to convert - time will show |
|
404 |
||
22125 | 405 |
separator := self separator. |
406 |
nameString := nameString copy |
|
407 |
replaceAllForWhich:[:each| each ~= separator |
|
408 |
and:[self class isBadCharacter:each]] |
|
409 |
with:$_ from:srchStart to:(nameString size). |
|
410 |
||
3789 | 411 |
|
412 |
" |
|
16562 | 413 |
'hello world' asFilename makeLegalFilename |
22125 | 414 |
'hello<>world' asFilename makeLegalFilename |
16562 | 415 |
'hello:world' asFilename makeLegalFilename |
416 |
'hello::world' asFilename makeLegalFilename |
|
417 |
'c:hello::world' asFilename makeLegalFilename |
|
418 |
'\\idefix' asFilename makeLegalFilename |
|
419 |
'\\idefix\' asFilename makeLegalFilename |
|
3789 | 420 |
" |
421 |
||
13158
75976f0d731a
changed: #makeLegalFilename
Claus Gittinger <cg@exept.de>
parents:
13104
diff
changeset
|
422 |
"Modified: / 01-12-2010 / 18:53:59 / cg" |
7062 | 423 |
! |
424 |
||
425 |
makeNonDOSName |
|
426 |
"convert the receivers name to be a full filename, in case its an abbreviated (alternative) DOS name. |
|
427 |
This removes/replaces components of the form FOOBAR~n by the real, full components name." |
|
428 |
||
8548 | 429 |
|directory directoryName baseName info| |
7062 | 430 |
|
431 |
(nameString includes:$~) ifFalse:[^self]. |
|
8948 | 432 |
(nameString startsWith:$~) ifTrue:[^self]. |
7062 | 433 |
|
8548 | 434 |
directoryName := self directoryName. |
435 |
directoryName = nameString ifTrue:[^self]. |
|
436 |
||
7062 | 437 |
baseName := self baseName. |
8548 | 438 |
|
7062 | 439 |
(baseName includes:$~) ifTrue:[ |
16562 | 440 |
info := self info. |
441 |
info notNil ifTrue:[ |
|
442 |
baseName := info fullName. |
|
443 |
]. |
|
444 |
directory := self class named:directoryName. |
|
445 |
directory isRootDirectory ifFalse:[ |
|
446 |
directory makeNonDOSName. |
|
447 |
]. |
|
448 |
nameString := directory constructString:baseName |
|
7062 | 449 |
]. |
450 |
||
451 |
" |
|
16562 | 452 |
Filename tempDirectory makeNonDOSName |
7062 | 453 |
" |
454 |
||
455 |
"Modified: / 11.10.1998 / 01:40:47 / cg" |
|
3789 | 456 |
! ! |
457 |
||
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
458 |
!PCFilename methodsFor:'file operations'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
459 |
|
3570 | 460 |
renameTo:newName |
461 |
"rename the file - the argument must be convertable to a String. |
|
462 |
Raise an error if not successful. |
|
15822 | 463 |
Redefined to delete any existing target-file first. |
464 |
Also take care of possible locks by antivirus scanners, that go away after some time." |
|
465 |
||
22391 | 466 |
|retryCtr| |
21121 | 467 |
|
468 |
"try 5 times (retry 4 times) if file has just been written to and is locked by a virus scanner" |
|
469 |
retryCtr := 4. |
|
470 |
[ |
|
471 |
^ super renameTo:newName |
|
472 |
] on:OSErrorHolder existingReferentSignal do:[:ex| |
|
473 |
|newFilename| |
|
474 |
||
475 |
newFilename := newName asFilename. |
|
476 |
(self pathName sameAs:newFilename pathName) ifTrue:[ |
|
477 |
ex reject. |
|
21060 | 478 |
]. |
21121 | 479 |
newFilename remove. |
480 |
ex restart. |
|
481 |
] on:OSErrorHolder noPermissionsSignal do:[:ex| |
|
21060 | 482 |
retryCtr > 0 ifTrue:[ |
483 |
Logger warning:'Error caught while renaming %1 to %2 - maybe temporary locked by virus scanner, still trying: %3' |
|
484 |
with:self pathName |
|
22391 | 485 |
with:newName |
21060 | 486 |
with:ex description. |
21121 | 487 |
retryCtr := retryCtr - 1. |
488 |
Delay waitForMilliseconds:200. |
|
489 |
ex restart. |
|
21060 | 490 |
] ifFalse:[ |
491 |
ex reject |
|
492 |
]. |
|
15822 | 493 |
]. |
3336 | 494 |
|
3570 | 495 |
" |
21121 | 496 |
'c:\users\stefan\test.txt' asFilename renameTo:'c:\users\stefan\test1.txt' |
497 |
'c:\users\stefan\test12.txt' asFilename renameTo:'c:\users\stefan\test.txt' |
|
3570 | 498 |
" |
499 |
||
10004
949fa299db1f
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
9921
diff
changeset
|
500 |
"Modified: / 20-01-1998 / 15:33:00 / md" |
949fa299db1f
care for same-name rename on OS which is not filename-case-sensitive
Claus Gittinger <cg@exept.de>
parents:
9921
diff
changeset
|
501 |
"Modified: / 21-09-2006 / 18:19:47 / cg" |
22391 | 502 |
"Modified (format): / 12-12-2017 / 12:45:47 / stefan" |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
503 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
504 |
|
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
505 |
!PCFilename methodsFor:'queries'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
506 |
|
4374
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
507 |
directoryName |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
508 |
"return the directory name part of the file/directory as a string. |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
509 |
- thats the name of the directory where the file/dir represented by |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
510 |
the receiver is contained in. |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
511 |
This method does not check if the path is valid. |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
512 |
|
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
513 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
514 |
and '/usr/lib' asFilename directoryName -> /usr'). |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
515 |
|
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
516 |
(this is almost equivalent to #directory, but returns |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
517 |
a string instead of a Filename instance). |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
518 |
|
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
519 |
See also: #pathName, #directoryPathName and #baseName. |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
520 |
Compatibility note: use #head for ST-80 compatibility." |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
521 |
|
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
522 |
|nm| |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
523 |
|
13104 | 524 |
(nameString endsWith:':\') ifTrue:[ |
16562 | 525 |
^ nameString |
13104 | 526 |
]. |
527 |
||
4374
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
528 |
nm := super directoryName. |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
529 |
(nm size == 2 and:[(nm at:2) == $:]) ifTrue:[ |
16562 | 530 |
^ nm , '\' |
4374
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
531 |
]. |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
532 |
^ nm |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
533 |
|
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
534 |
" |
16562 | 535 |
(PCFilename named:'c:\') directoryName |
536 |
(PCFilename named:'c:\users') directoryName |
|
537 |
(PCFilename named:'c:\users') directory pathName |
|
538 |
(PCFilename named:'c:\users') directory isRootDirectory |
|
4374
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
539 |
" |
13104 | 540 |
|
541 |
"Modified: / 26-10-2010 / 12:45:55 / cg" |
|
4374
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
542 |
! |
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
543 |
|
3336 | 544 |
fileType |
545 |
"this returns a string describing the type of contents of |
|
546 |
the file. Here, the suffix is examined for a standard |
|
547 |
suffix and an appropriate string is returned. |
|
548 |
Poor MSDOS - no file command." |
|
549 |
||
550 |
|suff type info fmt| |
|
551 |
||
552 |
StandardSuffixTable isNil ifTrue:[ |
|
3570 | 553 |
self class initStandardSuffixTable |
3336 | 554 |
]. |
555 |
||
556 |
suff := self suffix asUppercase. |
|
557 |
type := StandardSuffixTable at:suff ifAbsent:nil. |
|
558 |
type isNil ifTrue:[ |
|
3570 | 559 |
type := super fileType. |
3336 | 560 |
]. |
561 |
^ type |
|
562 |
||
563 |
"Created: 16.10.1997 / 13:07:24 / cg" |
|
564 |
"Modified: 16.10.1997 / 13:10:00 / cg" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
565 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
566 |
|
9423 | 567 |
freeBytesInVolume |
9921 | 568 |
^ (OperatingSystem getDiskInfoOf: self volume) at: #freeBytes |
9423 | 569 |
|
570 |
"Created: / 05-07-2006 / 15:02:38 / cg" |
|
571 |
! |
|
572 |
||
9207 | 573 |
fullAlternativePathName |
574 |
"return my complete MSDOS-path" |
|
16562 | 575 |
|
11805
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
576 |
|altNameComponent fullAlternativePath fullAlternativeDirectoryName info| |
9207 | 577 |
|
578 |
self isRootDirectory ifTrue:[ |
|
16562 | 579 |
^ nameString |
9207 | 580 |
]. |
11805
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
581 |
|
9207 | 582 |
(self name endsWith:$\) ifTrue:[ |
16562 | 583 |
^ (self class named:self pathName) fullAlternativePathName |
9207 | 584 |
]. |
11805
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
585 |
|
16562 | 586 |
info := self info. |
11805
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
587 |
info notNil ifTrue:[ |
16562 | 588 |
^ info alternativePathName. |
11805
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
589 |
]. |
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
590 |
|
9207 | 591 |
fullAlternativeDirectoryName := self directory fullAlternativePathName. |
592 |
(fullAlternativeDirectoryName endsWith:$\) ifTrue:[ |
|
16562 | 593 |
fullAlternativePath := fullAlternativeDirectoryName, self baseName. |
9207 | 594 |
] ifFalse:[ |
16562 | 595 |
fullAlternativePath := fullAlternativeDirectoryName , '\' , (altNameComponent ? self baseName). |
9207 | 596 |
]. |
597 |
^ fullAlternativePath |
|
598 |
||
599 |
" |
|
16562 | 600 |
'C:\Dokumente und Einstellungen\str\Desktop\output folder' asFilename fullAlternativePathName |
9208 | 601 |
'C:\Dokumente und Einstellungen\str\Desktop\output folder' asFilename fullAlternativePathName asFilename exists |
16562 | 602 |
'C:\' asFilename fullAlternativePathName |
11805
28b3ead51d73
Speed up #fullAlternativePathName
Stefan Vogel <sv@exept.de>
parents:
11421
diff
changeset
|
603 |
'C:\Dokumente und Einstellungen\str\Desktop\output folder\' asFilename fullAlternativePathName asFilename |
9207 | 604 |
" |
605 |
! |
|
606 |
||
11248 | 607 |
isCDRom |
608 |
"return true, if is is a drive" |
|
609 |
|pathName| |
|
610 |
||
12775 | 611 |
self isRootDirectory ifFalse:[^ false]. |
11248 | 612 |
|
613 |
pathName := self asString asLowercase. |
|
16792 | 614 |
^ (OperatingSystem getDriveType:pathName) == 5 |
11248 | 615 |
|
16792 | 616 |
" |
19599 | 617 |
'd:' asFilename isCDRom |
16792 | 618 |
" |
11248 | 619 |
! |
620 |
||
3850
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
621 |
isDirectory |
16562 | 622 |
"return true, if I represent a directory |
3850
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
623 |
Redefined to care for volumeRoots." |
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
624 |
|
23631 | 625 |
^ self isRootDirectory or:[super isDirectory]. |
3850
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
626 |
|
23631 | 627 |
"Created: / 24-09-1998 / 14:04:31 / cg" |
628 |
"Modified: / 22-01-2019 / 14:55:19 / Stefan Vogel" |
|
3850
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
629 |
! |
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
630 |
|
11248 | 631 |
isDrive |
16792 | 632 |
"return true, if is is a drive, |
633 |
that is either a fixed, removable, ramdisk or cdrom" |
|
634 |
||
11248 | 635 |
|pathName| |
636 |
||
12775 | 637 |
self isRootDirectory ifFalse:[^ false]. |
11248 | 638 |
|
639 |
pathName := self asString asLowercase. |
|
640 |
||
16792 | 641 |
"/ ((pathName = 'a:\') or:[pathName = 'b:\']) ifTrue:[^ false]. |
19599 | 642 |
^ #(2 3 5 6) includes:(OperatingSystem getDriveType:pathName) |
11248 | 643 |
|
16792 | 644 |
" |
19599 | 645 |
'z:' asFilename isDrive |
646 |
'c:' asFilename isDrive |
|
647 |
'd:' asFilename isDrive |
|
648 |
'a:\' asFilename isDrive |
|
649 |
'b:\' asFilename isDrive |
|
16792 | 650 |
" |
11248 | 651 |
! |
652 |
||
3336 | 653 |
isExecutableProgram |
654 |
"return true, if such a file exists and is an executable program. |
|
655 |
(i.e. for directories, false is returned.)" |
|
656 |
||
20558 | 657 |
|osName| |
3815 | 658 |
|
20558 | 659 |
osName := self osNameForAccess. |
660 |
||
22718 | 661 |
((OperatingSystem isValidPath:osName) |
662 |
and:[(OperatingSystem isDirectory:osName) not]) ifTrue:[ |
|
663 |
(#('exe' 'com') includes:self suffix asLowercase) ifTrue:[ |
|
664 |
"take care: getBinaryType is very slow on network shares!!" |
|
665 |
^ (OperatingSystem getBinaryType:osName) notNil |
|
666 |
]. |
|
667 |
^ #('bat' 'cmd') includes:self suffix asLowercase. |
|
3336 | 668 |
]. |
669 |
^ false |
|
670 |
||
20558 | 671 |
" |
672 |
'%windir%\notepad.exe' asFilename isExecutableProgram |
|
673 |
'%windir%\notepad' asFilename isExecutableProgram |
|
674 |
'%windir%\system32\kernel32.dll' asFilename isExecutableProgram |
|
675 |
'bmake.bat' asFilename isExecutableProgram |
|
676 |
'c:\' asFilename isExecutableProgram |
|
677 |
OperatingSystem getBinaryType:'bmake.bat' |
|
678 |
OperatingSystem getBinaryType:'c:\' |
|
679 |
" |
|
680 |
||
681 |
||
13619 | 682 |
"Created: / 16-10-1997 / 13:19:10 / cg" |
683 |
"Modified: / 09-09-1998 / 20:17:52 / cg" |
|
684 |
"Modified: / 23-08-2011 / 21:24:57 / jv" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
685 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
686 |
|
3336 | 687 |
isExplicitRelative |
688 |
"return true, if this name is an explicit relative name |
|
689 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
690 |
||
691 |
(nameString startsWith:'.\') ifTrue:[ |
|
23631 | 692 |
^ true |
3336 | 693 |
]. |
23631 | 694 |
^ nameString startsWith:'..\'. |
695 |
||
696 |
"Modified: / 22-01-2019 / 15:47:19 / Stefan Vogel" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
697 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
698 |
|
10595 | 699 |
isHidden |
12389 | 700 |
"return true, if such a file is hidden. |
701 |
On MSDOS, a name starting with a period is considered hidden |
|
702 |
AND a file with a hidden attribute is so." |
|
10595 | 703 |
|
23720 | 704 |
"/ |baseName| |
705 |
"/ |
|
706 |
"/ baseName := self baseName. |
|
23604 | 707 |
"sr: no this is totally wrong, |
708 |
in windows files starting with . are not hidden by definition" |
|
709 |
"/ ((baseName startsWith:'.') and:[baseName ~= '..']) ifTrue:[^ true]. |
|
710 |
||
10595 | 711 |
^ OperatingSystem isHidden:(self osNameForFile) |
23604 | 712 |
|
713 |
"Modified: / 16-01-2019 / 11:43:46 / sr" |
|
23720 | 714 |
"Modified: / 12-02-2019 / 12:15:38 / Stefan Vogel" |
10595 | 715 |
! |
716 |
||
3844
fb51bffc0aa3
redefined isRootDirectory for drive-letters & net-drives
Claus Gittinger <cg@exept.de>
parents:
3815
diff
changeset
|
717 |
isRootDirectory |
16562 | 718 |
"return true, if I represent a root directory |
23631 | 719 |
(i.e. I have no parentDir). |
720 |
||
721 |
Note: this doesn't check if I am a real directory that exists, |
|
722 |
but instead checks if the name is that of a root directory, |
|
723 |
which may not exist or may not be reachable (if on a network share)." |
|
3844
fb51bffc0aa3
redefined isRootDirectory for drive-letters & net-drives
Claus Gittinger <cg@exept.de>
parents:
3815
diff
changeset
|
724 |
|
11415 | 725 |
|nm| |
3844
fb51bffc0aa3
redefined isRootDirectory for drive-letters & net-drives
Claus Gittinger <cg@exept.de>
parents:
3815
diff
changeset
|
726 |
|
23631 | 727 |
(self class isRootDirectoryName:nameString) ifTrue:[ |
728 |
^ true |
|
729 |
]. |
|
11421 | 730 |
|
23631 | 731 |
((nameString includesAny:'~%') or:[nameString includesString:'..']) ifTrue:[ |
732 |
nm := self pathName. "/ compress '..' components ... |
|
733 |
nm ~= nameString ifTrue:[ |
|
734 |
"... and try again" |
|
735 |
^ self class isRootDirectoryName:nm |
|
736 |
]. |
|
8785 | 737 |
]. |
11415 | 738 |
^ false |
11421 | 739 |
" |
23631 | 740 |
'\' asFilename isRootDirectory. |
741 |
'c:\' asFilename isRootDirectory. |
|
742 |
'\\exeptn\tmp\' asFilename isRootDirectory. |
|
743 |
'\\exeptn\tmp\abc\..' asFilename isRootDirectory. |
|
744 |
'%SystemDrive%' asFilename isRootDirectory. |
|
4374
0b2a18a8cf84
fixed directoryName and isAbsolute.
Claus Gittinger <cg@exept.de>
parents:
3873
diff
changeset
|
745 |
|
23631 | 746 |
'c:\abc' asFilename isRootDirectory. |
747 |
'..\..' asFilename isRootDirectory. |
|
748 |
'\dir' asFilename isRootDirectory. |
|
749 |
'' asFilename isRootDirectory. |
|
750 |
" |
|
3850
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
751 |
|
23631 | 752 |
"Modified (comment): / 22-01-2019 / 15:44:24 / Stefan Vogel" |
3844
fb51bffc0aa3
redefined isRootDirectory for drive-letters & net-drives
Claus Gittinger <cg@exept.de>
parents:
3815
diff
changeset
|
753 |
! |
fb51bffc0aa3
redefined isRootDirectory for drive-letters & net-drives
Claus Gittinger <cg@exept.de>
parents:
3815
diff
changeset
|
754 |
|
3336 | 755 |
isVolumeAbsolute |
756 |
"return true, if the receiver represents an absolute pathname |
|
757 |
on some disk volume." |
|
758 |
||
23507 | 759 |
|osName| |
760 |
||
761 |
osName := self osNameForAccess. |
|
762 |
||
3815 | 763 |
"/ <DRIVE-CHAR>: |
23507 | 764 |
osName size < 3 ifTrue:[ |
765 |
^ false. |
|
766 |
]. |
|
767 |
||
768 |
((osName at:2) == $: |
|
769 |
and:[(osName at:3) == $\]) ifTrue:[ |
|
770 |
"/ something like x:\foo |
|
771 |
^ true |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
772 |
]. |
3815 | 773 |
|
774 |
"/ \\REMOTE-HOST: |
|
23507 | 775 |
((osName at:1) == $\ |
776 |
and:[(osName at:2) == $\]) ifTrue:[ |
|
777 |
"/ something like \\hostname |
|
778 |
^ true |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
779 |
]. |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
780 |
^ false |
3336 | 781 |
|
23668 | 782 |
" |
783 |
'C:\bla' asFilename isVolumeAbsolute |
|
784 |
'\\exeptn\bbb' asFilename isVolumeAbsolute |
|
785 |
'\dir\file' asFilename isVolumeAbsolute |
|
786 |
'file' asFilename isVolumeAbsolute |
|
787 |
" |
|
788 |
||
23507 | 789 |
"Created: / 07-09-1997 / 23:54:20 / cg" |
790 |
"Modified: / 09-09-1998 / 20:38:54 / cg" |
|
791 |
"Modified: / 05-11-2018 / 11:12:59 / Stefan Vogel" |
|
23668 | 792 |
"Modified (comment): / 06-02-2019 / 09:30:22 / Stefan Vogel" |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
793 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
794 |
|
16562 | 795 |
localNameStringFrom:aString |
3336 | 796 |
"ST-80 compatibility. |
797 |
what does this do ? (used in FileNavigator-goody). |
|
798 |
GUESS: does it strip off the voulume-character and initial '\' ?" |
|
799 |
||
800 |
(aString at:2) == $: ifTrue:[ |
|
801 |
(aString at:3) == $\ ifTrue:[ |
|
802 |
^ aString copyFrom:4 |
|
803 |
]. |
|
804 |
^ aString copyFrom:3 |
|
16562 | 805 |
]. |
3336 | 806 |
(aString at:1) == $\ ifTrue:[ |
807 |
^ aString copyFrom:1 |
|
808 |
]. |
|
809 |
^ aString |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
810 |
! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
811 |
|
3853 | 812 |
localPathName |
813 |
"return the full pathname of the file represented by the receiver, |
|
814 |
but without any volume information. |
|
815 |
Only makes a difference on MSDOS & VMS systems." |
|
816 |
||
817 |
|vol vsz rest| |
|
818 |
||
819 |
vol := self volume. |
|
20693 | 820 |
(vsz := vol size) ~~ 0 ifTrue:[ |
821 |
rest := nameString copyFrom:vsz + 1. |
|
822 |
rest size == 0 ifTrue:[ |
|
823 |
^ '\' |
|
824 |
]. |
|
825 |
(rest startsWith:$\) ifFalse:[ |
|
826 |
^ '\' , rest |
|
827 |
]. |
|
828 |
^ rest |
|
3853 | 829 |
]. |
830 |
^ nameString |
|
831 |
||
832 |
" |
|
16562 | 833 |
'\foo' asFilename localPathName |
834 |
'\foo\' asFilename localPathName |
|
835 |
'\foo\bar' asFilename localPathName |
|
836 |
'\foo\bar\' asFilename localPathName |
|
837 |
'c:' asFilename localPathName |
|
838 |
'c:\' asFilename localPathName |
|
839 |
'c:\foo' asFilename localPathName |
|
840 |
'c:\foo\' asFilename localPathName |
|
841 |
'c:\foo\bar' asFilename localPathName |
|
842 |
'c:\foo\bar\' asFilename localPathName |
|
843 |
'\\idefix' asFilename localPathName |
|
844 |
'\\idefix\home' asFilename localPathName |
|
845 |
'\\idefix\home\foo' asFilename localPathName |
|
3853 | 846 |
" |
847 |
||
848 |
"Modified: / 24.9.1998 / 19:09:53 / cg" |
|
849 |
! |
|
850 |
||
8870
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
851 |
pathName |
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
852 |
|path| |
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
853 |
|
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
854 |
path := super pathName. |
23631 | 855 |
(path size > 1 and:[path endsWith:$\]) ifTrue:[ |
856 |
(path endsWith:':\') ifFalse:[ |
|
857 |
path := path copyButLast:1 |
|
858 |
] |
|
8870
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
859 |
]. |
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
860 |
^ path |
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
861 |
|
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
862 |
" |
16562 | 863 |
'\foo' asFilename pathName |
864 |
'\foo\' asFilename pathName |
|
865 |
'\foo\bar' asFilename pathName |
|
866 |
'\foo\bar\' asFilename pathName |
|
867 |
'\' asFilename pathName |
|
868 |
'c:' asFilename pathName |
|
869 |
'c:\' asFilename pathName |
|
870 |
'c:\foo' asFilename pathName |
|
871 |
'c:\foo\' asFilename pathName |
|
872 |
'c:\foo\bar' asFilename pathName |
|
873 |
'c:\foo\bar\' asFilename pathName |
|
874 |
'\\idefix' asFilename pathName |
|
875 |
'\\idefix\home' asFilename pathName |
|
876 |
'\\idefix\home\foo' asFilename pathName |
|
8870
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
877 |
" |
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
878 |
|
23631 | 879 |
"Modified: / 24-09-1998 / 19:09:53 / cg" |
880 |
"Modified: / 22-01-2019 / 15:54:03 / Stefan Vogel" |
|
8870
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
881 |
! |
93dc7a3aec7c
remove trailing '\' when asked for the pathName
Claus Gittinger <cg@exept.de>
parents:
8824
diff
changeset
|
882 |
|
3336 | 883 |
volume |
884 |
"return the disc volume part of the name or an empty string. |
|
3853 | 885 |
This is only used with DOS filenames - on unix, an empty string is returned. |
16562 | 886 |
A full path can be reconstructed from |
20693 | 887 |
aFilename volume , aFilename localPathName |
3853 | 888 |
" |
3336 | 889 |
|
20693 | 890 |
|endIdx| |
3850
f4d25f3deac8
fixes for network drives (isRootDirectory)
Claus Gittinger <cg@exept.de>
parents:
3848
diff
changeset
|
891 |
|
3848 | 892 |
nameString size >= 2 ifTrue:[ |
20693 | 893 |
(nameString at:2) == $: ifTrue:[ |
894 |
^ nameString copyTo:2 |
|
895 |
]. |
|
896 |
(nameString startsWith:'\\') ifTrue:[ |
|
897 |
endIdx := nameString indexOf:$\ startingAt:3. |
|
898 |
endIdx == 0 ifTrue:[ |
|
899 |
^ nameString. |
|
900 |
]. |
|
901 |
^ nameString copyFrom:1 to:endIdx-1 |
|
902 |
]. |
|
3336 | 903 |
]. |
3815 | 904 |
|
3336 | 905 |
^ '' |
906 |
||
3853 | 907 |
" |
16562 | 908 |
'\foo' asFilename volume |
909 |
'\foo\' asFilename volume |
|
910 |
'\foo\bar' asFilename volume |
|
911 |
'\foo\bar\' asFilename volume |
|
912 |
'c:' asFilename volume |
|
913 |
'c:\' asFilename volume |
|
914 |
'c:\foo' asFilename volume |
|
915 |
'c:\foo\' asFilename volume |
|
916 |
'c:\foo\bar' asFilename volume |
|
917 |
'c:\foo\bar\' asFilename volume |
|
918 |
'c:\foo\bar\' asFilename localPathName |
|
919 |
'\\idefix' asFilename volume |
|
920 |
'\\idefix\home' asFilename volume |
|
921 |
'\\idefix\home\foo' asFilename volume |
|
922 |
'\\idefix\home\foo' asFilename localPathName |
|
3853 | 923 |
" |
924 |
||
925 |
"Modified: / 24.9.1998 / 19:04:27 / cg" |
|
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
926 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
927 |
|
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
928 |
!PCFilename methodsFor:'special accessing'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
929 |
|
7062 | 930 |
osNameForAccess |
11001
737865de3757
avoid relative pathname when asking for fileInfo
Claus Gittinger <cg@exept.de>
parents:
10993
diff
changeset
|
931 |
"/ mhmh - Win32operatingSystem gets confused, when we give it a relative name for fileInfo. |
737865de3757
avoid relative pathname when asking for fileInfo
Claus Gittinger <cg@exept.de>
parents:
10993
diff
changeset
|
932 |
(nameString startsWith:'..\') ifTrue:[ |
16562 | 933 |
^ self pathName |
11001
737865de3757
avoid relative pathname when asking for fileInfo
Claus Gittinger <cg@exept.de>
parents:
10993
diff
changeset
|
934 |
]. |
14219
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
935 |
^ self osNameForFile |
7062 | 936 |
! |
937 |
||
3570 | 938 |
osNameForDirectory |
939 |
"special - return the OS's name for the receiver to |
|
940 |
access it as a directory. |
|
23627 | 941 |
Care remove trailing backSlashes here." |
3749 | 942 |
|
14219
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
943 |
|n| |
3336 | 944 |
|
14219
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
945 |
n := self osNameForFile. |
7062 | 946 |
|
14219
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
947 |
(n endsWith:'\') ifTrue:[ |
23627 | 948 |
((n size == 3) and:[(n at:2) == $:]) ifFalse:[ |
949 |
"keep \ in c:\" |
|
950 |
n := n copyButLast:1 |
|
951 |
] |
|
3570 | 952 |
]. |
3765 | 953 |
"/ i := OperatingSystem infoOf:n. |
954 |
"/ (i notNil and:[(shortName := i alternativeName) notNil]) ifTrue:[ |
|
955 |
"/ ^ shortName |
|
956 |
"/ ]. |
|
3749 | 957 |
^ n |
3336 | 958 |
|
23627 | 959 |
"Modified: / 20-01-1998 / 15:39:06 / md" |
960 |
"Modified: / 17-08-1998 / 10:04:01 / cg" |
|
961 |
"Modified (comment): / 21-01-2019 / 16:04:49 / Stefan Vogel" |
|
3721
75e65b780e45
oops - need a kludge to read the top directory.
Claus Gittinger <cg@exept.de>
parents:
3708
diff
changeset
|
962 |
! |
75e65b780e45
oops - need a kludge to read the top directory.
Claus Gittinger <cg@exept.de>
parents:
3708
diff
changeset
|
963 |
|
7062 | 964 |
osNameForFile |
14219
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
965 |
"internal - return the OS's name for the receiver to |
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
966 |
access it as a file." |
7062 | 967 |
|
20247 | 968 |
(nameString includesAny:'~%') ifTrue:[ |
969 |
^ self class nameWithSpecialExpansions:nameString. |
|
7062 | 970 |
]. |
971 |
||
972 |
^ nameString |
|
14234 | 973 |
|
974 |
"Modified: / 21-07-2012 / 19:35:19 / cg" |
|
7062 | 975 |
! |
976 |
||
3570 | 977 |
setName:aString |
14219
94e162606bbc
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
13816
diff
changeset
|
978 |
"set the filename, convert unix directory separators to native separators" |
3570 | 979 |
|
23508 | 980 |
nameString := aString copyReplaceAll:$/ with:$\. |
981 |
self makeNonDOSName. |
|
3570 | 982 |
|
15530 | 983 |
"Created: / 22-01-1998 / 17:32:45 / md" |
984 |
"Modified: / 16-07-2013 / 19:44:00 / cg" |
|
23508 | 985 |
"Modified: / 05-11-2018 / 12:52:25 / Stefan Vogel" |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
986 |
! ! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
987 |
|
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
988 |
!PCFilename class methodsFor:'documentation'! |
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
989 |
|
3336 | 990 |
version |
19599 | 991 |
^ '$Header$' |
12389 | 992 |
! |
993 |
||
994 |
version_CVS |
|
19599 | 995 |
^ '$Header$' |
13619 | 996 |
! |
997 |
||
998 |
version_SVN |
|
19599 | 999 |
^ '$Id$' |
3708
27a62fa7b5bb
in #isVolumeAbsolute: care for filenames of the form: \hostname
Claus Gittinger <cg@exept.de>
parents:
3570
diff
changeset
|
1000 |
! ! |
20247 | 1001 |