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