Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Go Back  Xtreme Visual Basic Talk > > > Finding and listing all images on a computer / folder structure


Reply
 
Thread Tools Display Modes
  #1  
Old 09-20-2014, 12:24 PM
dmratcliffe dmratcliffe is offline
Newcomer
 
Join Date: Sep 2014
Posts: 2
Default Finding and listing all images on a computer / folder structure


Hey, so I whipped up to code snippets here,
both are meant to go through every folder and find every image,
I will go into more detail for each of them:

This is my original finder before I knew much about arrays:
Code:
 For Each foundFile As String In My.Computer.FileSystem.GetFiles(Application.StartupPath)
            Try
                Dim tryImage As System.Drawing.Image = System.Drawing.Image.FromFile(foundFile)
                pictureListBox.Items.Add(foundFile)
            Catch ex As Exception

            End Try
        Next

        For Each Dir As String In My.Computer.FileSystem.GetDirectories(Application.StartupPath, FileIO.SearchOption.SearchAllSubDirectories)
            For Each foundFile As String In My.Computer.FileSystem.GetFiles(Dir)
                Try
                    Dim tryImage As System.Drawing.Image = System.Drawing.Image.FromFile(foundFile)
                    pictureListBox.Items.Add(foundFile)
                Catch ex As Exception

                End Try
            Next
        Next
The problem is, 1. its slow as balls, 2. It hates protected folders because of those fors. It looks at each file and tests if it is an image then adds it or moves on.

Then I went off and learned about arrays and ranges and came up with this:
Code:
 Private Function listFiles(ByVal appStart As String) As List(Of String)
        Dim fList As New List(Of String)
        Dim fldrLis As New List(Of String)
        Dim t As New List(Of String)

        Dim d As New IO.DirectoryInfo(appStart)
        If Not d.Exists Then
            MessageBox.Show("Not a real folder errr")
            Return Nothing
        End If
        Try
            fList.AddRange(Directory.GetFiles(appStart))
            fldrLis.AddRange(Directory.GetDirectories(appStart))
        Catch ex As Exception
            MessageBox.Show("Re run in admin mode")
            Return Nothing
        End Try
        'If there are directories in this folder process them
        For Each f As String In fldrLis
            t = listFiles(f)
            If t IsNot Nothing Then fList.AddRange(tmp)
        Next
        Return fList
    End Function
then after that finishes, I go through that and check each item for picture (I wrote this code in a ****ed off mode and haven't fixed it but it works):
Code:
 Try
            For n = 0 To ListBox1.Items.Count - 1
                ListBox1.SelectedIndex = n
                Dim var As String = ListBox1.SelectedItem.ToString
                Try
                    Dim tryImage As System.Drawing.Image = System.Drawing.Image.FromFile(var)
                    amountLabel.Text = pictureListBox.Items.Count
                    pictureListBox.Items.Add(var)
                Catch ex As Exception
                End Try
            Next
        Catch ex As Exception
            MsgBox("whoopse!")
        End Try
All this is still better then the original.
Is there a way to implement the second part into the first? Check it before adding it to the array?
I am still new to arrays but that code does work fine...
Thanks in advance to anyone who can help.
Reply With Quote
  #2  
Old 09-21-2014, 03:01 PM
hDC_0Finding and listing all images on a computer / folder structure hDC_0 is offline
Contributor

* Expert *
 
Join Date: Feb 2004
Posts: 559
Default HD searching..

Quote:
Originally Posted by dmratcliffe
Is there a way to implement the second part into the first? Check it before adding it to the array?
Did you possibly mean (hint) "Check it while adding it to the array"?
..and yes, I definitely commend you for learning about working with arrays;
however another topic to explore might be that of recursion.
It is a very powerful programming technique designed to do a lot of work while only using a few lines of code.

I did an advanced search of XVBT's VB.Net File I/O sub forum, using the terms "recursion" and "recursive"
--it found dozens of threads, including a few that use background threading (1, 2),
which allows stopping the search if it starts to run too long on full 8/10 terabyte hard drives.
Reply With Quote
  #3  
Old 09-26-2014, 04:53 PM
dmratcliffe dmratcliffe is offline
Newcomer
 
Join Date: Sep 2014
Posts: 2
Default

Quote:
Originally Posted by hDC_0 View Post
Did you possibly mean (hint) "Check it while adding it to the array"?
Oh. Derp. Why didn't I think of that?
So instead of just adding the .getFiles I should check the list of 'em first.
I really like that idea of 2 threads for the directory and for the files though.

Also, I had already placed the getfiles inside of a new thread to run it (such as the "1" you directed me to. However I have a lot of trouble stopping the thing while running, but I will look into that later.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
 
Finding and listing all images on a computer / folder structure
Finding and listing all images on a computer / folder structure
 
-->