IsolatedStorageFile.DeleteDirectory(String) Método
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Elimina un directorio del ámbito de almacenamiento aislado.
public:
void DeleteDirectory(System::String ^ dir);
public void DeleteDirectory (string dir);
member this.DeleteDirectory : string -> unit
Public Sub DeleteDirectory (dir As String)
- dir
- String
Ruta de acceso relativa del directorio que se va a eliminar en el ámbito de almacenamiento aislado.
No se pudo eliminar el directorio.
La ruta de acceso al directorio era 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
Un directorio debe estar vacío antes de eliminarlo. El directorio eliminado no se puede recuperar una vez eliminado.
En el ejemplo How to: Delete Files and Directoryies in Isolated Storage (Cómo: Eliminar archivos y directorios en almacenamiento aislado ) se muestra el uso del DeleteDirectory método .
Producto | Versiones |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
UWP | 10.0 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: