PCFilename.st
changeset 3789 7a6456f7161c
parent 3765 82e1d3f99746
child 3815 57aff51fbbfb
equal deleted inserted replaced
3788:ea7d4f4a2ba6 3789:7a6456f7161c
   176     ^ 'st%1%2'
   176     ^ 'st%1%2'
   177 
   177 
   178     "Created: 30.1.1998 / 12:09:18 / dq"
   178     "Created: 30.1.1998 / 12:09:18 / dq"
   179 ! !
   179 ! !
   180 
   180 
       
   181 !PCFilename methodsFor:'converting'!
       
   182 
       
   183 makeLegalFilename 
       
   184     "convert the receivers name to be a legal filename.
       
   185      This removes/replaces invalid characters and/or compresses
       
   186      the name as required by Win95-WinNT."
       
   187 
       
   188     |srchStart|
       
   189 
       
   190     "/ there may be only one colon in the name
       
   191     "/ (and if present, it must be the second character)
       
   192 
       
   193     ((nameString size >= 2)
       
   194     and:[(nameString at:2) == $:]) ifTrue:[
       
   195         srchStart := 3.
       
   196     ] ifFalse:[
       
   197         srchStart := 1
       
   198     ].
       
   199 
       
   200     "/ replace colons by underscore
       
   201     "/ may need more to convert - time will show
       
   202 
       
   203     (nameString indexOfAny:#($:) startingAt:srchStart) ~~ 0 ifTrue:[
       
   204         nameString := nameString copy.
       
   205         nameString replaceAny:#($:) with:$_ from:srchStart to:(nameString size).
       
   206     ].
       
   207     ^ self
       
   208 
       
   209     "
       
   210      'hello world' asFilename makeLegalFilename 
       
   211      'hello:world' asFilename makeLegalFilename 
       
   212      'hello::world' asFilename makeLegalFilename 
       
   213      'c:hello::world' asFilename makeLegalFilename 
       
   214     "
       
   215 
       
   216     "Modified: / 27.8.1998 / 12:52:03 / cg"
       
   217 ! !
       
   218 
   181 !PCFilename methodsFor:'file operations'!
   219 !PCFilename methodsFor:'file operations'!
   182 
   220 
   183 renameTo:newName
   221 renameTo:newName
   184     "rename the file - the argument must be convertable to a String.
   222     "rename the file - the argument must be convertable to a String.
   185      Raise an error if not successful.
   223      Raise an error if not successful.
   349 ! !
   387 ! !
   350 
   388 
   351 !PCFilename class methodsFor:'documentation'!
   389 !PCFilename class methodsFor:'documentation'!
   352 
   390 
   353 version
   391 version
   354     ^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.13 1998-08-17 08:04:54 cg Exp $'
   392     ^ '$Header: /cvs/stx/stx/libbasic/PCFilename.st,v 1.14 1998-08-27 11:36:39 cg Exp $'
   355 ! !
   393 ! !