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
Комментарии
Каталог должен быть пустым перед удалением. Удаленный каталог невозможно восстановить после удаления.
В примере How to: Delete Files and Directories in Isolated Storage (Практическое руководство. Удаление файлов и каталогов в изолированномDeleteDirectory хранилище) показано использование метода .