다음을 통해 공유


IsolatedStorageFile.DeleteDirectory(String) 메서드

정의

격리된 스토리지 범위 내에 있는 디렉터리를 삭제합니다.

public:
 void DeleteDirectory(System::String ^ dir);
public void DeleteDirectory (string dir);
member this.DeleteDirectory : string -> unit
Public Sub DeleteDirectory (dir As String)

매개 변수

dir
String

격리된 스토리지 범위 내에서 삭제할 디렉터리에 대한 상대 경로입니다.

예외

디렉터리를 삭제할 수 없는 경우

디렉터리 경로가 null인 경우

예제

// This method deletes directories in the specified Isolated Storage, after first 
// deleting the files they contain. In this example, the Archive directory is deleted. 
// There should be no other directories in this Isolated Storage.
void DeleteDirectories()
{
   try
   {
      IsolatedStorageFile^ isoFile = IsolatedStorageFile::GetStore( static_cast<IsolatedStorageScope>(IsolatedStorageScope::User | IsolatedStorageScope::Assembly | IsolatedStorageScope::Domain), System::Security::Policy::Url::typeid, System::Security::Policy::Url::typeid );
      array<String^>^dirNames = isoFile->GetDirectoryNames( "*" );
      array<String^>^fileNames = isoFile->GetFileNames( "Archive\\*" );
      
      // Delete the current files within the Archive directory.
      if ( fileNames->Length > 0 )
      {
         for ( int i = 0; i < fileNames->Length; ++i )
         {
            
            //delete files
            isoFile->DeleteFile( String::Concat("Archive\\", fileNames[ i ]) );

         }
         fileNames = isoFile->GetFileNames( "Archive\\*" );
      }
      if ( dirNames->Length > 0 )
      {
         for ( int i = 0; i < dirNames->Length; ++i )
         {
            
            // Delete the Archive directory.
            isoFile->DeleteDirectory( dirNames[ i ] );

         }
      }
      dirNames = isoFile->GetDirectoryNames( "*" );
      isoFile->Remove();
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( e->ToString() );
   }

}
// This method deletes directories in the specified Isolated Storage, after first
// deleting the files they contain. In this example, the Archive directory is deleted.
// There should be no other directories in this Isolated Storage.
public void DeleteDirectories()
{
    try
    {
        IsolatedStorageFile isoFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
            IsolatedStorageScope.Assembly |
            IsolatedStorageScope.Domain,
            typeof(System.Security.Policy.Url),
            typeof(System.Security.Policy.Url));
        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());
    }
}
' This method deletes directories in the specified Isolated Storage, after first 
' deleting the files they contain. In this example, the Archive directory is deleted. 
' There should be no other directories in this Isolated Storage.
Public Sub DeleteDirectories()
    Try
        Dim isoFile As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User _
            Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, _
            GetType(System.Security.Policy.Url), GetType(System.Security.Policy.Url))
        Dim name As String
        Dim dirNames As String() = isoFile.GetDirectoryNames("*")
        Dim fileNames As String() = isoFile.GetFileNames("Archive\*")
        ' Delete all the files currently in the Archive directory.
        If fileNames.Length > 0 Then
            For Each name In fileNames
                isoFile.DeleteFile(("Archive\" & name))
            Next name
            'Confirm no files are left.
            fileNames = isoFile.GetFileNames("Archive\*")
        End If
        If dirNames.Length > 0 Then
            For Each name In dirNames
                ' Delete the Archive directory.
                isoFile.DeleteDirectory(name)
            Next name
        End If
        dirNames = isoFile.GetDirectoryNames("*")
        isoFile.Remove()
    Catch ex As Exception
        Console.WriteLine(ex.ToString())
    End Try
End Sub

설명

디렉터리가 삭제되기 전에 비어 있어야 합니다. 삭제된 디렉터리를 삭제한 후에는 복구할 수 없습니다.

방법: 격리된 스토리지에 파일 및 디렉터리 삭제 예제는 DeleteDirectory 메서드의 사용을 보여줍니다.

적용 대상

추가 정보