'From Pharo-1.1.1-- of 12 September 2010 [Latest update: #11414] on 26 June 2011 at 9:36:46 am'! Object subclass: #File instanceVariableNames: '' classVariableNames: '' poolDictionaries: '' category: 'DolphinCompatibility-Streams'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! File class instanceVariableNames: ''! !File class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 8/27/2009 13:11'! contentsOf:fileName "Answer a ByteArray of the contents of the file." | in | "8-09 - blowing up trying to read empty.mdb; something about multibyte streams and invalid input. in := FileStream read:fileName text:false." in := FileStream read:fileName text:false. [ in reset. ^in upToEnd. ] ensure:[ in close. ]. ! ! !File class methodsFor: 'as yet unclassified' stamp: 'Bill Schwab 9/30/2008 15:54'! createDirectory:path "9-08- for compatibility with Dolphin." " File createDirectory:'c:\docs\_createDirectoryTest'. FileDirectory dirPathFor:'c:\docs\_createDirectoryTest'. FileDirectory on:'c:\docs\_createDirectoryTest'. SmalltalkImage current imagePath. " | directory fileName | FileDirectory splitName:path to:[ :directoryName :aName | directory := FileDirectory on:directoryName. fileName := aName. ]. ( directory directoryExists:fileName ) ifFalse:[ directory createDirectory:fileName. ]. ! ! !File class methodsFor: 'as yet unclassified' stamp: 'BillSchwab 6/26/2011 09:36'! createDirectoryPath:fullPath "10-09 - Dolphin compatibility - recursively create all directories that do not exist." | dir out path | dir := FileDirectory on:fullPath. out := String writeStream. dir pathParts do:[ :each | "6-11 - hard-coded separator - bad." out nextPut:$/; nextPutAll:each. path := out contents. ( dir directoryExists:path ) ifFalse:[ File createDirectory:path. ]. ]. ! ! !File class methodsFor: 'as yet unclassified' stamp: 'BillSchwab 8/31/2010 11:56'! delete:fullPath "10-09 - Dolphin compatibility" | dir local | dir := FileDirectory on:( self splitPathFrom:fullPath ). local := dir localNameFor:fullPath. ^dir deleteFileNamed:local. ! ! !File class methodsFor: 'as yet unclassified' stamp: 'BillSchwab 10/11/2009 15:13'! exists:fullPath "10-09 - Dolphin compatibility" | dir | dir := FileDirectory on:( self splitPathFrom:fullPath ). ^dir fileExists:fullPath. ! ! !File class methodsFor: 'as yet unclassified' stamp: 'BillSchwab 10/3/2009 23:31'! for:searchPath do:aBlock "10-09 - Dolphin compatibility. Evaluate the block with a DirectoryEntry corresponding to each file or directory matching the search path, presumed to include wildcards." | directory fileNameSpec | "10-09 - Squeak appears to have no ready way to search for files by wildcard!!!!!! See FileList>>entriesMatching:." fileNameSpec := File splitFilenameFrom:searchPath. directory := FileDirectory on:( File splitPathFrom:searchPath ). directory entries do:[ :each | ( fileNameSpec match:each name ) ifTrue:[ aBlock value:each. ]. ]. ! ! !File class methodsFor: 'as yet unclassified' stamp: 'BillSchwab 10/4/2009 22:43'! for:spec in:directoryName do:aBlock "10-09 - Dolphin compatibility. Search for the file spec in the named directory." ^self for:( File composePath:directoryName subPath:spec ) do:aBlock ! ! !File class methodsFor: 'file name manipulation' stamp: 'Bill Schwab 6/2/2009 05:29'! change:fileName extension:newExt | oldExt stem dot workingExt | oldExt := self splitExtensionFrom:fileName. stem := fileName copyFrom:1 to:fileName size - oldExt size. dot := FileDirectory dot. workingExt := ( newExt beginsWith:dot ) ifTrue:[ newExt copyFrom:2 to:newExt size ] ifFalse:[newExt ]. ^stem last = dot first ifTrue:[ stem, workingExt ] ifFalse:[ stem, dot, workingExt ] " File change:'M:\Webs\wschwab\BibusFullText\VADS\this and that.pdf' extension:'txt'. File change:'M:\Webs\wschwab\BibusFullText\VADS\this and that.pdf' extension:'.txt'. "! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 8/31/2010 11:34'! composePath:path subPath:subPath "9-08 - emulate Dolphin's approach to assembling file names. Check carefully, because Dolphin might handle 'c:\this\that' + 'something\somethingelse.dat' better than this implementation, or maybe not, as this appear to work." | dir result | dir := FileDirectory on:path. result := dir fullNameFor:subPath. "8-10 - try to support ~/style/path/names" ( result beginsWith:'/~' ) ifTrue:[ result := result copyFrom:2 to:result size. ]. ^result. " File composePath:'c:\docs\here\there' subPath:'something.dat'. File composePath:'c:\docs\here' subPath:'there\something.dat'. File composePath:'~/docs/something' subPath:'somethingElse.txt'. " ! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 8/17/2010 17:11'! composePath:path subPath:subPath subPath:again "8-10 - overdue; concatenate a path and two subpaths (any more?)." ^File composePath:( File composePath:path subPath:subPath ) subPath:again. ! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 6/11/2011 10:09'! composePath:path subPath:subPath subPath:again subPath:andAgain "6-11 - overdue; concatenate a path and three subpaths (any more?)." ^File composePath:( File composePath:path subPath:subPath subPath:again ) subPath:andAgain. " File composePath:'/home/me/here' subPath:'there' subPath:'there2' subPath:'this.that' " ! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 8/31/2010 10:44'! composeStem:stem extension:ext ^ext first = $. ifTrue:[ stem, ext. ] ifFalse:[ stem, '.', ext. ].! ! !File class methodsFor: 'file name manipulation' stamp: 'Bill Schwab 6/2/2009 01:09'! splitExtensionFrom:fileName ^FileDirectory extensionFor:fileName. ! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 6/11/2011 09:54'! splitFilenameFrom: path FileDirectory splitName:path to:[ :directoryName :aName | ^aName. ]. " File splitFilenameFrom:'/here/there/this.that' " ! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 10/3/2009 14:19'! splitPathFrom: path FileDirectory splitName:path to:[ :directoryName :aName | ^directoryName. ]. " File splitPathFrom:'~/docs/VADS/this and that.pdf'. " ! ! !File class methodsFor: 'file name manipulation' stamp: 'BillSchwab 8/17/2010 17:12'! splitStemFrom: path "8-10 - get the file name minus path and extension." ^File splitFilenameFrom:( FileDirectory baseNameFor:path ). " File splitStemFrom:'M:\Webs\wschwab\BibusFullText\VADS\this and that.pdf'. File splitStemFrom:'/home/use/linux/this and that.pdf'. File splitStemFrom:'/this and that.pdf'. " ! !