How do I delete all files in a folder?
-
Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)
-
Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)
Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.
SLRGrant wrote:
PS: How would I display the results in a textbox of what is in that folder before i delete it?
Same way, show them what Directory.GetFiles returns, you can make that array of strings the datasource of a list control.
Christian Graus - C++ MVP
-
Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)
SLRGrant wrote:
How would I display the results in a textbox of what is in that folder
http://www.codeproject.com/dotnet/folderwatcher.asp[^]
Janani
-
Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.
SLRGrant wrote:
PS: How would I display the results in a textbox of what is in that folder before i delete it?
Same way, show them what Directory.GetFiles returns, you can make that array of strings the datasource of a list control.
Christian Graus - C++ MVP
Christian Graus wrote:
Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.
Does that mean that I couldnt create a program that could clean the computer like CCleaner for example? :sigh:
-
Christian Graus wrote:
Sadly, the answer is 'one at a time'. Directory.GetFiles will tell you the files, then you delete them one at a time.
Does that mean that I couldnt create a program that could clean the computer like CCleaner for example? :sigh:
No, of course not. Why would it mean that ?
Christian Graus - C++ MVP
-
Hey everyone, well the title says it all. How do I delete all files in a folder? e.g. TEMP folder PS: How would I display the results in a textbox of what is in that folder before i delete it? ( then i click a button to comfirm deletion)
If you want to delete all the files in a folder, the best approach would be to use a for/next statement. use a listbox for your display as oppose to a textbox. Dim di as new system.io.directoryinfo = "your directory" '(1) Dim fi as system.io.fileinfo for each fi in di.getfiles'(5) '(4) listbox1.items.add(fi.filename) fi.delete '(2) (3) '(4) next Note: (1) You could use a folder browser dialog to establish the folder or for the user to establish the folder (2) When testing, have a test folder filled with copies files or something. (3) If you wished to display first then give the option of deleting, you could put a similar for/next statement under a button's click action or something and only have delete option. (4) You could have an if statement here for certain paremeters (5) In the brackets after getfiles, you can specify file type
Posted by The ANZAC
-
If you want to delete all the files in a folder, the best approach would be to use a for/next statement. use a listbox for your display as oppose to a textbox. Dim di as new system.io.directoryinfo = "your directory" '(1) Dim fi as system.io.fileinfo for each fi in di.getfiles'(5) '(4) listbox1.items.add(fi.filename) fi.delete '(2) (3) '(4) next Note: (1) You could use a folder browser dialog to establish the folder or for the user to establish the folder (2) When testing, have a test folder filled with copies files or something. (3) If you wished to display first then give the option of deleting, you could put a similar for/next statement under a button's click action or something and only have delete option. (4) You could have an if statement here for certain paremeters (5) In the brackets after getfiles, you can specify file type
Posted by The ANZAC
Cool, well thanks guys for all your help, I will fiddle about with the code and see what the result is ;P