How do I make sure a directory exists?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How do I make sure a directory exists?

Hannes Hirzel
Hello

In Squeak and the dialect independent FileMan [1] there is


    FileDirectory
       assureExistence
            "Make sure the current directory exists. If necessary, create all
parts in between"


What is the equivalent Pharo method? BTW is there a cheat sheet for
FileSystem operations in Pharo?

Thanks in advance
Hannes



---------------------------------------------------------
[1] http://wiki.squeak.org/squeak/6333

https://github.com/mumez/FileMan

FileMan provides an API to file and directory tasks.
FileMan is a thin wrapper for various Smalltalk file libraries. It
provides simple, portable interfaces for manipulating files and
directories.
...
Since 2015 FileMan is the default file library in Cuis Smalltalk.

Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Sven Van Caekenberghe-2
Probably #ensureCreateDirectory

> On 10 Mar 2018, at 21:01, H. Hirzel <[hidden email]> wrote:
>
> Hello
>
> In Squeak and the dialect independent FileMan [1] there is
>
>
>    FileDirectory
>       assureExistence
>    "Make sure the current directory exists. If necessary, create all
> parts in between"
>
>
> What is the equivalent Pharo method? BTW is there a cheat sheet for
> FileSystem operations in Pharo?
>
> Thanks in advance
> Hannes
>
>
>
> ---------------------------------------------------------
> [1] http://wiki.squeak.org/squeak/6333
>
> https://github.com/mumez/FileMan
>
> FileMan provides an API to file and directory tasks.
> FileMan is a thin wrapper for various Smalltalk file libraries. It
> provides simple, portable interfaces for manipulating files and
> directories.
> ...
> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>


Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

CyrilFerlicot
In reply to this post by Hannes Hirzel

On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
Hello

In Squeak and the dialect independent FileMan [1] there is


    FileDirectory
       assureExistence
            "Make sure the current directory exists. If necessary, create all
parts in between"


What is the equivalent Pharo method? BTW is there a cheat sheet for
FileSystem operations in Pharo?

Hi,

There is #ensureCreateDirectory in Pharo but I don't know if it will check the parents exists. (And I don't have a Pharo image to check.


Thanks in advance
Hannes



---------------------------------------------------------
[1] http://wiki.squeak.org/squeak/6333

https://github.com/mumez/FileMan

FileMan provides an API to file and directory tasks.
FileMan is a thin wrapper for various Smalltalk file libraries. It
provides simple, portable interfaces for manipulating files and
directories.
...
Since 2015 FileMan is the default file library in Cuis Smalltalk.

--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Peter Uhnak
There is #ensureCreateDirectory in Pharo but I don't know if it will check the parents exists. (And I don't have a Pharo image to check.

It will, at least on Windows.

Peter
Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Hannes Hirzel
In reply to this post by CyrilFerlicot
Yes, #ensureCreateDirectory is available.

I'd like to make sure a directory 'public' is available as a sibling
directory of the working directory (the directory where the Pharo
image is in)

However

    FileSystem disk workingDirectory / '../public'  ensureCreateDirectory

does not work as

    FileSystem disk workingDirectory / '../public'

is an instance of ByteStream. Seemingly there is no conversion to a
directory object.

I wonder what is needed in addition?







On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:

> On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
>
>> Hello
>>
>> In Squeak and the dialect independent FileMan [1] there is
>>
>>
>>     FileDirectory
>>        assureExistence
>>             "Make sure the current directory exists. If necessary, create
>> all
>> parts in between"
>>
>>
>> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> FileSystem operations in Pharo?
>>
>
> Hi,
>
> There is #ensureCreateDirectory in Pharo but I don't know if it will check
> the parents exists. (And I don't have a Pharo image to check.
>
>
>> Thanks in advance
>> Hannes
>>
>>
>>
>> ---------------------------------------------------------
>> [1] http://wiki.squeak.org/squeak/6333
>>
>> https://github.com/mumez/FileMan
>>
>> FileMan provides an API to file and directory tasks.
>> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> provides simple, portable interfaces for manipulating files and
>> directories.
>> ...
>> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>>
>> --
> Cyril Ferlicot
> https://ferlicot.fr
>
> http://www.synectique.eu
> 2 rue Jacques Prévert 01,
> 59650 Villeneuve d'ascq France
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

CyrilFerlicot

On sam. 10 mars 2018 at 21:36, H. Hirzel <[hidden email]> wrote:
Yes, #ensureCreateDirectory is available.

I'd like to make sure a directory 'public' is available as a sibling
directory of the working directory (the directory where the Pharo
image is in)

However

    FileSystem disk workingDirectory / '../public'  ensureCreateDirectory

does not work as

    FileSystem disk workingDirectory / '../public'

Try `(FileSystem workingDirectory / '..' / 'public') ensureCreateDirectory`


is an instance of ByteStream. Seemingly there is no conversion to a
directory object.

I wonder what is needed in addition?







On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:
> On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
>
>> Hello
>>
>> In Squeak and the dialect independent FileMan [1] there is
>>
>>
>>     FileDirectory
>>        assureExistence
>>             "Make sure the current directory exists. If necessary, create
>> all
>> parts in between"
>>
>>
>> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> FileSystem operations in Pharo?
>>
>
> Hi,
>
> There is #ensureCreateDirectory in Pharo but I don't know if it will check
> the parents exists. (And I don't have a Pharo image to check.
>
>
>> Thanks in advance
>> Hannes
>>
>>
>>
>> ---------------------------------------------------------
>> [1] http://wiki.squeak.org/squeak/6333
>>
>> https://github.com/mumez/FileMan
>>
>> FileMan provides an API to file and directory tasks.
>> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> provides simple, portable interfaces for manipulating files and
>> directories.
>> ...
>> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>>
>> --
> Cyril Ferlicot
> https://ferlicot.fr
>
> http://www.synectique.eu
> 2 rue Jacques Prévert 01,
> 59650 Villeneuve d'ascq France
>

--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Peter Uhnak
In reply to this post by Hannes Hirzel
Operator priority :); unary messages `#ensureCreateDirectory have precedence over binary `#/`

(FileSystem disk workingDirectory / '../public') ensureCreateDirectory.

Also please note that the workingDirectory should be based on where Pharow as launched from, if you are looking for the image directory, then use the following

FileLocator imageDirectory asFileReference

Cheers,
Peter

On Sat, Mar 10, 2018 at 9:35 PM, H. Hirzel <[hidden email]> wrote:
Yes, #ensureCreateDirectory is available.

I'd like to make sure a directory 'public' is available as a sibling
directory of the working directory (the directory where the Pharo
image is in)

However

    FileSystem disk workingDirectory / '../public'  ensureCreateDirectory

does not work as

    FileSystem disk workingDirectory / '../public'

is an instance of ByteStream. Seemingly there is no conversion to a
directory object.

I wonder what is needed in addition?







On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:
> On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
>
>> Hello
>>
>> In Squeak and the dialect independent FileMan [1] there is
>>
>>
>>     FileDirectory
>>        assureExistence
>>             "Make sure the current directory exists. If necessary, create
>> all
>> parts in between"
>>
>>
>> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> FileSystem operations in Pharo?
>>
>
> Hi,
>
> There is #ensureCreateDirectory in Pharo but I don't know if it will check
> the parents exists. (And I don't have a Pharo image to check.
>
>
>> Thanks in advance
>> Hannes
>>
>>
>>
>> ---------------------------------------------------------
>> [1] http://wiki.squeak.org/squeak/6333
>>
>> https://github.com/mumez/FileMan
>>
>> FileMan provides an API to file and directory tasks.
>> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> provides simple, portable interfaces for manipulating files and
>> directories.
>> ...
>> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>>
>> --
> Cyril Ferlicot
> https://ferlicot.fr
>
> http://www.synectique.eu
> 2 rue Jacques Prévert 01,
> 59650 Villeneuve d'ascq France
>


Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Hannes Hirzel
I note that 'workingDirectory' is the directory where Pharo is
launched from. In my case it happens to be the same where the image is
in but that cannot be assumed generally.

So

    (FileSystem workingDirectory / '..' / 'public') ensureCreateDirectory


Worked fine.


Thanks to all!

--Hannes

On 3/10/18, Peter Uhnák <[hidden email]> wrote:

> Operator priority :); unary messages `#ensureCreateDirectory have
> precedence over binary `#/`
>
> (FileSystem disk workingDirectory / '../public') ensureCreateDirectory.
>
> Also please note that the workingDirectory should be based on where Pharow
> as launched from, if you are looking for the image directory, then use the
> following
>
> FileLocator imageDirectory asFileReference
>
> Cheers,
> Peter
>
> On Sat, Mar 10, 2018 at 9:35 PM, H. Hirzel <[hidden email]> wrote:
>
>> Yes, #ensureCreateDirectory is available.
>>
>> I'd like to make sure a directory 'public' is available as a sibling
>> directory of the working directory (the directory where the Pharo
>> image is in)
>>
>> However
>>
>>     FileSystem disk workingDirectory / '../public'  ensureCreateDirectory
>>
>> does not work as
>>
>>     FileSystem disk workingDirectory / '../public'
>>
>> is an instance of ByteStream. Seemingly there is no conversion to a
>> directory object.
>>
>> I wonder what is needed in addition?
>>
>>
>>
>>
>>
>>
>>
>> On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:
>> > On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]>
>> wrote:
>> >
>> >> Hello
>> >>
>> >> In Squeak and the dialect independent FileMan [1] there is
>> >>
>> >>
>> >>     FileDirectory
>> >>        assureExistence
>> >>             "Make sure the current directory exists. If necessary,
>> create
>> >> all
>> >> parts in between"
>> >>
>> >>
>> >> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> >> FileSystem operations in Pharo?
>> >>
>> >
>> > Hi,
>> >
>> > There is #ensureCreateDirectory in Pharo but I don't know if it will
>> check
>> > the parents exists. (And I don't have a Pharo image to check.
>> >
>> >
>> >> Thanks in advance
>> >> Hannes
>> >>
>> >>
>> >>
>> >> ---------------------------------------------------------
>> >> [1] http://wiki.squeak.org/squeak/6333
>> >>
>> >> https://github.com/mumez/FileMan
>> >>
>> >> FileMan provides an API to file and directory tasks.
>> >> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> >> provides simple, portable interfaces for manipulating files and
>> >> directories.
>> >> ...
>> >> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>> >>
>> >> --
>> > Cyril Ferlicot
>> > https://ferlicot.fr
>> >
>> > http://www.synectique.eu
>> > 2 rue Jacques Prévert 01,
>> > 59650 Villeneuve d'ascq France
>> >
>>
>>
>

Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

CyrilFerlicot

On sam. 10 mars 2018 at 21:49, H. Hirzel <[hidden email]> wrote:
I note that 'workingDirectory' is the directory where Pharo is
launched from. In my case it happens to be the same where the image is
in but that cannot be assumed generally.

The fact that "workingDirectory" point to the folder from where Pharo was launched is only valid since Pharo 7. Before there was no distinction between workingDirectory and imageDirectory which caused problems when you wanted to script. 



So

    (FileSystem workingDirectory / '..' / 'public') ensureCreateDirectory


Worked fine.


Thanks to all!

--Hannes
--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

John Pfersich
In reply to this post by CyrilFerlicot
Works on Ubuntu 16.04

Sent from my iPhone
Encrypted email at [hidden email]

On Mar 10, 2018, at 12:38, Cyril Ferlicot <[hidden email]> wrote:


On sam. 10 mars 2018 at 21:36, H. Hirzel <[hidden email]> wrote:
Yes, #ensureCreateDirectory is available.

I'd like to make sure a directory 'public' is available as a sibling
directory of the working directory (the directory where the Pharo
image is in)

However

    FileSystem disk workingDirectory / '../public'  ensureCreateDirectory

does not work as

    FileSystem disk workingDirectory / '../public'

Try `(FileSystem workingDirectory / '..' / 'public') ensureCreateDirectory`


is an instance of ByteStream. Seemingly there is no conversion to a
directory object.

I wonder what is needed in addition?







On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:
> On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
>
>> Hello
>>
>> In Squeak and the dialect independent FileMan [1] there is
>>
>>
>>     FileDirectory
>>        assureExistence
>>             "Make sure the current directory exists. If necessary, create
>> all
>> parts in between"
>>
>>
>> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> FileSystem operations in Pharo?
>>
>
> Hi,
>
> There is #ensureCreateDirectory in Pharo but I don't know if it will check
> the parents exists. (And I don't have a Pharo image to check.
>
>
>> Thanks in advance
>> Hannes
>>
>>
>>
>> ---------------------------------------------------------
>> [1] http://wiki.squeak.org/squeak/6333
>>
>> https://github.com/mumez/FileMan
>>
>> FileMan provides an API to file and directory tasks.
>> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> provides simple, portable interfaces for manipulating files and
>> directories.
>> ...
>> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>>
>> --
> Cyril Ferlicot
> https://ferlicot.fr
>
> http://www.synectique.eu
> 2 rue Jacques Prévert 01,
> 59650 Villeneuve d'ascq France
>

--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Guillermo Polito
You can also do:

FileSystem disk workingDirectory parent / 'public'.

I feel it cleaner :)

On Sun, Mar 11, 2018 at 10:27 AM, john pfersich <[hidden email]> wrote:
Works on Ubuntu 16.04

Sent from my iPhone
Encrypted email at [hidden email]

On Mar 10, 2018, at 12:38, Cyril Ferlicot <[hidden email]> wrote:


On sam. 10 mars 2018 at 21:36, H. Hirzel <[hidden email]> wrote:
Yes, #ensureCreateDirectory is available.

I'd like to make sure a directory 'public' is available as a sibling
directory of the working directory (the directory where the Pharo
image is in)

However

    FileSystem disk workingDirectory / '../public'  ensureCreateDirectory

does not work as

    FileSystem disk workingDirectory / '../public'

Try `(FileSystem workingDirectory / '..' / 'public') ensureCreateDirectory`


is an instance of ByteStream. Seemingly there is no conversion to a
directory object.

I wonder what is needed in addition?







On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:
> On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
>
>> Hello
>>
>> In Squeak and the dialect independent FileMan [1] there is
>>
>>
>>     FileDirectory
>>        assureExistence
>>             "Make sure the current directory exists. If necessary, create
>> all
>> parts in between"
>>
>>
>> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> FileSystem operations in Pharo?
>>
>
> Hi,
>
> There is #ensureCreateDirectory in Pharo but I don't know if it will check
> the parents exists. (And I don't have a Pharo image to check.
>
>
>> Thanks in advance
>> Hannes
>>
>>
>>
>> ---------------------------------------------------------
>> [1] http://wiki.squeak.org/squeak/6333
>>
>> https://github.com/mumez/FileMan
>>
>> FileMan provides an API to file and directory tasks.
>> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> provides simple, portable interfaces for manipulating files and
>> directories.
>> ...
>> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>>
>> --
> Cyril Ferlicot
> https://ferlicot.fr
>
> http://www.synectique.eu
> 2 rue Jacques Prévert 01,
> 59650 Villeneuve d'ascq France
>

--
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France



--

   

Guille Polito

Research Engineer

Centre de Recherche en Informatique, Signal et Automatique de Lille

CRIStAL - UMR 9189

French National Center for Scientific Research - http://www.cnrs.fr


Web: http://guillep.github.io

Phone: +33 06 52 70 66 13

Reply | Threaded
Open this post in threaded view
|

Re: How do I make sure a directory exists?

Sven Van Caekenberghe-2


> On 12 Mar 2018, at 10:11, Guillermo Polito <[hidden email]> wrote:
>
> You can also do:
>
> FileSystem disk workingDirectory parent / 'public'.
>
> I feel it cleaner :)

Indeed, the power of messages.

> On Sun, Mar 11, 2018 at 10:27 AM, john pfersich <[hidden email]> wrote:
> Works on Ubuntu 16.04
>
> Sent from my iPhone
> Encrypted email at [hidden email]
>
> On Mar 10, 2018, at 12:38, Cyril Ferlicot <[hidden email]> wrote:
>
>>
>> On sam. 10 mars 2018 at 21:36, H. Hirzel <[hidden email]> wrote:
>> Yes, #ensureCreateDirectory is available.
>>
>> I'd like to make sure a directory 'public' is available as a sibling
>> directory of the working directory (the directory where the Pharo
>> image is in)
>>
>> However
>>
>>     FileSystem disk workingDirectory / '../public'  ensureCreateDirectory
>>
>> does not work as
>>
>>     FileSystem disk workingDirectory / '../public'
>>
>> Try `(FileSystem workingDirectory / '..' / 'public') ensureCreateDirectory`
>>
>>
>> is an instance of ByteStream. Seemingly there is no conversion to a
>> directory object.
>>
>> I wonder what is needed in addition?
>>
>>
>>
>>
>>
>>
>>
>> On 3/10/18, Cyril Ferlicot <[hidden email]> wrote:
>> > On sam. 10 mars 2018 at 21:02, H. Hirzel <[hidden email]> wrote:
>> >
>> >> Hello
>> >>
>> >> In Squeak and the dialect independent FileMan [1] there is
>> >>
>> >>
>> >>     FileDirectory
>> >>        assureExistence
>> >>             "Make sure the current directory exists. If necessary, create
>> >> all
>> >> parts in between"
>> >>
>> >>
>> >> What is the equivalent Pharo method? BTW is there a cheat sheet for
>> >> FileSystem operations in Pharo?
>> >>
>> >
>> > Hi,
>> >
>> > There is #ensureCreateDirectory in Pharo but I don't know if it will check
>> > the parents exists. (And I don't have a Pharo image to check.
>> >
>> >
>> >> Thanks in advance
>> >> Hannes
>> >>
>> >>
>> >>
>> >> ---------------------------------------------------------
>> >> [1] http://wiki.squeak.org/squeak/6333
>> >>
>> >> https://github.com/mumez/FileMan
>> >>
>> >> FileMan provides an API to file and directory tasks.
>> >> FileMan is a thin wrapper for various Smalltalk file libraries. It
>> >> provides simple, portable interfaces for manipulating files and
>> >> directories.
>> >> ...
>> >> Since 2015 FileMan is the default file library in Cuis Smalltalk.
>> >>
>> >> --
>> > Cyril Ferlicot
>> > https://ferlicot.fr
>> >
>> > http://www.synectique.eu
>> > 2 rue Jacques Prévert 01,
>> > 59650 Villeneuve d'ascq France
>> >
>>
>> --
>> Cyril Ferlicot
>> https://ferlicot.fr
>>
>> http://www.synectique.eu
>> 2 rue Jacques Prévert 01,
>> 59650 Villeneuve d'ascq France
>
>
>
> --
>    
> Guille Polito
> Research Engineer
>
> Centre de Recherche en Informatique, Signal et Automatique de Lille
> CRIStAL - UMR 9189
> French National Center for Scientific Research - http://www.cnrs.fr
>
> Web: http://guillep.github.io
> Phone: +33 06 52 70 66 13