Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

IsolatedStorageFile.GetDirectoryNames Method

Enumerates directories in an isolated storage scope that match a given pattern.

[Visual Basic]
Public Function GetDirectoryNames( _
   ByVal searchPattern As String _
) As String()
public string[] GetDirectoryNames(
 string searchPattern
public: String* GetDirectoryNames(
 String* searchPattern
)  __gc[];
public function GetDirectoryNames(
   searchPattern : String
) : String[];


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

Return Value

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


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


Wildcard characters must only be in the final element of a searchPattern. For instance, "directory1/*etc*" is a valid search string, but "*etc*/directory" is not.

The searchPattern "Project\Data*" will give all subdirectories of Project beginning with Data in the isolated storage scope. The searchPattern "*" will return all directories located in the root. For complete description of search string criteria, see the Directory class.

For information on getting file names, see the GetFileNames method.

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


[Visual Basic, C#, C++] The following code example demonstrates the GetDirectoryNames 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

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("*");
            catch (Exception e)

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.


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

© 2018 Microsoft