語言

IsolatedStorageFile.GetDirectoryNames 方法

定義

列舉孤立商店根部的目錄。

多載

名稱 Description
GetDirectoryNames()

列舉孤立商店根部的目錄。

GetDirectoryNames(String)

列舉與特定搜尋模式相符的隔離儲存範圍目錄。

GetDirectoryNames()

來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs

列舉孤立商店根部的目錄。

public:
 cli::array <System::String ^> ^ GetDirectoryNames();
public string[] GetDirectoryNames();
[System.Runtime.InteropServices.ComVisible(false)]
public string[] GetDirectoryNames();
member this.GetDirectoryNames : unit -> string[]
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.GetDirectoryNames : unit -> string[]
Public Function GetDirectoryNames () As String()

傳回

String[]

孤立儲存根節點目錄的相對路徑陣列。 零長度陣列則指定根節點不存在目錄。

屬性

例外狀況

這間孤立的商店已被處理掉。

那家孤立的商店已經關閉。

隔離的商店已被拆除。

來電者無權列舉目錄。

找不到一個或多個目錄。

備註

此方法等同於使用 IsolatedStorageFile.GetDirectoryNames(String) 指定「*」的搜尋模式方法。

另請參閱

適用於

GetDirectoryNames(String)

來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs
來源:
IsolatedStorageFile.cs

列舉與特定搜尋模式相符的隔離儲存範圍目錄。

public:
 cli::array <System::String ^> ^ GetDirectoryNames(System::String ^ searchPattern);
public string[] GetDirectoryNames(string searchPattern);
member this.GetDirectoryNames : string -> string[]
Public Function GetDirectoryNames (searchPattern As String) As String()

參數

searchPattern
String

一種搜尋模式。 支援單字元(“?”)與多字元(“*”)萬用字元。

傳回

String[]

一個陣列,列出隔離儲存範圍中與 相符 searchPattern的目錄相對路徑。 零長度陣列則表示沒有與其相符的目錄。

例外狀況

searchPattern 是 null。

那家孤立的商店已經關閉。

這間孤立的商店已被處理掉。

呼叫者無權列舉從 解決 searchPattern的目錄。

找不到指定的 searchPattern 目錄或目錄。

隔離的商店已被拆除。

範例

以下程式碼範例示範了此 GetDirectoryNames 方法。 關於此範例的完整背景,請參閱 IsolatedStorageFile 概述。

    String[] dirNames = isoFile.GetDirectoryNames("*");
    String[] fileNames = isoFile.GetFileNames("Archive\\*");

    // Delete all the files currently in the Archive directory.

    if (fileNames.Length > 0)
    {
        for (int i = 0; i < fileNames.Length; ++i)
        {
            // Delete the files.
            isoFile.DeleteFile("Archive\\" + fileNames[i]);
        }
        // Confirm that no files remain.
        fileNames = isoFile.GetFileNames("Archive\\*");
    }

    if (dirNames.Length > 0)
    {
        for (int i = 0; i < dirNames.Length; ++i)
        {
            // Delete the Archive directory.
        }
    }
    dirNames = isoFile.GetDirectoryNames("*");
    isoFile.Remove();
}
catch (Exception e)
{
    Console.WriteLine(e.ToString());
}
Dim dirNames As String() = isoFile.GetDirectoryNames("*")
Dim fileNames As String() = isoFile.GetFileNames("*")
Dim name As String

' List directories currently in this Isolated Storage.
If dirNames.Length > 0 Then

    For Each name In dirNames
        Console.WriteLine("Directory Name: " & name)
    Next name
End If

' List the files currently in this Isolated Storage.
' The list represents all users who have personal preferences stored for this application.
If fileNames.Length > 0 Then

    For Each name In fileNames
        Console.WriteLine("File Name: " & name)
    Next name
End If

備註

萬用字元只能位於 的最後元素 searchPattern中。 例如,「directory1/*etc*」是有效的搜尋字串,但「*etc*/directory」則不是。

searchPattern「Project\Data*」會提供隔離儲存範圍內以 Data 開頭的所有Project子目錄。 「 searchPattern *」會回傳所有位於根目錄中的目錄。 欲了解搜尋字串條件的完整描述,請參閱該 Directory 類別。

關於取得檔案名稱的資訊,請參見方法。GetFileNames

「如何使用:在隔離儲存中尋找現有檔案與目錄」範例展示了此GetDirectoryNames方法的使用。

另請參閱

適用於