Filename.st
changeset 360 90c3608b92a3
parent 359 b8df66983eff
child 379 5b5a130ccd09
equal deleted inserted replaced
359:b8df66983eff 360:90c3608b92a3
    18 
    18 
    19 Filename comment:'
    19 Filename comment:'
    20 COPYRIGHT (c) 1992 by Claus Gittinger
    20 COPYRIGHT (c) 1992 by Claus Gittinger
    21 	     All Rights Reserved
    21 	     All Rights Reserved
    22 
    22 
    23 $Header: /cvs/stx/stx/libbasic/Filename.st,v 1.28 1995-06-27 02:12:52 claus Exp $
    23 $Header: /cvs/stx/stx/libbasic/Filename.st,v 1.29 1995-07-02 01:06:48 claus Exp $
    24 '!
    24 '!
    25 
    25 
    26 !Filename class methodsFor:'documentation'!
    26 !Filename class methodsFor:'documentation'!
    27 
    27 
    28 copyright
    28 copyright
    39 "
    39 "
    40 !
    40 !
    41 
    41 
    42 version
    42 version
    43 "
    43 "
    44 $Header: /cvs/stx/stx/libbasic/Filename.st,v 1.28 1995-06-27 02:12:52 claus Exp $
    44 $Header: /cvs/stx/stx/libbasic/Filename.st,v 1.29 1995-07-02 01:06:48 claus Exp $
    45 "
    45 "
    46 !
    46 !
    47 
    47 
    48 documentation
    48 documentation
    49 "
    49 "
    67 	'Makefile' asFilename readStream
    67 	'Makefile' asFilename readStream
    68 
    68 
    69 	'newFile' asFilename writeStream
    69 	'newFile' asFilename writeStream
    70 
    70 
    71 	Filename newTemporary writeStream
    71 	Filename newTemporary writeStream
       
    72 "
       
    73 !
       
    74 
       
    75 examples
       
    76 "
       
    77     does a file/directory exist ?:
       
    78 
       
    79 	|f|
       
    80 
       
    81 	f := 'foobar' asFilename.
       
    82 	^ f exists  
       
    83 
       
    84 
       
    85     is it a directory ?:
       
    86 
       
    87 	|f|
       
    88 
       
    89 	f := '/tmp' asFilename.
       
    90 	^ f isDirectory.   
       
    91 
       
    92         
       
    93     get the working directory:
       
    94 
       
    95 	^ Filename defaultDirectory
       
    96 
       
    97 
       
    98     get a files full pathname 
       
    99     (caring for relative names or symbolic links):
       
   100 
       
   101 	|f|
       
   102 
       
   103 	f := '..' asFilename.
       
   104 	^ f pathName  
       
   105 
       
   106 
       
   107     get a directories directory:
       
   108 
       
   109 	|f|
       
   110 
       
   111 	f := Filename defaultDirectory.
       
   112 	^ f directory 
       
   113 
       
   114 
       
   115     get a files directory:
       
   116 
       
   117 	|f|
       
   118 
       
   119 	f := './smalltalk' asFilename.
       
   120 	^ f directory 
       
   121 
       
   122 
       
   123     getting access & modification times:
       
   124 
       
   125 
       
   126 	|f|
       
   127 
       
   128 	f := '/tmp' asFilename.
       
   129 	^ f dates
       
   130 
       
   131     access time only:
       
   132 
       
   133 	|f|
       
   134 
       
   135 	f := '/tmp' asFilename.
       
   136 	^ f dates at:#accessed  
       
   137         
       
   138 
       
   139     getting all information on a file/directory:
       
   140 
       
   141 
       
   142 	|f|
       
   143 
       
   144 	f := '/tmp' asFilename.
       
   145 	^ f info
       
   146 
       
   147 
       
   148     getting a temporary file (unique name):
       
   149 
       
   150 	|f|
       
   151 
       
   152 	f := Filename newTemporary.
       
   153 	^ f    
       
   154 
       
   155 
       
   156     creating, writing, reading and removing a temporary file:
       
   157 
       
   158 
       
   159 	|f writeStream readStream|
       
   160 
       
   161 	f := Filename newTemporary.
       
   162 	writeStream := f writeStream.
       
   163 	writeStream nextPutAll:'hello world'.
       
   164 	writeStream cr.
       
   165 	writeStream close.
       
   166 
       
   167 	'contents (as seen by unix''s cat command:' printNL.
       
   168 	OperatingSystem executeCommand:('cat ' , f pathName).
       
   169 
       
   170 	readStream := f readStream.
       
   171 	Transcript showCr:'contents as seen by smalltalk:'.
       
   172 	Transcript showCr:(readStream upToEnd).
       
   173 	readStream close.
       
   174 
       
   175 	f delete.
       
   176         
       
   177 
       
   178     getting a directories contents:
       
   179 
       
   180 	|f files|
       
   181 
       
   182 	f := '.' asFilename.
       
   183 	files := f directoryContents.
       
   184 	Transcript showCr:'the files are:'.
       
   185 	Transcript showCr:(files printString).
       
   186 
       
   187 
       
   188     editing a file:
       
   189 
       
   190 	|f|
       
   191 
       
   192 	f := '/tmp/fooBar' asFilename.
       
   193 	(f writeStream) nextPutAll:'hello world'; close.
       
   194 
       
   195 	f edit
    72 "
   196 "
    73 ! !
   197 ! !
    74 
   198 
    75 !Filename class methodsFor:'instance creation'!
   199 !Filename class methodsFor:'instance creation'!
    76 
   200