• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 156
  • Last Modified:

Remove a file

Hi there people

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

Thanks
0
cofneverlivetotell
Asked:
cofneverlivetotell
1 Solution
 
Steve-HowesCommented:
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
 
aelatikCommented:
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now