OFF97: Kill Statement May Delete All Files in a FolderLast reviewed: February 27, 1998Article ID: Q169093 |
The information in this article applies to:
SYMPTOMSIn any of the programs listed at the beginning of this article, if you run a Visual Basic for Applications macro that includes the Kill statement, the macro may delete all of the files stored in a folder on a network server.
CAUSEThis behavior may occur when all of the following conditions are true:
RESOLUTIONMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. To prevent files from being deleted by the Kill statement, verify that the Kill statements always refer to both a valid path and a valid file name. The following examples demonstrate the syntax to use:
Kill "\\server\share\myfiles\*.old" Kill "E:\myfiles\*.old" Dim FileList As String FileList = "*.old" Kill "\\server\share\myfiles\" & FileList Dim FileList As String, NetPath As String NetPath = "\\server\share\myfiles\" FileList = "*.old" Kill NetPath & FileListThese are all valid uses of the Kill statement. You can also prevent this problem from occurring by making sure that there are no drive letters that are mapped to shares on the network server. The problem occurs only if a drive letter is mapped to the server.
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe Kill statement in Visual Basic for Applications allows you to delete files from a disk. The syntax is as follows:
Kill <pathname>The variable <pathname> refers to the path and file name of the file (or files) that you want to delete. You can use multiple character (*) and single character (?) wildcards to specify multiple files that you want to delete with the Kill statement. If you want to delete all of the files in a folder, make sure that the path name that is used by the Kill statement ends in "*.*." For example, to delete all of the files in the folder E:\myfiles, you could use the following code:
Kill "E:\myfiles\*.*" -or- Dim FileList As String FileList = "*.*" Kill "E:\myfiles\" & FileListDo NOT use a path name without a valid file name. For example, the following Kill statements may cause the problem described in this article to occur:
Kill "" Kill "\\server\share\" Kill "\\server\share\myfiles\" Kill "E:\" Kill "E:\myfiles\" Dim FileList As String Kill FileList Dim FileList As String Kill "\\server\share\myfiles\" & FileListIf the current folder or the folder that is specified in the Kill statement is stored on a computer running Microsoft Windows 95, or if the folder is stored on a computer running Microsoft Windows NT, and no drive letter is mapped to the server, you receive the following error message
Run-time error '53': File not foundif the path name is invalid. In this case, no files are deleted.
REFERENCESFor more information about the Kill statement, click the Office Assistant in the Visual Basic Editor, type "kill" (without the quotation marks), click Search, and then click to view "Kill Statement." NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Microsoft Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q120802 TITLE : Office: How to Add/Remove a Single Office Program or Component |
Additional query words: XL97 xlvbainfo
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |