Solved

Delete Only specific  Cookies from Cookie Folder vb6

Posted on 2004-09-10
5
375 Views
Last Modified: 2010-05-02
Hello Experts

I am trying to delete only specific cookies in my cookie folder

for example if i only want to delete   (   google.co[1].txt   ) in the cookie folder

Here is some more in my cookie folder

D:\Documents and Settings\Win2000\Cookies\win2000@www.cnn[1].txt
D:\Documents and Settings\Win2000\Cookies\win2000@google.co[1].txt
D:\Documents and Settings\Win2000\Cookies\win2000@experts-exchange[1].txt

I am using code in vb6

to display the cookies  folder in a listview1 box  i use the code.
'--------------------------------------------------------------------------------------
Private Sub Command1_Click()

   ListView1.ListItems.Clear
   
   Set FD = fso.GetFolder(Cookies)
    Set FLS = FD.Files
   
    For Each F In FLS
    ListView1.ListItems.Add , , "Item " & F.path  ' F.path contains the full path and name of cookie
    Next

End Sub
'--------------------------------------------------------------------------------------
and to select a  cookie in listview1  i am using
'--------------------------------------------------------------------------------------
Private Sub Command2_Click()

Dim intindex
 With ListView1
   For intindex = .ListItems.Count To 1 Step -1
      If .ListItems(intindex).Checked Then
          .ListItems.Remove intindex
      End If
   Next
 End With

End Sub

in the above code Command2_Click() how can i insert some code
to delete the actual cookie file selected  , for example if  ( google.co[1].txt  )  
is selected then i want to delete this cookie from the cookie folder

thanks experts






0
Comment
Question by:Jimmyx1000
  • 3
5 Comments
 
LVL 16

Expert Comment

by:JohnBPrice
Comment Utility
If you use the Microsoft Scripting runtime, you can use

Dim fs As New FileSystemObject
fs.DeleteFile FileName

Where FileName is the name of the file to delete.
0
 
LVL 14

Expert Comment

by:JohnK813
Comment Utility
Give this a try.  Don't know if it's 100% accurate, though, so you'll have to test.

Dim cookie_name as String

...

      If .ListItems(intindex).Checked Then
          cookie_name = .ItemData(intindex)
          fso.DeleteFile cookie_name
          .ListItems.Remove intindex
      End If
0
 
LVL 14

Accepted Solution

by:
JohnK813 earned 500 total points
Comment Utility
Hmmm... looks like you add the word "Item " to the front of the cookie path/name.  So, you'll have to parse that out.

          cookie_name = .ItemData(intindex)
          cookie_name = Replace(cookie_name,"Item ","")
          fso.DeleteFile cookie_name
          .ListItems.Remove intindex
0
 

Author Comment

by:Jimmyx1000
Comment Utility
Hello Experts

The command   " fso.DeleteFile cookie_name "
does not allow deleteing of the index.dat file in the cookie folder ,
 

how can i have the listview1 box stop from showing the line in listvew so it cant be checked
i would need to omit the listview  item which contain the words index.dat

i guess this would be in this code  

Private Sub Command1_Click()

   ListView1.ListItems.Clear
   
   Set FD = fso.GetFolder(Cookies)
    Set FLS = FD.Files
   
    For Each F In FLS
    ListView1.ListItems.Add , , "Item " & F.path  ' F.path contains the full path and name of cookie
    Next

End Sub
0
 
LVL 14

Expert Comment

by:JohnK813
Comment Utility
You can do one of the following things:

'only add to listbox if filename contains ".txt"
    For Each F In FLS
      If Instr(F.path,".txt") then
         ListView1.ListItems.Add , , "Item " & F.path  ' F.path contains the full path and name of cookie
      End If
    Next


or:


'only add to listbox if filename does not contain "index.dat"
    For Each F In FLS
      If Not Instr(F.path,"index.dat") then
         ListView1.ListItems.Add , , "Item " & F.path  ' F.path contains the full path and name of cookie
      End If
    Next
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now