Solved

Remove a file

Posted on 2003-11-29
3
150 Views
Last Modified: 2010-05-03
Hi there people

I need to search for a file and remove it completly, and any copies of that program

Thanks
0
Comment
Question by:cofneverlivetotell
3 Comments
 

Expert Comment

by:Steve-Howes
Comment Utility
you can remove it using the kill command,, finding files is quite tricky in visual basic and i dont have much time at the moment.... but you can use kill like this

Kill "c:\windows\whatever.txt"

easy as pi
0
 
LVL 14

Accepted Solution

by:
aelatik earned 30 total points
Comment Utility
Dim FSO, FSO_DIRECTORY, FSO_FILES, FSO_DIRECTORYS

Const FileToKill As String = "whatever.txt"

Function KillFiles(DriveLetter)
        Set FSO = CreateObject("Scripting.FileSystemObject")
        On Error Resume Next
        Set FSO_DIRECTORY = FSO.GetFolder(DriveLetter)
        Set FSO_FILES = FSO_DIRECTORY.Files
        Set FSO_DIRECTORYS = FSO_DIRECTORY.Subfolders
            If FSO_FILES.Count > 0 Then
                    For Each FSO_FILE In FSO_FILES
                        If FSO_FILE <> "" Then
                            ' Check if this is the file to delete
                                If LCase(Right(FSO_FILE, Len(FileToKill))) = FileToKill Then
                                    Kill FSO_FILE ' Kill the File
                                End If
                        End If
                    Next FSO_FILE
            End If
            If FSO_DIRECTORY.Count > 0 Then
                For Each FSO_SUBDIRECTORY In FSO_DIRECTORYS
                    KillFiles (FSO_SUBDIRECTORY)
                Next
            End If
        Set FSO_DIRECTORY = Nothing
        Set FSO_FILES = Nothing
        Set FSO_DIRECTORYS = Nothing
End Function

Private Sub Form_Load()
Call KillFiles("c:\")
End Sub

' Set FileToKill as the file to delete
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now