We have a process around here which at the end of each week ends up with a lot of trash files. The folders which these files are in are highly restricted due to our ISO 9001 compliance requirements. I have to use a special login account on the Novell network to have access to erase anything in this area. Ok, that's not a problem. But at the end of each week I end up having to manually go through about 100 folders or do a search of some kind for all this trash which is in the form of *.tmp, *.bak, *.log, *.dwl* files. I want to cleanup these folders on a routine basis by getting rid of these files. Here is what I have come up with so far, but again, my limited experience tells me I may be mixing VB6 with VB.NET code again. Can anyone look this over and tell me if it's safe and sane code and how I may improve on it. I am open to other methods for certain.
There are about 100 or so folders under "path_on_novell_server" so I'd rather use something that will recurse through all of the folders below it instead of writing 100's of blocks of code for each one. The beauty of the structure under this is that each folder is numerically sequence i.e /10000, /11000, /12000....etc. There are a few exceptions inside of it, but I can handle those and I think I can write the code which will loop through all these. But again, I was thinking that with VB.NET there is a way to recurse through the whole tree in a shorter method. Oh, and one more thing. The files with the *.dwl* extension mask are going to be hidden files. So I have to come up with a way of handling that similar to what I do with a DOS command window line (del /a:h *.dwl*) and there may well be filenames with spaces in them. In addition, there are always instances of users leaving their application which created these *.dwl* files and they could very well be still opened. In that case, I do not want to erase them. This is why using an old batch file I tried is not working too well and I want to port the process to VB.NET.
There are about 100 or so folders under "path_on_novell_server" so I'd rather use something that will recurse through all of the folders below it instead of writing 100's of blocks of code for each one. The beauty of the structure under this is that each folder is numerically sequence i.e /10000, /11000, /12000....etc. There are a few exceptions inside of it, but I can handle those and I think I can write the code which will loop through all these. But again, I was thinking that with VB.NET there is a way to recurse through the whole tree in a shorter method. Oh, and one more thing. The files with the *.dwl* extension mask are going to be hidden files. So I have to come up with a way of handling that similar to what I do with a DOS command window line (del /a:h *.dwl*) and there may well be filenames with spaces in them. In addition, there are always instances of users leaving their application which created these *.dwl* files and they could very well be still opened. In that case, I do not want to erase them. This is why using an old batch file I tried is not working too well and I want to port the process to VB.NET.
Code:
Imports System.IO
Module Module1
Sub Main()
Dim file_name As String
Dim files As Collection
Dim i As Integer
Dim dir_name As String = "path_on_novell_server\Vault\10000" ' <<-- This is where I'd have to change the search folder's name each time
' Get a list of files it contains.
files = New Collection
file_name = Dir$(dir_name & "\*.bak*")
Do While Len(file_name) > 0
If (file_name <> "..") And (file_name <> ".") Then
files.Add(dir_name & "\" & file_name)
End If
file_name = Dir$()
Loop
' Delete the files.
For i = 1 To files.Count
File.Delete(files(i))
Next i
End Sub
End Module