2465 Return true if successful, false if not." |
2465 Return true if successful, false if not." |
2466 |
2466 |
2467 ^ OperatingSystem createDirectory:(self osNameForDirectory) |
2467 ^ OperatingSystem createDirectory:(self osNameForDirectory) |
2468 ! |
2468 ! |
2469 |
2469 |
2470 copyTo:newName |
2470 copyTo:newNameArg |
2471 "Copy the files contents into another file. |
2471 "Copy the files contents into another file. |
2472 The argument must be convertable to a filename. |
2472 The argument must be convertable to a filename. |
2473 Raises an exception, if an error occurs." |
2473 Raises an exception, if an error occurs." |
2474 |
2474 |
2475 |inStream outStream| |
2475 |newName inStream outStream| |
|
2476 |
|
2477 newName := newNameArg asFilename. |
2476 |
2478 |
2477 "Contents is not copied if newName represent same file as me." |
2479 "Contents is not copied if newName represent same file as me." |
2478 newName asFilename asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
2480 newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
2479 |
2481 |
2480 inStream := self readStream. |
2482 inStream := self readStream. |
2481 inStream isNil ifTrue:[ |
2483 inStream isNil ifTrue:[ |
2482 ^ self fileNotFoundError:self |
2484 ^ self fileNotFoundError:self |
2483 ]. |
2485 ]. |
2484 |
2486 |
2485 [ |
2487 [ |
2486 outStream := newName asFilename writeStream. |
2488 outStream := newName writeStream. |
2487 outStream isNil ifTrue:[ |
2489 outStream isNil ifTrue:[ |
2488 ^ self fileCreationError:newName asFilename |
2490 ^ self fileCreationError:newName |
2489 ]. |
2491 ]. |
2490 inStream binary. |
2492 inStream binary. |
2491 outStream binary. |
2493 outStream binary. |
2492 |
2494 |
2493 [ |
2495 [ |
2494 inStream copyToEndInto:outStream. |
2496 inStream copyToEndInto:outStream. |
2495 ] on:OperatingSystem errorSignal do:[:ex| |
2497 ] on:OperatingSystem errorSignal do:[:ex| |
2496 ^ self fileCreationError:newName asFilename |
2498 ^ self fileCreationError:newName |
2497 ] |
2499 ] |
2498 ] ensure:[ |
2500 ] ensure:[ |
2499 inStream close. |
2501 inStream close. |
2500 outStream notNil ifTrue:[outStream close]. |
2502 outStream notNil ifTrue:[outStream close]. |
2501 ]. |
2503 ]. |
2504 'Makefile' asFilename copyTo:'/tmp/Makefile.foo' |
2506 'Makefile' asFilename copyTo:'/tmp/Makefile.foo' |
2505 'Makefile' asFilename copyTo:'/' |
2507 'Makefile' asFilename copyTo:'/' |
2506 'smalltalk' asFilename copyTo:'/dev/null' |
2508 'smalltalk' asFilename copyTo:'/dev/null' |
2507 " |
2509 " |
2508 |
2510 |
2509 "Modified: / 23.12.1999 / 21:52:36 / cg" |
2511 "Modified: / 10-09-2004 / 09:49:28 / janfrog" |
2510 "Modified: / 10.9.2004 / 09:49:28 / janfrog" |
2512 "Modified: / 29-09-2006 / 16:26:32 / cg" |
2511 ! |
2513 ! |
2512 |
2514 |
2513 createAsEmptyFile |
2515 createAsEmptyFile |
2514 "create an empty file with the receivers name. |
2516 "create an empty file with the receivers name. |
2515 Raises an exception if not successful |
2517 Raises an exception if not successful |