QuestionHelpHow to delete files in Visual Basic with a CheckedListBox1

Posts 1–15 of 20 · Page 1 of 2
How to delete files in Visual Basic with a CheckedListBox1
Hello, I was wondering how I can make my form look for files in a directory (Let's say.. Combat Arms or something) And it'll look for.. let's say text files.. How can I have that text file (Or name I guess I can say) Go into the CheckedListBox1 (Example inside of CheckedListBox1 it says the text name and the directory:"C:\Game\Combat Arms\Filename.txt or .exe or .jpg etc. etc.") and I can check it and click the "Delete" button and it'll delete the file from the directory and it'll clear from the CheckedListBox1.. If you can help me I'll be more then thankful and more then just happy(: (Sorry if this was hard to understand.. I'm just very tired and in a hurry)
I wouldn't know how to do it with a ListBox, but with a ListView its a bit easier

Code:
For Each Item as ListViewItem in ListView1.CheckedIndicies
IO.File.Delete(Item.Text)
Next
He wants to know everything from "finding" the files, to adding them to the checkbox, to removing items from it. It's not 1 question, its a "please give me code which does ___ ___ & ____".

-And has 'no thoughts on how' to accomplish this -- he wants copy-pastable code.
Something Nobby I Made:


Design:
@Jorndel thanks for the post mate.. But question.. How can I have certain files to show? (Like let's say I was making a Combat Arms cleaner.. How can I make it just show *.txt files or.. EndingBanner.exe etc.)
Quote Originally Posted by cruz967 View Post
@Jorndel thanks for the post mate.. But question.. How can I have certain files to show? (Like let's say I was making a Combat Arms cleaner.. How can I make it just show *.txt files or.. EndingBanner.exe etc.)
at the end here:

If there is an error, 'I' will not be increased, and an infinite loop will happen because the same index will be used in the next iteration: and fail, and loop. ?

Add 'Finally' block and move "I++" to that? or initialize 'I' to -1 and move "I++" before the function call. ?

Even if it didn't loop forever,on error 'I' won't be incremented, so 'I' won't correctly correspond to the next item in the list.
Quote Originally Posted by abuckau907 View Post
If there is an error, 'I' will not be increased, and an infinite loop will happen because the same index will be used in the next iteration:
The For Each will still be done, and ignore the item that have the problem.
-But I see your point about the "never-ending-problem-file"

Well, this is such things I never code so

+ Quit
Yep, not sure what I was thinking: it won't infinite loop, but 'I' is still not incremented as it should.
Quote Originally Posted by abuckau907 View Post
Yep, not sure what I was thinking: it won't infinite loop, but 'I' is still not incremented as it should.
Tip:
Add the I += 1 BEFORE the File Delete Operation

X,x
(Was thinking C# i++ )
Quote Originally Posted by Jorndel View Post


Tip:
Add the I += 1 BEFORE the File Delete Operation

X,x
(Was thinking C# i++ )
And initialize I to -1, or you'll skip the first item in the list : p


....there are still 1 based "array function" ...mostly dealing with Strings.
Quote Originally Posted by abuckau907 View Post
And initialize I to -1, or you'll skip the first item in the list : p


....there are still 1 based "array function" ...mostly dealing with Strings.
I've never ever in my life heard of arrays starting with an index of 1
I forget if .SelectedItems () is 0 or 1 based (intellisense will tell you) : if it's 0 based, and you move I++ before the function call, you must initialize I to -1 or you'll skip item (0). If it's 1 based, initialize it to 0.
Quote Originally Posted by abuckau907 View Post
I forget if .SelectedItems () is 0 or 1 based (intellisense will tell you) : if it's 0 based, and you move I++ before the function call, you must initialize I to -1 or you'll skip item (0). If it's 1 based, initialize it to 0.
As it's an Array Based Function: 0
I'm drawing a blank...I'll post when I can think of one. I think it's weird too.

-Something to do with indexed properties, some start at 1.

Edit:

http://msdn.microsoft.com/en-us/library/ms233801.aspx

Only example it gives is the Mid function, which has been replaced by String.SubString() : I can't think of any others at the moment so I guess it's a dumb argument. I agree, it's silly. I think I've only seen it with functions that return string/ array of strings.


^^It specifically says 0-based because sometimes it's not.

^^That's vb for you : still some quirks, backwards compatibility I guess. I tend to check intellisense when using strings functions, I vaguely remember a few more doing the same thing.
Posts 1–15 of 20 · Page 1 of 2

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us