0

Creating directories using BrightScript

Is it possible to create a directory on the SD card using BrightScript? I've been able to create a file, like this:

  CreateObject("roCreateFile", "SD:/dir1/dir2/aNewFile")

However, this assumes that dir1/dir2 already exists on the SD card. If not, they are not created implicitly. I also tried this

  CreateObject("roCreateFile", "SD:/dir1/")

Hoping that it would see the trailing slash, and create a directory rather than a file. But it did not.

Since there's an API to create files, it would seem as a strange omission that those can't be created anywhere except at the root level, unless the directories have already been created by other means. So I guess I'm overlooking someghing.

-JM

PS: Using the latest 6.1.37 beta version on an XD232, fwiw.

3 comments

  • 0
    Avatar
    Romeo

    Hi,

    >Is it possible to create a directory on the SD card using BrightScript?

    Yes. as per the below info from the object reference manual:

    CreateDirectory(directory As String) As Boolean: Creates the specified directory. Only one directory can be created at a time. This method returns True upon success and False upon failure.

    so in order to create a directory, subdirectory and check that they were successfully created you could do this:

     

    Ok1 = CreateDirectory("dir1")

    print " Ok1 :  " Ok1

    Ok2 = CreateDirectory("dir1/dir2")

    print " Ok2 :  " Ok2

     

    Regards,

    Romeo

     

  • 0
    Avatar
    Jean Michel

    Thanks! I was looking for this functionality on the roXxxFile objects, where I would have expected to find it, and not on the roGlobal object. It could make sense to improve your docs in this area, with a pointer back to the roGlobal object under the roXxxFile for additional file related functions.

    -JM

  • 0
    Avatar
    BrightSign TechDocs

    Hi Jean Michel,

    That's a good idea. We'll add some pointers to roGlobal in the file creation entries.

Please sign in to leave a comment.