By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,579 Members | 1,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,579 IT Pros & Developers. It's quick & easy.

Find specific file types with a folder structure

P: n/a
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
Nov 21 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
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
Nov 21 '05 #2

P: n/a
???
"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!
Nov 21 '05 #3

P: n/a
Justin,

Than I know that the directoryinfo can be one of the methods you can use.

http://msdn.microsoft.com/library/de...filestopic.asp

In my opinion is the sample more difficult than strictly needed, therefore
when you have a problem, than reply (not in 5 minutes please).

I hope this helps,

Cor
Nov 21 '05 #4

P: n/a
"Justin" <Ju****@NoSpam.com> schrieb:
I need to scan a specific folder and it's subfolders for specific file
types for example, *.gif, *.jpg, *.png... and so forth.


<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/FileSystemEnumerator.zip>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

P: n/a
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!!!
Nov 21 '05 #6

P: n/a
"Justin" <Ju****@NoSpam.com> wrote in message
news:OK**************@TK2MSFTNGP14.phx.gbl...
: 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
Nov 21 '05 #7

P: n/a
"Justin" <Ju****@NoSpam.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8

P: n/a
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.


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:eQ****************@TK2MSFTNGP14.phx.gbl...
"Justin" <Ju****@NoSpam.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9

P: n/a
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!

Nov 21 '05 #10

P: n/a
"Justin" <Ju****@NoSpam.com> schrieb:
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'?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #11

P: n/a
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.
Nov 21 '05 #12

P: n/a
Correction:

whenever I find an index.htm I create a THUMBNAIL of it
and stream it from memory and into an object.
Nov 21 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.