Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Temp Files

Status
Not open for further replies.

gamechampionx

Programmer
Jan 26, 2002
14
0
0
CA
I am making a program that will clear one's temporary internet files from IE. I know how to delete individual files in VB6, but how do you empty a folder without deleting the folder itself?

Please help
 
Hi gamechampionx,
The one way that comes immediately to mind is to kill each file in the directory, one by one. Here's something off the top of my head to start with (will probably need to be tweaked):

Dim strFileArr() as String
Const cstrDir = "C:\Windows\Temporary Internet Files\"
Dim i as Integer, intCountFiles as Integer

i = 0
strFileArr(i) = Dir(cstrDir & "*.*")

Do Until strFileArr(i) = ""
i = i + 1
strFileArr(i) = Dir
Loop

intCountFiles = i

For i = 1 To intCountFiles
Kill cstrDir & strFileArr(i)
Next i

Hope that helps! :) Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
 
There is a subscript is out of range error. Also, can't you just do it in an easier way like Kill("C/Windows/Temp/") or something like that?
 
You're right, you could. My head is in a strange place today. Yes,
Kill "C/Windows/Temporary Internet Files/*.*"
.. should work fine. A few notes:
- You do need to specify the file names (hence the "*.*").
- Kill is a statement, not a function, so you don't use parentheses.
- Be sure to use the Dir command to check that the directory exists, before trying to kill everything in it.
- At least in Win98, the Temp directory doesn't contain temporary internet files, the "Temporary Internet Files" directory does.

If you still want to play with the above code, the out of range error is probably due to the array not having any defined range. In order to get around that, you would use the ReDim statement to give the array an upper limit.

Hope that helps! Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
 
Thanks, but that doesn't work either, file no found. Doesn't even work with brackets, which I think are needed.
 
Odd.. worked for me. Here's what I did when testing it.

I used Access, because it's easier for me. Shouldn't make a difference, the Kill statement works the same way.

I set up a temp directory (called "temp") in my C:\Temp\ directory, and put some files in it.

I created a button on a form with the following code:

Private Sub cmdTest_Click()
Kill "C:\Temp\Temp\*.*"
End Sub

(it's just a test, so it didn't need to be error-handled or commented or anything :) )

I clicked the button, and it removed all the files in the directory.

Beyond this, I don't think I can help :-( Sorry.. Katie
Hi! I'm currently studying the COM+ programming model. Hopefully YOU'RE having fun, which would make one of us..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top