Neko/Macro create directories recusively

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Neko/Macro create directories recusively

danielku15
Hi everybody.

It seems the neko.FileSystem.createDirectory method does not support the creation of recursive directories.
Take this example:

The directory "/home/me/haxe/" exists and is empty. If I call createDirectory("/home/me/haxe/top/sub") the directory cannot be created because the "top" directory is not existing.

Is there an easy way to create all directories in a path? In Java you would use File.mkdirs() for this task.

Greetings
Daniel
Reply | Threaded
Open this post in threaded view
|

Re: Neko/Macro create directories recusively

Tarwin Stroh-Spijer
I think you'd just split by '/', loop through them and see if they exist, if not create them.

You could easily make yourself a utility function for it ..


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Fri, Nov 4, 2011 at 3:09 AM, danielku15 <[hidden email]> wrote:
Hi everybody.

It seems the neko.FileSystem.createDirectory method does not support the
creation of recursive directories.
Take this example:

The directory "/home/me/haxe/" exists and is empty. If I call
createDirectory("/home/me/haxe/top/sub") the directory cannot be created
because the "top" directory is not existing.

Is there an easy way to create all directories in a path? In Java you would
use File.mkdirs() for this task.

Greetings
Daniel

--
View this message in context: http://haxe.1354130.n2.nabble.com/Neko-Macro-create-directories-recusively-tp6962272p6962272.html
Sent from the Haxe mailing list archive at Nabble.com.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Neko/Macro create directories recusively

Adrian Veith
In reply to this post by danielku15
Hi,

I use this function for your purpose:

 public static function forceDir(APath: String): Bool {
        //trace(APath);
        try {
            var path = new Path(APath);
            if (! FileSystem.exists(path.dir)) {
                //trace('check: ' + path.dir);
                if (forceDir(path.dir)) {
                    //trace('create: ' + path.dir);
                    FileSystem.createDirectory(path.dir);
                } else return false;
            }
            return true;
        } catch (e: Dynamic) {
            trace(e);
            return false;
        }
    }

best,

Adrian.

Am 04.11.2011 11:09, schrieb danielku15:

> Hi everybody.
>
> It seems the neko.FileSystem.createDirectory method does not support the
> creation of recursive directories.
> Take this example:
>
> The directory "/home/me/haxe/" exists and is empty. If I call
> createDirectory("/home/me/haxe/top/sub") the directory cannot be created
> because the "top" directory is not existing.
>
> Is there an easy way to create all directories in a path? In Java you would
> use File.mkdirs() for this task.
>
> Greetings
> Daniel
>
> --
> View this message in context: http://haxe.1354130.n2.nabble.com/Neko-Macro-create-directories-recusively-tp6962272p6962272.html
> Sent from the Haxe mailing list archive at Nabble.com.
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: Neko/Macro create directories recusively

danielku15
In reply to this post by danielku15
Thanks. I built an own solution and now everything works fine. Too bad there isn't an option for that.


Cheers
Daniel