Skip to Content
VB.NET Language in a Nutshell, Second Edition
book

VB.NET Language in a Nutshell, Second Edition

by Steven Roman PhD, Ron Petrusha, Paul Lomax
April 2002
Intermediate to advanced
688 pages
19h 51m
English
O'Reilly Media, Inc.
Content preview from VB.NET Language in a Nutshell, Second Edition

Name

Kill Procedure

Class

Microsoft.VisualBasic.FileSystem

Syntax

Kill(pathname)
pathname (required; String)

The file or files to be deleted

Description

Deletes a file from disk

Rules at a Glance

  • If pathname does not include a drive letter, the folder and file are assumed to be on the current drive.

  • If pathname does not include a folder name, the file is assumed to be in the current folder.

  • You can use the multiple-character (*) and single-character (?) wildcards to specify multiple files to delete.

  • If the file is open or is set to read only, an error will be generated.

Programming Tips and Gotchas

  • Note that the deleted file is not placed in the Recycle Bin. However, the following code demonstrates how to use the FileOperation API found in Shell32.DLL to move a file to the Windows Recycle Bin:

    Option Explicit 'declare the file operation structure Type SHFILEOPSTRUCT hWnd As Long wFunction As Long pFrom As String pTo As String fFlags As Integer fAborted As Boolean hNameMaps As Long sProgress As String End Type 'declare two constants needed for the delete operation Private Const FO_DELETE = &H3 Private Const FO_FLAG_ALLOWUNDO = &H40 'declare the API call function Declare Function SHFileOperation Lib "shell32.dll" _ Alias "SHFileOperationA" _ (lpFileOp As SHFILEOPSTRUCT) As Long Public Function WinDelete(sFileName As String) As Long 'create a copy of the file operation structure Dim SHFileOp As SHFILEOPSTRUCT 'need a Null terminated string sFileName = sFileName & vbNullChar 'assign relevant ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

VB .NET Language in a Nutshell

VB .NET Language in a Nutshell

Steven Roman PhD, Ron Petrusha, Paul Lomax

Publisher Resources

ISBN: 0596003080Supplemental ContentCatalog PageErrata