首页 > 代码库 > Winphone 删除文件夹IsolatedStorageFile.DeleteDirectory

Winphone 删除文件夹IsolatedStorageFile.DeleteDirectory

Winphone 没有直接删除文件夹的接口(因为文件夹不为空是删除不了的),所以要自己实现


public static void DeleteDirectoryRecursively(this IsolatedStorageFile storageFile, String dirName){
    String pattern = dirName + @"\*";
    String[] files = storageFile.GetFileNames(pattern);
    foreach (var fName in files)
    {
        storageFile.DeleteFile(Path.Combine(dirName, fName));
    }
    String[] dirs = storageFile.GetDirectoryNames(pattern);
    foreach (var dName in dirs)
    {
        DeleteDirectoryRecursively(storageFile, Path.Combine(dirName, dName));
    }
    storageFile.DeleteDirectory(dirName);}

http://stackoverflow.com/questions/18422331/easy-way-to-recursively-delete-directories-in-isolatedstorage-on-wp7-8