Results 1 to 6 of 6

Thread: [Help] Find & Delete File

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    17

    Arrow [Help] Find & Delete File

    Hello All,
    I am working on a private custom application for a friend, and the newest version I have, has some features in it that stop him from using it when I need him to, and the older versions don't, so what I need, is code to search for all other *.exe's with a certain name on his HD, and remove them, so he will only have the most recent version.

    I know how to delete a file from the HD manually, with the Kill Switch, but I don't know how to make it find a file, and delete whichever one's it's found, i remember seeing it somewhere before but I cannot remember where..

  2. #2
    Member
    Join Date
    Mar 2008
    Location
    Michigan
    Posts
    32

    Re: [Help] Find & Delete File

    If you know what folder the files are in and the names of the files you want to delete then you can use the "if dir" to find out if the file exists and if it does then use "kill" to delete the file

    Code:
    If Dir(App.Path & "\Filetodelete.txt", vbDirectory) = "" Then
        'Copy files code goes here cause file doesnt exist
    Else
        Kill (App.Path & "\Filetodelete.txt")
        'Copy files code goes here cause file existed and we got rid of it
    End if

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: [Help] Find & Delete File

    you can use the searchtreeforfile API to locate file in other directories
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [Help] Find & Delete File

    Welcome to the forums sirhiro.
    Quote Originally Posted by westconn1
    you can use the searchtreeforfile API to locate file in other directories
    This is my personal favorite. Here is the declare
    Code:
    Private Declare Function SearchTreeForFile Lib "imagehlp" _
    (ByVal RootPath As String, ByVal InputPathName As String, _
    ByVal OutputPathBuffer As String) As Long
    
    Private Const MAX_PATH = 260

  5. #5
    New Member
    Join Date
    Apr 2008
    Posts
    15

    Smile Re: [Help] Find & Delete File

    When you say "find" them do you really mean that you need to search the complete hard drive or do you know what directory (Folder) they're in and you need code for selecting the correct files?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Apr 2008
    Posts
    17

    Re: [Help] Find & Delete File

    "If you know what folder the files are in and the names of the files you want to delete then you can use the "if dir" to find out if the file exists and if it does then use "kill" to delete the file" ~Tarasque
    I do not know what folder the files are in, but I do know the names of them, that is why I need it to search for the files names to find what folder there in..

    "Welcome to the forums sirhiro." ~Hack
    Thanks

    Hack, I found this website relating to the decleration you gave me,
    http://vbnet.mvps.org/index.html?cod...htree4file.htm

    Seems to be just what I need, because it can scan for the file name on drive letter C:\ then, it can hold the path name if it finds it, once stored I can send the kill command to that saved path, so it should work out nicely..
    Thanks alot, for that.

    "When you say "find" them do you really mean that you need to search the complete hard drive or do you know what directory (Folder) they're in and you need code for selecting the correct files?" ~VB-Want-To-Be
    Yes, I need to search the complete HD, because I know the name, but not the folder, because he moved the older versions to backup folders.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width