Find specific file types with a folder structure

  • Thread starter Thread starter Justin
  • Start date Start date
J

Justin

I need to scan a specific folder and it's subfolders for specific file types
for example, *.gif, *.jpg, *.png... and so forth.

Every time I find one of these files I will be dumping it and other info
into a DB.

Before I tackle this feat I figure there might be an existing routine out
there already.

Can anyone point me in the right direction? An hour of Google got me no
where.

Thanks for any info!
Justin
 
Justin,

When you want an alternative routine, than you have first to tell us what
you use now.
There are a lot of posibilities you know. However the DirectoryInfo will
probably be the way to go and than loop through the returned files.

Cor
 
???
"Before I tackle this feat..."

I'm not looking for an alternative. I have nothing. Hence an hour of
googling got me nowhere.

I need to scan a folder path and it's subfolders for multiple files. Once I
have that I can handle writing them to a DB. I now have many hours of
google under my belt on this one. I have since come up with a routine but
it will only search for one file at a time. I might have up to 20 file
types to search for. I can also have thousands of folders to search
through. So time to wait for the process is a concideration.


Sub FindFiles(ByVal files As ArrayList, ByVal dirname As String, ByVal
filespec As String)
For Each fname As String In System.IO.Directory.GetFiles(dirname, filespec)
files.Add(fname)
Next
For Each dname As String In System.IO.Directory.GetDirectories(dirname)
FindFiles(files, dname, filespec)
Next
End Sub

Maybe I can run this routine for every file type but I'm affraid of how slow
that may run on slower systems. That's one thing I can't test for.


If you made it this far, thanks for your time with my problem!
 
Thanks Wagner! This is much more stable then the routine I came up with.
It's also a good tutorial on threads which is something I hadn't gotten into
before. That's a new step for me.

As for finding multiple file types I guess I could dynamicly create this IF
statement:

If Path.GetFileName(e.FileName) Like Type1 or Path.GetFileName(e.FileName)
Like Type2 or Path.GetFileName(e.FileName) Like Type3........ Then

That would be a huge IF statement. Any performance issues on that one?

Thanks for all your help!!!
 
: Thanks Wagner! This is much more stable then the routine I came up
with.
: It's also a good tutorial on threads which is something I hadn't
gotten into
: before. That's a new step for me.
:
: As for finding multiple file types I guess I could dynamicly create
: this IF statement:
:
: If Path.GetFileName(e.FileName) Like Type1 or
: Path.GetFileName(e.FileName)
: Like Type2 or Path.GetFileName(e.FileName) Like Type3........ Then
:
: That would be a huge IF statement. Any performance issues on that
: one?
:
: Thanks for all your help!!!


How about:

Select Case Path.GetFileName(e.FileName)
Case Type1, Type2, Type3, ..., TypeN
DoSomething
Case Else
DoSomethingElse
End Select

Ralf
 
Justin said:
As for finding multiple file types I guess I could dynamicly create this
IF statement:

If Path.GetFileName(e.FileName) Like Type1 or Path.GetFileName(e.FileName)
Like Type2 or Path.GetFileName(e.FileName) Like Type3........ Then

That would be a huge IF statement. Any performance issues on that one?

You may want to use 'OrElse' instead of 'Or' in order to use
short-circuiting.

\\\
Select Case Path.GetExtension(FileName)
Case ".txt", ".doc", ".wri"
...
Case ".exe"
...
...
End Select
///
 
Buy file type I'm specifying the whole file name. These file names and
types are stored in a listbox and they can be named "anything". I'll never
the know the names until I hit GO.

For example:
index.html
index.htm
default.html
default.asp
......

It looks like your last bit of code would handle every single file it came
across. I'll research OrElse.
 
Wagner,
I'm hoping you can help me out on this one. I'm using your dll from the
link you provided and when I run something specific from within your code I
get this error:

An unhandled exception of type 'System.StackOverflowException' occurred

Here is what I've done to your sub (I'll spare you my large case select):


Private Sub m_Enumerator_FileFound(ByVal sender As Object, ByVal e As
FileFoundEventArgs) Handles m_Enumerator.FileFound

If Me.InvokeRequired Then
Me.BeginInvoke(New FileFoundDelegate(AddressOf Me.m_Enumerator_FileFound),
New Object() {sender, e})
Else
Select Case listFileTypes.Items.Count
Case 1

If Path.GetFileName(e.FileName) Like "index.htm" Then
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source='" & Application.StartupPath & "\access.mdb'")
Dim cmdURL As New OleDbCommand("INSERT INTO " & ID & " (URL) VALUES (@URL)",
con)
cmdURL.CommandType = CommandType.Text
Dim paramURL As New OleDbParameter
paramURL.ParameterName = "@URL"
paramURL.OleDbType = OleDbType.Char
paramURL.Value = e.FileName
cmdURL.Parameters.Add(paramURL)
con.Open()
cmdURL.ExecuteNonQuery()
con.Close()

snap.SetTimeOut(100000)
snap.SetSnapDimension(800, 600)
snap.SnapUrl(e.FileName, "*") ***************This is where it
breaks**************
snap.SetJPEGQuality(100)
' Stream the thumbnail from memory and into an object
Dim adoStreamThumbnail
Dim Thumbnail
Thumbnail = snap.GetThumbImageBytes("*.jpg", 200, 200, 1)
adoStreamThumbnail = CreateObject("ADODB.Stream")
adoStreamThumbnail.Type = 1
adoStreamThumbnail.Open()
adoStreamThumbnail.Write(Thumbnail)
adoStreamThumbnail.SaveToFile("c:\Thumbnail.jpg")


If I put my "snap" code anywhere else it works fine. It only happens when
it's in your "If Path.GetFileName(e.FileName) Like " statement.

If I remove the "snap" code then everything else runs fine.


Thanks for any insight!
 
Justin said:
snap.SetTimeOut(100000)
snap.SetSnapDimension(800, 600)
snap.SnapUrl(e.FileName, "*") ***************This is where it
breaks**************
snap.SetJPEGQuality(100)
' Stream the thumbnail from memory and into an object
Dim adoStreamThumbnail
Dim Thumbnail
Thumbnail = snap.GetThumbImageBytes("*.jpg", 200, 200, 1)
adoStreamThumbnail = CreateObject("ADODB.Stream")
adoStreamThumbnail.Type = 1
adoStreamThumbnail.Open()
adoStreamThumbnail.Write(Thumbnail)
adoStreamThumbnail.SaveToFile("c:\Thumbnail.jpg")

If I put my "snap" code anywhere else it works fine.

What is 'snap'?
 
Sorry, I should have explained that:

Here are the two lines that create it:

Friend WithEvents snap As HtmlSnap2.CHtmlSnapClass
Me.snap = New HtmlSnap2.CHtmlSnapClass

It's a dll that takes an HTML page and creates a thumbnail of it. So
basicly in this case whenever I find an index.htm I create an index of it
and stream it from memory and into an object.

The exact line it fails on is when it's trying to create that thumbnail.
 
Correction:

whenever I find an index.htm I create a THUMBNAIL of it
and stream it from memory and into an object.
 

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

Back
Top