获取wp8中文件夹中的文件数

时间:2014-01-23 13:20:45

标签: c# windows-phone-8

我正在尝试获取文件夹中的文件数量,但它给出了以下异常

{System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Data\Programs\{6AF473D1-D227-423A-B6A6-EA76F880B1F8}\Install\Mp3 Files\0\113'

我正在使用下面的

检索文件
public static bool versesExists(byte suraNumber, byte reciterID)
        {
            string folderPath = string.Format("{0}{1}{2}", @"Mp3 Files\", reciterID, @"\" + suraNumber + @"\");
            int totalSuraAyas = 0;
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (storage.DirectoryExists(folderPath))
                {
                    try
                    {

                        DirectoryInfo dir = new System.IO.DirectoryInfo(folderPath);
                        FileInfo[] files = dir.GetFiles("*.mp3");
                        if (files.Length == totalSuraAyas)
                            return true;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return false;
                    }

                }
            }
            return false;
        }

如果您看到我正在检查该目录是否存在,那么请转到文件,但它在“GetFiles(* .mp3)”中提供了例外,我不知道它可以用什么工作?

2 个答案:

答案 0 :(得分:0)

最可能的原因是,您正在尝试访问独立存储。

使用“GetFileNames()”或OpenFile()等隔离存储方法访问隔离存储文件。

答案 1 :(得分:0)

文件夹路径中不应有空格。

Mp3文件应为Mp3Files

string folderPath = string.Format("{0}{1}{2}", @"Mp3Files\", reciterID, @"\" + suraNumber + @"\");