find ALL files in folder and sub folders...how?

Discussion in 'Questions (Windows Mobile)' started by Byak@, Jan 3, 2009.

  1. Byak@

    Byak@ Active Member Licensed User

    I thought much but and have not found a beautiful way...
    how can i find ALL files in given dir?include subdirs
     
  2. Filippo

    Filippo Expert Licensed User

  3. Byak@

    Byak@ Active Member Licensed User

    Greating Flippo)i'm work with soirce of your explorer but not find,how can i do it.you find files in subfolder when click it.but i must find all files at once
     
  4. tsteward

    tsteward Active Member Licensed User

    Man get out of my head.
    I just asked the same question in a different way.

    Anyway looking forward to the solution as I also need to do this!!!
     
  5. Cableguy

    Cableguy Expert Licensed User

    FROM BASIC4PPC HELP

    ------------------------------------------------------
     
  6. Byak@

    Byak@ Active Member Licensed User

    Cableguy
    we know how find files and find folders.but how find files in all subfolders and subsubfolders and sub...subfolders?
     
  7. Cableguy

    Cableguy Expert Licensed User

    use a bit of logic...
    if root folder has subdir, then search each subdir for folders...Until the result is 0Then you will have a series of array with ALL THE SUBFOLDERS OF YOUR MAIN ROOT

    Same with the files...

    Example:
    IF DirSearch(Root(),"\MyDocuments")>0 Then
    For x=0 to arraylen(root())-1
    Textbox1.text=TextBox1.text&Root(x)&crlf 'this will populate a textbox with the root values
    Next
    For x=0 to Arraylen(Root())-1
    DirSearch(Control(Level(),Root(x))
    Textbox1.text=TextBox1.text&Root(x)&crlf
    Next
    End If

    NOTE this is untested code, root and level are arraylist controls...
     
  8. Byak@

    Byak@ Active Member Licensed User

    Cableguy you read my post?i must find ALL FILES in folder,sub-folders,subsub-folders,subsubsub-folders,subsubsub-folders...subsubsubsubsubsubsubsubsubsubsubsub-folders.
    yes,you may use 1000 cicles and create 1000 arraylists...but i want a beautiful way...

    p.s. in your code your have some errors)and your cade show only folders from root
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Here:
    Code:
    Sub Globals
        
    'Declare the global variables here.

    End Sub

    Sub App_Start
        Form1.Show
        FindAllFiles(
    "\My Documents")
        
    For i = 0 To alFiles.Count-1
            listbox1.Add(FileName(alFiles.Item(i))) 
    'Remove FileName if you need the full 
        Next
    End Sub

    Sub FindAllFiles(root)
        alFolders.Clear 
    'ArrayList
        alFiles.Clear 'ArrayList
        alFolders.Add(root)
        i = 
    0
        
    Do While alFolders.Count > i
            
    'search one folder
            currentFolder = alFolders.Item(i)
            DirSearch(alFolders,currentFolder) 
    'Add all subfolders in this folder to the list.
            FileSearch(alFiles,currentFolder,"*.*"'Add all files from this folder.
            b = alFiles.Count
            i = i + 
    1
        
    Loop
    End Sub
     
  10. Byak@

    Byak@ Active Member Licensed User

    Erel big-big-big thanks!!!i'm don't know what dirsearch add folders to arraylist,i'm think it replace)
    big thanks!
     
  11. tsteward

    tsteward Active Member Licensed User

    Thanks erol,
    The logic was eluding me and as I was reading down this thread I started thinking I needed a do while loop rather than If's

    Then I came to your post. It must frustrate the more experienced users sometimes but we can't always see the forrest when the trees get in the way.

    Thanks for your help
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Not at all. This was an interesting question with a nice answer.
     
  13. joel2009

    joel2009 Member Licensed User

    I'm getting an error everytime with "end sub" on the findallfiles sub.... and without it i get an argument out of range exception. Anyone know what i'm doing wrong?

    Code:
    Sub App_Start
        Form1.Show
        FindAllFiles(
    "\Storage Card\Program Files")
        
    For i = 0 To alFiles.Count-1
            listbox1.Add(FileName(alFiles.Item(i))) 
    'Remove FileName if you need the full 
        Next
    End Sub

    Sub FindAllFiles(root)
        alFolders.Clear 
    'ArrayList
        alFiles.Clear 'ArrayList
        alFolders.Add(root)
        i = 
    0
        
    Do While alFolders.Count > i
            
    'search one folder
            currentFolder = alFolders.Item(i)
            DirSearch(alFolders,currentFolder) 
    'Add all subfolders in this folder to the list.
            FileSearch(alFiles,currentFolder,"*.exe*"'Add all files from this folder.
            b = alFiles.Count
            i = i + 
    1
        
    Loop
    I'm trying to write a program that will restore all of my shortcuts to my start menu after flashing.

    EDIT: from what i can tell... the out of range exception has something to do with arrays.
     
  14. Erel

    Erel Administrator Staff Member Licensed User

    Can you upload your code file?
    There is a missing 'end sub' in the posted code.
     
  15. joel2009

    joel2009 Member Licensed User

    It doesn't run with the end Sub. (it gives an error and closes on me)
     

    Attached Files:

  16. Erel

    Erel Administrator Staff Member Licensed User

    I've added the missing 'End Sub' and it works fine.
    What error do you get?
     
  17. joel2009

    joel2009 Member Licensed User

    Code:
    error compiling program.
    error descrition: Variable main.b 
    in sub main.findallfiles is never used.
    error occurred on line: 
    26
    End Sub
     
  18. Cableguy

    Cableguy Expert Licensed User

    Joel, you can safely remove the
    Code:
    b = alFiles.Count
    Code line from the code, and the error will no longer be trigged, or simply un-check the "check un-used variable" option...
     
  19. joel2009

    joel2009 Member Licensed User

    Thanks much, cant believe i didnt see that haha....
     
  20. Erel

    Erel Administrator Staff Member Licensed User

    Another solution is to add:
    Code:
    Dim b
    In this sub.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice