/// <summary> /// Creates a folder at the specified path, parent folders will be created automatically if necessary. If the folder already exists it will be overwitten /// </summary> /// <param name="library">The library to start in - you must request permissions for it in the app manifest</param> /// <param name="relativePath">Path to the folder in which to create the new folder</param> public static void CreateFolder(WSAStorageLibrary library, string relativePath) { #if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0) StorageFolder folder = GetStorageFolderForWSAKnownLibrary(library); StorageFolder createdFolder = folder.CreateFolderAsync(relativePath, CreationCollisionOption.ReplaceExisting).AsTask().Result; #endif }
/// <summary> /// Attempts to delete the folder at the specified path /// </summary> /// <param name="library">The library to start in - you must request permissions for it in the app manifest</param> /// <param name="relativePath">Path to the folder which should be deleted</param> public static void DeleteFolder(WSAStorageLibrary library, string relativePath) { #if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0) StorageFolder folder = GetStorageFolderForWSAKnownLibrary(library); StorageFolder folderToDelete = folder.GetFolderAsync(relativePath).AsTask().Result; folderToDelete.DeleteAsync().AsTask().Wait(); #endif }
/// <summary> /// Gets the names of all the folders at the specified path /// </summary> /// <param name="library">The library to start in - you must request permissions for it in the app manifest</param> /// <param name="relativePath">Path to the folder to look in - empty string for the root</param> /// <param name="result">Collection of folders at the specified path</param> public static void GetFolders(WSAStorageLibrary library, string relativePath, Action <IEnumerable <string> > result) { #if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0) if (result != null) { StorageFolder folder = GetStorageFolderForWSAKnownLibrary(library); GetFoldersAsync(folder, relativePath, result); } #endif }
/// <summary> /// Creates a file at the specified path and returns a handle to it, parent folders will be created automatically if necessary. /// If the file already exists it will be overwritten /// </summary> /// <param name="library">The library to start in - you must request permissions for it in the app manifest</param> /// <param name="relativePath">Path to the folder in which to create the file</param> /// <returns>A handle to the created file</returns> public static WSAStorageFile CreateFile(WSAStorageLibrary library, string relativePath) { #if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0) StorageFolder folder = GetStorageFolderForWSAKnownLibrary(library); StorageFile file = folder.CreateFileAsync(relativePath, CreationCollisionOption.ReplaceExisting).AsTask().Result; WSAStorageFile mappedFile = MapStorageFileToWSAStorageFile(file); return(mappedFile); #else return(new WSAStorageFile()); #endif }
private static StorageFolder GetStorageFolderForWSAKnownLibrary(WSAStorageLibrary wsaStorageLibrary) { switch (wsaStorageLibrary) { case WSAStorageLibrary.Local: return(ApplicationData.Current.LocalFolder); case WSAStorageLibrary.Music: return(KnownFolders.MusicLibrary); case WSAStorageLibrary.Pictures: return(KnownFolders.PicturesLibrary); default: return(KnownFolders.VideosLibrary); } }
/// <summary> /// Determines whether a folder exists /// </summary> /// <param name="library">The library to start in - you must request permissions for it in the app manifest</param> /// <param name="relativePath">Path to the folder</param> /// <returns>True if the folder exists, otherwise false</returns> public static bool DoesFolderExist(WSAStorageLibrary library, string relativePath) { #if NETFX_CORE || (ENABLE_IL2CPP && UNITY_WSA_10_0) StorageFolder folder = GetStorageFolderForWSAKnownLibrary(library); try { folder.GetFolderAsync(relativePath).AsTask().Wait(); return(true); } catch { } #endif return(false); }