FileSystem.DeleteFile Método

Definição

Exclui um arquivo.Deletes a file.

Sobrecargas

DeleteFile(String)

Exclui um arquivo.Deletes a file.

DeleteFile(String, UIOption, RecycleOption)

Exclui um arquivo.Deletes a file.

DeleteFile(String, UIOption, RecycleOption, UICancelOption)

Exclui um arquivo.Deletes a file.

DeleteFile(String)

Exclui um arquivo.Deletes a file.

public:
 static void DeleteFile(System::String ^ file);
public static void DeleteFile (string file);
static member DeleteFile : string -> unit
Public Shared Sub DeleteFile (file As String)

Parâmetros

file
String

O nome e o caminho do arquivo a ser excluído.Name and path of the file to be deleted.

Exceções

O caminho não é válido por um dos seguintes motivos: é uma cadeia de caracteres de tamanho zero, contém somente espaço em branco, contém caracteres inválidos, tem uma barra à direita na qual um arquivo deve ser especificado ou é um caminho de dispositivo (começa com \\.\).The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; it has a trailing slash where a file must be specified; or it is a device path (starts with \\.\).

file é Nothing ou é uma cadeia de caracteres vazia.file is Nothing or an empty string.

O caminho excede o tamanho máximo definido pelo sistema.The path exceeds the system-defined maximum length.

Um nome de arquivo ou de diretório no caminho contém dois-pontos (:) ou está em um formato inválido.A file or directory name in the path contains a colon (:) or is in an invalid format.

O arquivo está em uso.The file is in use.

O usuário não tem as permissões necessárias para exibir o caminho.The user lacks necessary permissions to view the path.

O arquivo não existe.The file does not exist.

O usuário não tem permissão para excluir o arquivo ou o arquivo é somente leitura.The user does not have permission to delete the file or the file is read-only.

Exemplos

Este exemplo exclui o arquivo Test.txt .This example deletes the file Test.txt.

My.Computer.FileSystem.DeleteFile("C:\test.txt")

Este exemplo exclui o arquivo Test.txt e permite que o usuário confirme se o arquivo deve ser excluído.This example deletes the file Test.txt and allows the user to confirm that the file should be deleted.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

Este exemplo exclui o arquivo Test.txt e o envia para a Lixeira.This example deletes the file Test.txt and sends it to the Recycle Bin.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.OnlyErrorDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

Comentários

A tabela a seguir lista um exemplo de uma tarefa que envolve o My.Computer.FileSystem.DeleteFile método.The following table lists an example of a task involving the My.Computer.FileSystem.DeleteFile method.

ParaTo ConsulteSee
Para excluir um arquivoTo delete a file Como excluir um arquivo no Visual BasicHow to: Delete a File in Visual Basic

Aplica-se a

DeleteFile(String, UIOption, RecycleOption)

Exclui um arquivo.Deletes a file.

public:
 static void DeleteFile(System::String ^ file, Microsoft::VisualBasic::FileIO::UIOption showUI, Microsoft::VisualBasic::FileIO::RecycleOption recycle);
public static void DeleteFile (string file, Microsoft.VisualBasic.FileIO.UIOption showUI, Microsoft.VisualBasic.FileIO.RecycleOption recycle);
static member DeleteFile : string * Microsoft.VisualBasic.FileIO.UIOption * Microsoft.VisualBasic.FileIO.RecycleOption -> unit
Public Shared Sub DeleteFile (file As String, showUI As UIOption, recycle As RecycleOption)

Parâmetros

file
String

O nome e o caminho do arquivo a ser excluído.Name and path of the file to be deleted.

showUI
UIOption

Se o progresso da operação deve ser acompanhado visualmente.Whether to visually track the operation's progress. O padrão é UIOption.OnlyErrorDialogs.Default is UIOption.OnlyErrorDialogs.

recycle
RecycleOption

Se o arquivo excluído deve ou não ser enviado para a Lixeira.Whether or not the deleted file should be sent to the Recycle Bin. O padrão é RecycleOption.DeletePermanently.Default is RecycleOption.DeletePermanently.

Exceções

O caminho não é válido por um dos seguintes motivos: é uma cadeia de caracteres de tamanho zero, contém somente espaço em branco, contém caracteres inválidos, tem uma barra à direita na qual um arquivo deve ser especificado ou é um caminho de dispositivo (começa com \\.\).The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; it has a trailing slash where a file must be specified; or it is a device path (starts with \\.\).

file é Nothing ou é uma cadeia de caracteres vazia.file is Nothing or an empty string.

O caminho excede o tamanho máximo definido pelo sistema.The path exceeds the system-defined maximum length.

Um nome de arquivo ou de diretório no caminho contém dois-pontos (:) ou está em um formato inválido.A file or directory name in the path contains a colon (:) or is in an invalid format.

O arquivo está em uso.The file is in use.

O usuário não tem as permissões necessárias para exibir o caminho.The user lacks necessary permissions to view the path.

O arquivo não existe.The file does not exist.

O usuário não tem permissão para excluir o arquivo ou o arquivo é somente leitura.The user does not have permission to delete the file or the file is read-only.

Exemplos

Este exemplo exclui o arquivo Test.txt .This example deletes the file Test.txt.

My.Computer.FileSystem.DeleteFile("C:\test.txt")

Este exemplo exclui o arquivo Test.txt e permite que o usuário confirme se o arquivo deve ser excluído.This example deletes the file Test.txt and allows the user to confirm that the file should be deleted.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

Este exemplo exclui o arquivo Test.txt e o envia para a Lixeira.This example deletes the file Test.txt and sends it to the Recycle Bin.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.OnlyErrorDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

Comentários

Os showUI recycle parâmetros e não têm suporte em aplicativos que não são interativos pelo usuário, como os serviços do Windows.The showUI and recycle parameters are not supported in applications that are not user interactive, such as Windows Services.

A tabela a seguir lista um exemplo de uma tarefa que envolve o My.Computer.FileSystem.DeleteFile método.The following table lists an example of a task involving the My.Computer.FileSystem.DeleteFile method.

ParaTo ConsulteSee
Para excluir um arquivoTo delete a file Como excluir um arquivo no Visual BasicHow to: Delete a File in Visual Basic

Confira também

Aplica-se a

DeleteFile(String, UIOption, RecycleOption, UICancelOption)

Exclui um arquivo.Deletes a file.

public:
 static void DeleteFile(System::String ^ file, Microsoft::VisualBasic::FileIO::UIOption showUI, Microsoft::VisualBasic::FileIO::RecycleOption recycle, Microsoft::VisualBasic::FileIO::UICancelOption onUserCancel);
public static void DeleteFile (string file, Microsoft.VisualBasic.FileIO.UIOption showUI, Microsoft.VisualBasic.FileIO.RecycleOption recycle, Microsoft.VisualBasic.FileIO.UICancelOption onUserCancel);
static member DeleteFile : string * Microsoft.VisualBasic.FileIO.UIOption * Microsoft.VisualBasic.FileIO.RecycleOption * Microsoft.VisualBasic.FileIO.UICancelOption -> unit
Public Shared Sub DeleteFile (file As String, showUI As UIOption, recycle As RecycleOption, onUserCancel As UICancelOption)

Parâmetros

file
String

O nome e o caminho do arquivo a ser excluído.Name and path of the file to be deleted.

showUI
UIOption

Se o progresso da operação deve ser acompanhado visualmente.Whether to visually track the operation's progress. O padrão é UIOption.OnlyErrorDialogs.Default is UIOption.OnlyErrorDialogs.

recycle
RecycleOption

Se o arquivo excluído deve ou não ser enviado para a Lixeira.Whether or not the deleted file should be sent to the Recycle Bin. O padrão é RecycleOption.DeletePermanently.Default is RecycleOption.DeletePermanently.

onUserCancel
UICancelOption

Especifica se uma exceção é lançada ou não quando o usuário cancela a operação.Specifies whether or not an exception is thrown when the user cancels the operation. O padrão é UICancelOption.ThrowException.Default is UICancelOption.ThrowException.

Exceções

O caminho não é válido por um dos seguintes motivos: é uma cadeia de caracteres de tamanho zero, contém somente espaço em branco, contém caracteres inválidos, tem uma barra à direita na qual um arquivo deve ser especificado ou é um caminho de dispositivo (começa com \\.\).The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; it has a trailing slash where a file must be specified; or it is a device path (starts with \\.\).

file é Nothing ou é uma cadeia de caracteres vazia.file is Nothing or an empty string.

O caminho excede o tamanho máximo definido pelo sistema.The path exceeds the system-defined maximum length.

Um nome de arquivo ou de diretório no caminho contém dois-pontos (:) ou está em um formato inválido.A file or directory name in the path contains a colon (:) or is in an invalid format.

O arquivo está em uso.The file is in use.

O usuário não tem as permissões necessárias para exibir o caminho.The user lacks necessary permissions to view the path.

O arquivo não existe.The file does not exist.

O usuário não tem permissão para excluir o arquivo ou o arquivo é somente leitura.The user does not have permission to delete the file or the file is read-only.

O usuário cancelou a operação e onUserCancel está definido para ThrowException.The user cancelled the operation and onUserCancel is set to ThrowException.

Exemplos

Este exemplo exclui o arquivo Test.txt .This example deletes the file Test.txt.

My.Computer.FileSystem.DeleteFile("C:\test.txt")

Este exemplo exclui o arquivo Test.txt e permite que o usuário confirme se o arquivo deve ser excluído.This example deletes the file Test.txt and allows the user to confirm that the file should be deleted.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.AllDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

Este exemplo exclui o arquivo Test.txt e o envia para a Lixeira.This example deletes the file Test.txt and sends it to the Recycle Bin.

My.Computer.FileSystem.DeleteFile(
  "C:\test.txt",
  FileIO.UIOption.OnlyErrorDialogs,
  FileIO.RecycleOption.SendToRecycleBin,
  FileIO.UICancelOption.ThrowException)

Comentários

Os showUI recycle parâmetros,, e onUserCancel não têm suporte em aplicativos que não são interativos pelo usuário, como os serviços do Windows.The showUI, recycle, and onUserCancel parameters are not supported in applications that are not user interactive, such as Windows Services.

A tabela a seguir lista um exemplo de uma tarefa que envolve o My.Computer.FileSystem.DeleteFile método.The following table lists an example of a task involving the My.Computer.FileSystem.DeleteFile method.

ParaTo ConsulteSee
Para excluir um arquivoTo delete a file Como excluir um arquivo no Visual BasicHow to: Delete a File in Visual Basic

Confira também

Aplica-se a