Results 1 to 4 of 4

Thread: if statement only choice

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    if statement only choice

    hi gurus

    Here is my problem->
    I have three folders that I need to check if they are empty or not, if one of them is empty, I would like to keep checking the other two, if they are not empty I want to do something and then check the other two, but not all the time all three will be empty or not empty there might be times where one folder has something and the other two not and so on. I just want to check a folder and if its empty go to the next one but if not do something and still g to the next one to check if it empty or not, an so on

    what would be my best approach to solve this.

    Nested If statement or is there a better way.

    Thanks a bunch gurus
    thanks a bunch

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: if statement only choice

    Code:
    Dim folders = New String() {"C:\test\folder1", _
                                "C:\test\folder2", _
                                "C:\test\folder3"}
    For Each folder In folders
        Dim directory = New IO.DirectoryInfo(folder)
        Dim files = directory.GetFiles()
        If files.Length > 0 Then
            '//not empty, process files
        End If
    Next

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,419

    Re: if statement only choice

    you just need to check all 3 folders for files sequentially:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     If IO.Directory.GetFiles("folder1").Count > 0 Then
    3.  
    4.     End If
    5.     If IO.Directory.GetFiles("folder2").Count > 0 Then
    6.  
    7.     End If
    8.     If IO.Directory.GetFiles("folder3").Count > 0 Then
    9.  
    10.     End If
    11. End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Posts
    138

    Re: if statement only choice

    WoW gurus

    Thanks a bunch , I think I was going in the wrong direction,thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width