K
Kimera.Kimera
I'm trying to write a program in VB.net 2003 that basically deletes all
files, folders, sub-folders and sub-sub folders (etc).
The program is simply for deleting the Windows/Temp folder contents,
removing all the files/folders inside it.
The problem i am having is that i can only delete files in the
Windows/Temp folder, and i can't delete folders if they contain files,
i know that you can't do this.
But i don't know how i would go about deleting the files inside
folders/sub folders (and even deeper into a path)
I have looked and looked all over the place and i've not been able to
find a solution.
Here is my code so far for deleting files:
Imports:
Imports System.IO
Variables:
'Used to control Directory for deleting files
Public Directory As String
Dim Collection As System.Collections.IEnumerator
Collection = Directory.GetEnumerator
While Collection.MoveNext
Try
'Sets file to read-only, to make it delete without
prompt/error
System.IO.File.SetAttributes(Collection.Current,
IO.FileAttributes.Normal)
'Reads in sub dir and kills their files
Kill(Collection.Current)
Catch
'Set trigger that a file failed to delete
DeletionFail = True
'Add erroneous files to list variable, later to be
displayed
NotDeleted &= ("Unable to delete file : " &
Collection.Current & vbCrLf)
End Try
End While
Any other solution is welcome that will simply delete all
files/folders/sub dir's inside a spesfied directory (IE,
C:\WINDOWS\Temp)
files, folders, sub-folders and sub-sub folders (etc).
The program is simply for deleting the Windows/Temp folder contents,
removing all the files/folders inside it.
The problem i am having is that i can only delete files in the
Windows/Temp folder, and i can't delete folders if they contain files,
i know that you can't do this.
But i don't know how i would go about deleting the files inside
folders/sub folders (and even deeper into a path)
I have looked and looked all over the place and i've not been able to
find a solution.
Here is my code so far for deleting files:
Imports:
Imports System.IO
Variables:
'Used to control Directory for deleting files
Public Directory As String
Dim Collection As System.Collections.IEnumerator
Collection = Directory.GetEnumerator
While Collection.MoveNext
Try
'Sets file to read-only, to make it delete without
prompt/error
System.IO.File.SetAttributes(Collection.Current,
IO.FileAttributes.Normal)
'Reads in sub dir and kills their files
Kill(Collection.Current)
Catch
'Set trigger that a file failed to delete
DeletionFail = True
'Add erroneous files to list variable, later to be
displayed
NotDeleted &= ("Unable to delete file : " &
Collection.Current & vbCrLf)
End Try
End While
Any other solution is welcome that will simply delete all
files/folders/sub dir's inside a spesfied directory (IE,
C:\WINDOWS\Temp)