The first solution given by Sven works fine.

    dir := FileSystem workingDirectory / '..' / 'public'.
    dir ensureCreateDirectory.
    (dir / 'myFile.txt') writeStreamDo: [ :out | out << 'Hello World!' ].


The second version

    obj := (FileSystem workingDirectory / '..' / 'public' / 'testing'
/ 'test2.txt') ensureCreateFile.
    obj writeStream

gives a #streamError in the class FileHandle. This is for Pharo 6.1



On 3/11/18, Sven Van Caekenberghe <s...@stfx.eu> wrote:
>
>
>> On 11 Mar 2018, at 10:39, john pfersich <jpfers...@gmail.com> wrote:
>>
>> or try
>>
>> dir := (FileSystem workingDirectory / '..' / 'public' / 'testing' /
>> 'test2.txt') ensureCreateFile.
>> dir writeStream.
>
> Indeed!
>
>> On Sun, Mar 11, 2018 at 1:16 AM, Sven Van Caekenberghe <s...@stfx.eu>
>> wrote:
>>
>>
>> > On 11 Mar 2018, at 09:42, H. Hirzel <hannes.hir...@gmail.com> wrote:
>> >
>> > Hello
>> >
>> > This is a follow up question to 'How do I make sure a directory
>> > exists?'
>> >
>> > The answer to that question was
>> >
>> >       dir := FileSystem workingDirectory / '..' / 'public'.
>> >       dir ensureCreateDirectory.
>> >
>> >
>> > Now I want to create a writeStream.
>> >
>> >       dir writeStream
>> >
>> > gives 'Unable to open file'
>>
>> You want to write to a directory ?
>>
>> You probably mean
>>
>> dir := FileSystem workingDirectory / '..' / 'public'.
>> dir ensureCreateDirectory.
>> (dir / 'foo.txt') writeStreamDo: [ :out | out << 'bar' ].
>>
>> You are probably also looking for
>>
>> dir canonicalize.
>> (dir / 'foo.txt') canonicalize.
>>
>> > It seems that I need to ask to resolve the relative path first.
>> > How does the proper code idiom look like?
>> >
>> >
>> > Regards
>> >
>> > Hannes
>> >
>>
>>
>>
>
>
>

Reply via email to