folders creation from listbox

P

Pascal

Hi everybody

I try to create folders from a list stored in a listbox. It works a
"little"but, i would like to create these folders only if they don't exist.
here is the code i use :

Private Sub btnCreateFolders_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCreateFolders.Click
Try
Dim i As Integer
For i = 0 To lstbEleves.Items.Count - 1
' Open the path
Dim D As DirectoryInfo
D = New DirectoryInfo(ParentFolder)
Dim SD As DirectoryInfo
SD = New DirectoryInfo(lstbEleves.Items.Item(i))
' Vérify existence of directory
If D.Exists Then
If SD.Exists Then
'Do nothing because the subdirectory already exists in the parent folder
Else
'Create the sub-directory with the name from the listbox
D.CreateSubdirectory(lstbEleves.Items.Item(i).ToString)
End If
End If
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, Me.Text)
End Try
End Sub
I don't why it doesn't work.
If i don't put any if the folders are created..... but there no test!
can you help
thanks
pascal
http://www.scalpa.info
 
G

GS

what about the use of DirectoryInfo.GetDirectories and compare if any items
in your list is in existence?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top