Solved

Delete Only specific  Cookies from Cookie Folder vb6

Posted on 2004-09-10
5
377 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
ID: 12030762
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
ID: 12030837
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
ID: 12030858
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
ID: 12031242
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
ID: 12043620
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

863 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

23 Experts available now in Live!

Get 1:1 Help Now