Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Deleting Files

Posted on 2003-02-28
Medium Priority
Last Modified: 2010-05-01
In VB 6, what code can I use to delete files from a directory?
Question by:Patsfan
LVL 70

Expert Comment

by:Éric Moreau
ID: 8043181
you can use the VB Kill statement
LVL 18

Expert Comment

ID: 8043186
Kill "C:\my documents\*.*"
LVL 18

Expert Comment

ID: 8043189
sorry for the dup post emoreau
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 8043331
Thanks!  It worked fine.
LVL 70

Accepted Solution

Éric Moreau earned 200 total points
ID: 8043573
To close the question, you need to accept one of the comment. You will find a button for this on the gray bar separating comments.

Expert Comment

ID: 8054370
Try this code (API):

Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long

DeleteFile "C:\KPD-Team\test.kpd"

If you what to delete more files use FINDFIRSTFILE function, after that use FindNextFunction. This is more usefull if you have System File, Hiden or ReadOnly Files

Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long

Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question