Solved

Remove a file

Posted on 2003-11-29
3
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Expert Comment

by:Steve-Howes
ID: 9846326
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
ID: 9911803
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

689 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