?
Solved

Remove a file

Posted on 2003-11-29
3
Medium Priority
?
154 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 120 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

777 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