Murray Brown
asked on
VB.net Delete all files from a folder
Hi
I am using the following code to delete all the files from a folder but it doesn't seem to work
Dim MYDOC_DIR As String = Environ("userprofile") & "\My Documents"
Dim TEMP_IMAGES As String = MYDOC_DIR & "\Temp_Images"
Dim myDirInfo As System.IO.DirectoryInfo = New DirectoryInfo(TEMP_IMAGES)
For Each file As FileInfo In myDirInfo.GetFiles()
file.Delete()
Next
For Each dir As DirectoryInfo In myDirInfo.GetDirectories()
dir.Delete(True)
Next
I am using the following code to delete all the files from a folder but it doesn't seem to work
Dim MYDOC_DIR As String = Environ("userprofile") & "\My Documents"
Dim TEMP_IMAGES As String = MYDOC_DIR & "\Temp_Images"
Dim myDirInfo As System.IO.DirectoryInfo = New DirectoryInfo(TEMP_IMAGES)
For Each file As FileInfo In myDirInfo.GetFiles()
file.Delete()
Next
For Each dir As DirectoryInfo In myDirInfo.GetDirectories()
dir.Delete(True)
Next
So what does happen? Do you get an exception thrown, or something else?
sounds like you don't have permission to delete the user profile
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much James. That did the trick. I have used the previous code all over my apps so glad that you short circuited future user errors.
Murray
Murray