0

I am working in a tool that commit dcm files in multiple folders . Now i am trying to add a checkbox that manage the exact folder you want to commit so if i want to include files in subfolders i will press the check box if not i will leave unchecked . Now the problem is that i can not exclude the subfolders from being loaded even when the checkbox is unchecked

this the function i am working on :

Sub CheckBox1CheckedChanged()
If IO.Directory.GetDirectories(CWPathTB.Text).Length > 1  AndAlso checkBox1.Checked= False Then
'how to clear the subfolders and make them unseen in this condition 
    LoadChangedFiles2()
 Else
FilesGrid.Rows.Clear()
LoadChangedFiles()
End If
 End Sub

your help is highly appreciated :)

......

the function :

Public Sub LoadChangedFiles2()
    'loading all the modified , added and removed files only in the top directory into files grid
    Dim b,j As Integer
    Dim PushokClientt As New PushOkSvn.SVNClient
    Dim ModiFiles As New ArrayList
    Dim ConflFiles As New ArrayList

    FileLocalPos1.Clear()
    FileList1.Clear()
    ModFileArr1.Clear()
    ConfFileArr1.Clear()
    AddedFileArr1.Clear()
    RemovedFileArr1.Clear()

    Dim LocDir As New IO.DirectoryInfo(CWPath)
    Dim ignorSharcc As Boolean = False

    Dim FInfoLoc() As IO.FileInfo = LocDir.GetFiles("*.dcm",IO.SearchOption.TopDirectoryOnly)
    Dim FileInfoLoc As IO.FileInfo

    For Each FileInfoLoc In FInfoLoc
        If FileInfoLoc.FullName.Substring(FileInfoLoc.FullName.Length - 4 , 4 ) = ".dcm" Then

            If Not FileInfoLoc.FullName.Contains("sharcc") Then
                Dim TempFileName() As String
                Dim FileName As String
                TempFileName = FileInfoLoc.FullName.Split("\")
                FileName = TempFileName(TempFileName.Length - 1)
                If Not FileLocalPos1.Contains(FileName)Then
                    FileLocalPos1.Add(FileInfoLoc.FullName , FileName )
                    FileList1.Add(FileName)
                Else 
                    MsgBox("In Pfad exist two .dcm files with the same name . Choose an exacter Pfad . ")
                    Exit Sub

                End If
            Else
                ignorSharcc = True
            End If
        End If
    Next
       If ignorSharcc = True Then
        MsgBox("Sharcc folder has been ignored.")
    End If

    Call checkStatus2(CWPath, PushokClientt)

    j=0
    For b = 0 To ModFileArr1.Count - 1
        Dim Filerow1 As String() = {False, ModFileArr1.Item(b).ToString, "Modified", FileLocalPos1.Item(ModFileArr1.Item(b).ToString)}
        DcmComm.FilesGrid.Rows.Add(Filerow1)
        j = j + 1
    Next

    For b = 0 To ConfFileArr.Count - 1
        Dim Filerow1 As String() = {False, ConfFileArr1.Item(b).ToString, "Conflicted", FileLocalPos1.Item(ConfFileArr1.Item(b).ToString)}
        DcmComm.FilesGrid.Rows.Add(Filerow1)
        DcmComm.FilesGrid.Rows(j).DefaultCellStyle.BackColor = Color.DarkGray
        DcmComm.FilesGrid.Rows(j).ReadOnly = True
        MsgBox(ConfFileArr1.Item(b).ToString & " is out of date! Please update first! ")
        j = j + 1
    Next

    For b = 0 To AddedFileArr1.Count - 1
        Dim row1 As String() = {False, AddedFileArr1.Item(b).ToString, "Added", FileLocalPos1.Item(AddedFileArr1.Item(b).ToString)}
        DcmComm.FilesGrid.Rows.Add(row1)
        j = j + 1
    Next

    For b = 0 To RemovedFileArr1.Count - 1
        Dim row1 As String() = {False, RemovedFileArr1.Item(b).ToString, "Removed", ""}
        DcmComm.FilesGrid.Rows.Add(row1)
        j = j + 1
    Next
    Exit Sub
End Sub

..........................

and the error is appearing in this line :

        Dim Filerow1 As String() = {False, ModFileArr1.Item(b).ToString, "Modified", FileLocalPos1.Item(ModFileArr1.Item(b).ToString)}
A.Wad
  • 29
  • 3
  • 9

1 Answers1

0

You need to use the GetDirectories overload with the search options parameter:

IO.Directory.GetDirectories(CWPath, "*.*", IO.SearchOption.TopDirectoryOnly)
competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • Hello Thank you very much .. I have done that and when i came to run it and browsed the folder that contains subfolders without have the checkbox checked .. i had this msg ( Argument 'Index' is not a valid value.) and i have no idea why i got it .. i followed the code and all the values are 100 % right ,, any idea why i got this error ? – A.Wad Aug 03 '12 at 11:34
  • Can you update your question with your current code and show where you are receiving the error? – competent_tech Aug 03 '12 at 15:34
  • please anyone here can you help :( – A.Wad Aug 08 '12 at 16:24
  • Please update the question to show all of your code related to the question and indicate which line the error occurs on along with the exact error message you are receiving, please. Until we get that info, it is hard to tell what is going on. – competent_tech Aug 08 '12 at 16:43
  • hello again it is now updated please let me know if you can help ? – A.Wad Aug 10 '12 at 12:21
  • In your code, ModFileArr1 is never populated and you are not checking the existence of FileLocalPos1.Item(ModFileArr1.Item(b).ToString) before using it. – competent_tech Aug 10 '12 at 16:58
  • I dont get what do you mean by the array is never populated ? – A.Wad Aug 13 '12 at 12:02
  • This code was working completely fine when the searchopton was Alldirecoties but with the topdirectyonly option it is not working at all – A.Wad Aug 13 '12 at 12:58
  • please help i am really stuck big time – A.Wad Aug 14 '12 at 07:07