Solved

Delete Only specific  Cookies from Cookie Folder vb6

Posted on 2004-09-10
5
378 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

813 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

11 Experts available now in Live!

Get 1:1 Help Now