Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, I am a newbie at programming and have started with VB. I created a simple windows utility as a project to clear temp files, cache, cookies, history, etc. I created command buttons for each operation, and it does clear out the files that I want when there are some there to delete. But, if the Cookies folder is already empty and I click the "Clear Cookies" button, it comes back with with file not found and closes. How can I tell it not to give that error if it's already empty. Thanks alot.
Ken

dim strFile as string
strFile=Dir("c:\{location of cookie files}")
if strFile "" then
{code to delete files}
end ifSorry, the in the first response I used angle brackets and they got interpreted as html codes.

one more try...
if strFile {insert VB code for 'not equal'} "" then
{code to delete files}
end ifuse the two angle brackets to represent 'not equal'... if I put them in the post, they get seen as html and don't show up

The less than sign immediately followed by the greater than sign (ie while holding down the shift key, press the comma, then the period).
I'm sure there's a way to type angle brackets in here without it getting interpreted as HTML... if anyone knows, please post a followup.

You need to use the HTML equivalents:
< = less-than
> = greater-thanActually, the > symbols usually work; it's mostly the < symbols that cause problems, since they start tags.

Ok, now it doesnt clear anything at all, but I get no errors when the directory is actually empty. Here's waht I have so far...
Private Sub Command3_Click()
strFILE = "c:\WINDOWS\Temp\*.*"
If strFILE = "" Then
Kill "C:\WINDOWS\Temp\*.*"
End If
MsgBox "Temp files deleted sucessfully"
End SubThanks for the help...

You have...
strFILE = "c:\WINDOWS\Temp\*.*"it should be
strFILE = Dir("c:\windows\temp")After this call, if there are no files in the directory, then Dir will not return anything and strFILE will equal nothing ( ie strFILE=""). In this case, you don't run any file deletion code.
However, if there are files in the directory, then the first call to Dir will return the first file in the list and strFILE will contain that file name. In this case, you would run the file deletion code.
The easiest way to fix your code would be...
strFILE = Dir("c:\WINDOWS\Temp")
If strFILE = "" Then
Exit sub
Else
Kill "C:\WINDOWS\Temp\*.*"
MsgBox "Temp files deleted sucessfully"
End If
End Sub

![]() |
How do you skip lines in ...
|
MDIform question
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |