[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..
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
Re: [Help] Find & Delete File
you can use the searchtreeforfile API to locate file in other directories
Re: [Help] Find & Delete File
Welcome to the forums sirhiro. :wave:
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
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?
:rolleyes:
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.