Link to home
Start Free TrialLog in
Avatar of Altaf Patni
Altaf PatniFlag for India

asked on

USING VB6.0 HOW TO DELETE %TEMP% FILES.?

Hi i wanted to delete files from %temp%  folder
Using VB6.0
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hello.
try using  
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.Deletefile ("%temp%\*")

and please feedback
Avatar of Altaf Patni

ASKER

@stergium
Tried ur suggestion,
"Run Time Error 53
File Not Found"
Thanks for reply..

@angelIII

I tried your suggestion,  
and i write some code as bellow. please check.
now some of files deleting but now every files and folders whatever in temp folder.
so how to delete every thing from %temp% folder..


Dim fso As Object
i = 0
ReDim filelist(0)

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFolder(GetTmpPath)

For Each f1 In f.Files

        i = i + 1
        ReDim Preserve filelist(i)
        Set filelist(i) = f1

        Kill f1
Next

Open in new window

you can do like this:

Dim fso As Object
i = 0
ReDim filelist(0)

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFolder(GetTmpPath)

For Each f1 In f.Files
   f1.Delete
Next

Open in new window

Files is deleting but
folder can't

i want to delete folders withing temp folder
ok Problem solved

Thanks  angelIII

If oFs.FolderExists(FolderSpec) Then
    Set oFolder = oFs.GetFolder(FolderSpec)
    On Error Resume Next
    For Each oFolder In oFolder.SubFolders
        oFolder.Delete True 'setting force to true
                        
    Next
    DeleteAllFiles = oFolder.SubFolders.Count = 0
End If

Open in new window