locked
Create nested folders and is there a System.Path equivalent? RRS feed

  • Question

  • Are there any helper classes to deal with file paths or to see whether a file exists.

    I'm trying to create a folder/file structure inside Windows.Storage.ApplicationData.current.localFolder. 

    Let's say I want to create a file like .\foo\bar\example.txt - createFileAsync doesn't seem to work if the folder doesn't exists so I need to create foo and bar but createFolderAsync also doesn't seem to support creating of nested folders and I don't even know how to get to foo\bar efficiently without string manipulation since there doesn't seem to be an equivalent to .NET Frameworks System.IO.Path class.

    How can I create this file/folder structure effectively?

    Thursday, March 22, 2012 1:07 AM

Answers

  • You need to create the folders one by one via WinRT API.

              Windows.Storage.ApplicationData.current.localFolder.createFolderAsync("foo", Windows.Storage.CreationCollisionOption.replaceExisting)
                    .then(function (f) {
                        return f.createFolderAsync("bar", Windows.Storage.CreationCollisionOption.replaceExisting);
                    }).then(function (f) {
                        return f.createFileAsync("file.dat");
                    });

    Or you could wrap an own WinRT helper class to do this function, then you could use it in JS.


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Patrick Klug Thursday, March 22, 2012 11:59 PM
    Thursday, March 22, 2012 7:18 AM