473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 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 6971
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 the file size units where English would use "KB". ...
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 and deleted the .vbproj files that had been...
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 find a software.design group. I would like to...
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 problems marshalling the array of OIDs in...
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 things and I think it really belongs with the web app...
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. Folder 1 contains three files (File1, File2, File3)...
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 file management. At first, it appeared there...
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, header (prefixed with RHD) and detail (prefixed with...
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 file. perl -ne 'print if /struct.*{/ .. /}/'...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.