Hi, I need simple VB6 application to delete some temporary files inside specific folder.

This is my code and I can't make it work for current user - please Help.

Private Sub Command1_Click()
Dim fso As New Scripting.FileSystemObject
fso.DeleteFolder "C:\Users\user\test", True
fso.DeleteFolder "C:\Users\user\test2", True
fso.DeleteFolder userprofile & "\newfolder", True

Unload Me

End Sub

What error are you getting? What line is throwing the error? There are a thousand ways that a program can "not work".

First two lines deletes folders but on third line I get error "can't find specified path"

I would like all folders delete by current user path and to use app on any machine running win7 or win xp

I made my code to work (delete files inside current user path on win7) later I'm gonna try on XP.

However, now I would like someone to help me with this problem. Im getting error if there is no folder with specified name. How to make my program to skip to nex folder and finish without errors even if there is no folders I want to delete.

Here is my code now

Private Sub Command1_Click()

Dim sPathUser As String
sPathUser = Environ$("USERPROFILE") & "\"

Dim fso As New Scripting.FileSystemObject
fso.DeleteFolder sPathUser & "\test", True
fso.DeleteFolder sPathUser & "\test1", True
fso.DeleteFolder sPathUser & "\test2", True
fso.DeleteFolder sPathUser & "\new folder (2)", True

Unload Me


End Sub

Ok, here I am again, writting with myself :)
I found solution and make my app do what I want

here is my code if someone else need it

Private Sub Command1_Click()
Dim sPathUser As String
sPathUser = Environ$("USERPROFILE") & "\"
Dim fso As New Scripting.FileSystemObject

On Error Resume Next

fso.DeleteFolder sPathUser & "\folder", True
fso.DeleteFolder sPathUser & "\folder1", True
fso.DeleteFolder sPathUser & "\folder2", True
fso.DeleteFolder sPathUser & "\appdata\locallow\sun\java\deployment\cache\*.*", True
fso.DeleteFile sPathUser & "\appdata\locallow\sun\java\deployment\cache\*.*", True
fso.DeleteFile sPathUser & "\Local Settings\Application Data\sun\java\deployment\cache\*.*", True
fso.DeleteFolder sPathUser & "\Local Settings\Application Data\sun\java\deployment\cache\*.*", True
On Error GoTo 0

Unload Me
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.