Hack Forums
[.NET] VB.NET = Click button that deletes files - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] VB.NET = Click button that deletes files (/showthread.php?tid=5633201)



VB.NET = Click button that deletes files - Formula 1 - May 27, 2017

I want to make a program that deletes all the files in a desktop folder...


* - VmX5 - May 27, 2017

Well get a list of files in the desktop directory and delete each file. It's pretty self explanatory...


* - Xogg - May 27, 2017

Look into system.io and use loops.


* - Dеceived - May 27, 2017

Use system.io and use a for loop to delete the amount of things in the selected folder


* - Cairns - May 27, 2017

He's obviously looking for someone just to paste him the exact code to do it with no interest of learning.


* - Joz0 - May 27, 2017

System.io, learn it yourself otherwise you''re not progressing


* - Scaliber - May 27, 2017

I don't know if this is exactly what you want but:
PHP Code

<?php 
Sub DeleteFilesFromFolder
(Folder As String)
    If 
Directory.Exists(Folder) Then
        
For Each _file As String In Directory.GetFiles(Folder)
            
File.Delete(_file)
        
Next
        
For Each _folder As String In Directory.GetDirectories(Folder)

            
DeleteFilesFromFolder(_folder)
        
Next

    End 
If

End Sub

'Somewhere you call

DeleteFilesFromFolder("C:\New Folder") 

Source: https://stackoverflow.com/questions/25221181/how-to-delete-all-the-files-in-a-folder-including-the-files-in-the-sub-folders-w


* - Ninja - May 27, 2017

(May 27, 2017 03:52 PM)Scaliber Wrote:  I don't know if this is exactly what you want but:
PHP Code

<?php 
Sub DeleteFilesFromFolder
(Folder As String)
    If 
Directory.Exists(Folder) Then
        
For Each _file As String In Directory.GetFiles(Folder)
            
File.Delete(_file)
        
Next
        
For Each _folder As String In Directory.GetDirectories(Folder)

            
DeleteFilesFromFolder(_folder)
        
Next

    End 
If

End Sub

'Somewhere you call

DeleteFilesFromFolder("C:\New Folder") 

Source: https://stackoverflow.com/questions/25221181/how-to-delete-all-the-files-in-a-folder-including-the-files-in-the-sub-folders-w

You can just delete folders instead of deleting all files from folders.