472,328 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 software developers and data experts.

Find specific file types with a folder structure

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
12 6884
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
???
"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
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
"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
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
"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
"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
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
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
"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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: RussC | last post by:
(If this is not posted in the right place, please let me know what the right place is...) I understand that French Windows Explorer uses "Ko" as...
5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS...
2
by: Vince | last post by:
I have a very specific problem to solve but I cannot find a data structure for it. I don't know if I am posting on the good newsgroup but I cannot...
3
by: Charles Denny | last post by:
I'm trying to call CertFindCertificateInStore to find all certificates in the store that have the Code Signing enhanced key usage. I'm running into...
3
by: Bruce W.1 | last post by:
I've been keeping my solution .sln files for ASP.NET projects off in some remote location, along with all my other .sln files. This confuses...
9
by: Paul | last post by:
I'm trying to make get my app to delete all the files in a specified folder and all the files within the folders of the specified folder. e.g....
6
by: Kevin Frevert | last post by:
In the process of learning VS2005/C# (having a background in Borland Delphi 2 through 2005) I came across an interesting feature of Visual Studio's...
1
by: NathanB | last post by:
Hi there, I have a text file (flat file) which I would like to import on a regular basis into Access. The text file contains 2 record types,...
4
by: vishnujs | last post by:
Hi, I am completely new to perl. what i want to do is to find if a specific data type is used inside the structure definitions in a C header...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.