• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 155
  • Last Modified:

Deleting files

Using a cmd button "delete" I want to place an (*) next to files that I will delete upon exiting my program.  After click on the "exit" command button all files marked with an asterik will be deleted and I will exit the program.  Can someone help me with this coding?
0
belk979
Asked:
belk979
  • 5
  • 4
  • 3
  • +3
1 Solution
 
belk979Author Commented:
Adjusted points to 200
0
 
DalinCommented:
Where is your file (in a list box, text box)?
How is your * added?

0
 
davishahnCommented:
If you know the filename, simply use the Kill command against each file you have an astrisk by.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
belk979Author Commented:
I need to know how to place the asterik "*" next to a file using a cmd button called "delete" (caption).  The files are located in a visual basic database.  Then I need to know how to delete all files marked with an asterik through an "exit" cmd button. (supply the code please.)
0
 
davishahnCommented:
Be more specific about where your files are. What do you mean by 'located in a visual basic database'?
How are they being listed by your program?
Need more info to help.
0
 
DalinCommented:
belk979,
Here is my idea. Sorry I did not have time to get to the code today. If not answered by Sunday, I will try.
Regards
Dalin

pull all the file name to a list box,
Add/remove the "*" in the front of the filename when the user click the filename.

In your exit cmd, loop through the items in the list,
If the first chr is "*" ( use the left function), then delete the file (use kill).
0
 
davishahnCommented:
Be more specific about where your files are. What do you mean by 'located in a visual basic database'?
How are they being listed by your program?
Need more info to help.
0
 
StapleheadCommented:
belk,

if you use a multi-select list box, then your users can ctrl-click to make multiple selections.  then, you can loop through the items in the list box, checking whether .Selected is true.  if it is, then delete the file.

larry
0
 
belk979Author Commented:
I created some files using visual basic. ("Add-in")
0
 
davishahnCommented:
Are you talking about tables in an Access database?
0
 
jjmartinCommented:
How are you showing this list of files?  Is it in a list box, database grid, what?  General questions get general answers, specific questions get specific answers.
0
 
belk979Author Commented:
In a database grid.
0
 
kamallCommented:
belk979,
Here is the answer:
This example will remove the selected filename from a list box (List1) when Command1 (caption= Delete) is clicked, and add it to another list box (List2) with an ' * ' to the left of the file name. Then when Command2 (caption=Exit) is clicked, a message box will apear showing you the files that will be deleted.
Just add 2 list boxes and to command buttons on your form and copy/paste the following code:

Private Sub Command1_Click()

List2.AddItem "*" & List1
List1.RemoveItem List1.ListIndex

End Sub

Private Sub Command2_Click()
   
    For x = 0 To List2.ListCount - 1
        MsgBox "File " & List2.List(x) & " will be deleted."
        'filename = Right$(List2.List(x), Len(List2.List(x)) - 1)
        'Kill filename
    Next
   
End Sub

Private Sub Form_Load()
    For x = 1 To 10
        List1.AddItem "File" & CStr(x) & ".xxx"
    Next
End Sub

To really delete the files, remove the ( ' ) from the two code lines in the Command2 procedure.

Hope that helps.
Regards
0
 
kamallCommented:
One last thing,
In order to delete the files, they must be valid filenames including the full path of the files.
0
 
belk979Author Commented:
Thank You!
0
 
kamallCommented:
You are welcome, belk979.
Have a nice day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 5
  • 4
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now