2014-01-23 23 views
0

我試圖得到一個文件夾中的文件的數量,但它給我下面的異常獲取文件數在文件夾中的WP8

{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)」中的例外情況,我不知道可以用它來做什麼工作?

+0

我認爲你必須使用你的IsolatedStorageFile實例的方式來訪問任何文件系統的東西。參見:http://msdn.microsoft.com/en-us/library/c02ys433(v=vs.110).aspx – Mark

+0

非常感謝,終於在String []結尾添加了fileNames = isoFile.GetFileNames(「Archive \\ *「); – ARH

回答

0

最可能的原因是,您嘗試訪問獨立存儲。

使用「GetFileNames()」或OpenFile()等隔離存儲方法來訪問隔離存儲文件。

+0

我會接受你的回覆作爲回答,我知道馬克確實爲我提供了足夠的信息供我查詢。 – ARH

0

在文件夾路徑中不應有空格。

MP3文件應該是Mp3Files

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