hi
i would like to understand why and how this code is working. i know it works but would like to understand why:
so lets say i want to delete all files and sub folder of: C:\music
my folder looks like this:
music has 3 sub folders: hip hop, rock, country. each folder has 3 songs in it.
music it self also has 3 files besides the 3 subfolders.
now lets starts the loop:
DeleteFolder("C:\music")
what will happen?
'File 1
[/CODE]
'File 2
[/CODE]
it seems to me like by calling again the event we are NOT exiting the run and we are running the event myltiple time at the same time with different values (folder As String) is this correct?
i hope i was clear
i would like to understand why and how this code is working. i know it works but would like to understand why:
B4X:
Sub DeleteFolder (folder As String)
For Each f As String In File.ListFiles(folder)
If File.IsDirectory(folder, f) Then
DeleteFolder(File.Combine(folder, f))
End If
File.Delete(folder, f)
Next
End Sub
so lets say i want to delete all files and sub folder of: C:\music
my folder looks like this:
music has 3 sub folders: hip hop, rock, country. each folder has 3 songs in it.
music it self also has 3 files besides the 3 subfolders.
now lets starts the loop:
DeleteFolder("C:\music")
what will happen?
'File 1
B4X:
[CODE=b4x]Sub DeleteFolder (folder As String)
For Each f As String In File.ListFiles(folder) 'so folder is here on first start c:\music
If File.IsDirectory(folder, f) Then 'first file is not a folder so it will be skipped and delete the file
DeleteFolder(File.Combine(folder, f))
End If
File.Delete(folder, f) 'here is file 1 deleted
Next
End Sub
'File 2
B4X:
[CODE=b4x]Sub DeleteFolder (folder As String)
For Each f As String In File.ListFiles(folder) 'the folder name is still the same c:\music
If File.IsDirectory(folder, f) Then 'second file IS A FOLDER it is HIP HOP so now the condition is true and we will jump to the next line
DeleteFolder(File.Combine(folder, f)) ' here we start the method again and EXIT the existing run. we also update Folder name [(folder As String)] to the new folder
End If
File.Delete(folder, f) ' in the second run this LINE will not be called, because we have exit the loop, so when will this line called and delete the folder with the OLD folder name??
Next
End Sub
it seems to me like by calling again the event we are NOT exiting the run and we are running the event myltiple time at the same time with different values (folder As String) is this correct?
i hope i was clear