Here's what I came up with - it works, but I would be interested to know if there are any better alternatives:
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Linq;
public static class IsolatedStorageFileExtensions
{
public static List<string> GetAllFilePaths(this IsolatedStorageFile isolatedStorageFile)
{
List<string> result = new List<string>();
Stack<string> stack = new Stack<string>();
string initialDirectory = "*";
stack.Push(initialDirectory);
while (stack.Count > 0)
{
string dir = stack.Pop();
string directoryPath;
if (dir == "*")
{
directoryPath = "*";
}
else
{
directoryPath = dir + @"\*";
}
var filesInCurrentDirectory = isolatedStorageFile.GetFileNames(directoryPath).ToList<string>();
List<string> filesInCurrentDirectoryWithFolderName = new List<string>();
foreach (string file in filesInCurrentDirectory)
{
filesInCurrentDirectoryWithFolderName.Add(Path.Combine(dir, file));
}
result.AddRange(filesInCurrentDirectoryWithFolderName);
foreach (string directoryName in isolatedStorageFile.GetDirectoryNames(directoryPath))
{
stack.Push(directoryName);
}
}
return result;
}
}
source
share