File and Directory limitations

In order to use the File and Directory functions, we put this at the beginning of our C# script:

#if UNITY_WINRT
using UnityEngine.Windows;
using File = UnityEngine.Windows.File;
using Directory = UnityEngine.Windows.Directory;
#else
using System.IO;
using File = System.IO.File;
using Directory = System.IO.Directory;
#endif

However, there are a few functions that are not supported by UnityEngine.Windows. For example: Directory.GetFiles or File.Move.

Is there a way to workaround these limitations?

Specifically asking about our most important problem to solve: Is there a way to get the list of files in a folder / directory?

You can use StorageFile and StorageFolder classes from Windows.Storage namespace.
In order to use them, the script must be compiled using .NET Core and the code with these classes wrapped with #if NETFX_CORE.
Or you can write a plugin.

Thank you again Aurimas.

My problem in the same project is what I explained a few minutes ago and you chimed to help…

http://forum.unity3d.com/threads/241202-Strange-build-errors?p=1597737#post1597737

Compiling using .NET Core, I get the build error. So I guess my only solution is to convert scripts between js and c#. Correct?

There would be another solution. When you select “Use .NET Core partially”, scripts in Assets/Standard Assets, Assets/Pro Standard Assets and Assets/Plugins are compiled using Mono C# compiler, while all the others are compiled using Microsoft C# compiler. In result, JS can see classes from those three folders and you can use WinRT APIs in all other C# scripts.

Thank you for the explanation Tautvydas. This might help on future projects.

The problem is that the C# functions being called from JS are precisely those with the WinRT APIs

Another solution without changing your program architecture would be setting up callbacks to scripts that are allowed to call WinRT APIs.

Hi Tautvydas

Would it be possible to use Unity Networking by selecting “Use .NET Core partially”, and placing the Networking related scripts in Standard Assets?

No. That option just switches the compiler, which allows accessing C# classes from UnityScript and Boo. The cost of that is that these scripts can not use WinRT API.
This compilation option does not make any part of Unity API work. It might compile scripts in some cases, but they will still fail at runtime. Exception is restricted .NET APIs, which might compile and work, but they will fail certification later, so you won’t be able to submit your game to store.

Hi there, i got the same problem with Directiory.GetFile() with Win Store, so can u help me ? I’m newbee.
Thanks !