Solved

Remove a file

Posted on 2003-11-29
3
152 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Basic Excel Formatting error 4 141
bit defender blocks good applications 2 106
Copy a row 12 69
VB script to continue despite error 2 54
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

733 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