导出 (0) 打印
全部展开
EN
此内容没有您的语言版本,但有英语版本。

IsolatedStorageFile.GetFileNames Method

Enumerates files in isolated storage scope that match a given pattern.

[Visual Basic]
Public Function GetFileNames( _
   ByVal searchPattern As String _
) As String()
[C#]
public string[] GetFileNames(
 string searchPattern
);
[C++]
public: String* GetFileNames(
 String* searchPattern
)  __gc[];
[JScript]
public function GetFileNames(
   searchPattern : String
) : String[];

Parameters

searchPattern
A search pattern. Both single-character ("?") and multi-character ("*") wildcards are supported.

Return Value

An Array of relative paths of files in the isolated storage scope that match searchPattern. A zero-length array specifies that there are no files that match.

Exceptions

Exception Type Condition
ArgumentNullException The searchPattern was a null reference (Nothing in Visual Basic).

Remarks

The searchPattern "Project\Data*.txt" will give all ".txt" files beginning with Data in the Project directory of the isolated storage scope. For complete description of search pattern strings, see System.IO.Directory.

For information about how to find directory names, see the GetDirectoryNames method.

The Finding Existing Files and Directories example demonstrates the use of the GetFileNames method.

Example

[Visual Basic, C#, C++] The following code example demonstrates the GetFileNames method. For the complete context of this example, see the IsolatedStorageFile overview.

[Visual Basic] 
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

[C#] 
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());
            }

[C++] 
String* dirNames[]  = isoFile->GetDirectoryNames(S"*");
String* fileNames[] = isoFile->GetFileNames(S"*");

// List directories currently in this Isolated Storage.
if (dirNames->Length>0)
{
   for (int i=0;i<dirNames->Length;++i) 
   {
      Console::WriteLine(S"Directory Name: {0}", dirNames[i]);
   }
}

// 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)
{
   for (int i=0;i<fileNames->Length;++i) 
   {
      Console::WriteLine(S"File Name: {0}", fileNames[i]);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

IsolatedStorageFile Class | IsolatedStorageFile Members | System.IO.IsolatedStorage Namespace

显示:
© 2015 Microsoft