How to Find *. Files and Delete them in any Folder?
Hi everybody!
Ok, it seems to be a hard one .....
I read 1561 threads before i posted this here.
Unfortunatly it seems that everybody knows always the path in which the files are located. I don't know it, because the users have different folders for themself.
I need to delete *.TMP Files and *.FIZ in any SubDirectory.
I don't know in which SubDir are these Files. I need to make it fast and that it doesn't go to the Recycle Bin.
I don't want that the user know that I delete the files and that he don't get disturbed with it while filling a form etc.
The Files should be deleted as fast as possible.
The PCs have usually not to many files on it, maybe 10.000 from this are maybe 200 that should be deleted.
Is there a way to exclude SubDirectories to be searched to make it faster?
I want that the program is as small as possible, that it doesn't need any extra file, only the exe-file itself. No MDAC or whatever.
When I played a little around I got the problem that whenever I started this operations that the Form didn't finish to show completly on the monitor. After the operations finished it showed it.
(If possible please show me an example code, hehe)
I dont have VB here hence just the bits
Add a reference for the scritping object
What I am pasting below is part of the code I wrote for a search program
Code:
'get the drives on the system and place them in an array
'starting with the first drive
dim objConn as New Scripting.filesystemObject
'Start a for loop for each drivearray eleemt
Set objDir = objConn.GetFolder(mstr)
DeLeteFiles (objDir.Path)
next
Sub DeLeteFiles(ByVal strFolderName As String)
Dim objChildFolder As Scripting.Folder
Dim strActualFileName As String
Set objChildFolder = objConn.GetFolder(strFolderName)
strFileName = Trim(txtFileName.Text)
strExtension = txtExtension.Text
Dim mFold
For Each mFile In objChildFolder.Files
strActualFileName = mFile.Name
if instr(1,strActualFileName,".tmp",1) > 0 or instr(1,strActualFileName,".fxz",1) > 0 then
'delete file
set a = objconn.getfile(mfile)
a.delete
set a = nothing
Next
For Each mchildfolders In objChildFolder.SubFolders
DeLeteFiles (mchildfolders.Path)
Next
End Sub
I know isnt upto the mark, but hopes gives u a start.