I am using the AllenBrowne code of "filldirlisttot able" to provide some functions for a media library manager I am building in access 2003.
I have four checkboxes which if all four are not turned on, give a list of extensions that should be search for. However, when I do it that way, I get no results.
The code works great. Only one issue, I cannot find anywhere on the net any notes about using the filespec option.
By default it uses *.*, and I can make it work by specifying only one extension, such as *.jpg, but it becomes useless when I specify multiple extensions such as *.jpg, *.gif, *.png.
Obviously that must be the wrong way to provide the filespec.
Has anyone used this function? I am providing part of it below.
There may even be a better way of doing this, but I have written substantial code around this so I thought I would see if nybody was familiar with it before I started working on a different solution.
I am kind of thinking that unless this code simply cannot handle the multiple extensions regardless of how they are provided, then I may have to re-write this section of code. - Call FillDirToTable(colDirList, strpath, strFileSpec, bIncludeSubfolders)
This goes to: - Private Function FillDirToTable(colDirList As Collection _
-
, ByVal strFolder As String _
-
, strFileSpec As String _
-
, bIncludeSubfolders As Boolean)
-
-
'Build up a list of files, and then add add to this list, any additional folders
-
On Error GoTo Err_Handler
-
-
Dim strTemp As String
-
Dim colFolders As New Collection
-
Dim vFolderName As Variant
-
Dim strSQL As String
-
-
'Add the files to the folder.
-
strFolder = TrailingSlash(strFolder)
-
strTemp = Dir(strFolder & strFileSpec)
-
Do While strTemp <> vbNullString
-
gCount = gCount + 1
-
SysCmd acSysCmdSetStatus, gCount
-
strSQL = "INSERT INTO zzLibScan " _
-
& " (MediaFileName, MediaPath) " _
-
& " SELECT """ & strTemp & """" _
-
& ", """ & strFolder & """;"
-
CurrentDb.Execute strSQL
-
colDirList.Add strFolder & strTemp
-
strTemp = Dir
-
Loop
-
-
If bIncludeSubfolders Then
-
'Build collection of additional subfolders.
-
strTemp = Dir(strFolder, vbDirectory)
-
Do While strTemp <> vbNullString
-
If (strTemp <> ".") And (strTemp <> "..") Then
-
If (GetAttr(strFolder & strTemp) And vbDirectory) <> 0& Then
-
colFolders.Add strTemp
-
End If
-
End If
-
strTemp = Dir
-
Loop
-
'Call function recursively for each subfolder.
-
For Each vFolderName In colFolders
-
Call FillDirToTable(colDirList, strFolder & TrailingSlash(vFolderName), strFileSpec, True)
-
Next vFolderName
-
End If
-
-
Exit_Handler:
-
-
Exit Function
-
-
Err_Handler:
-
strSQL = "INSERT INTO zzLibScan " _
-
& " (MediaFileName, MediaPath) " _
-
& " SELECT "" ~~~ ERROR ~~~""" _
-
& ", """ & strFolder & """;"
-
CurrentDb.Execute strSQL
-
-
Resume Exit_Handler
-
End Function
-
-
Public Function TrailingSlash(varIn As Variant) As String
-
If Len(varIn) > 0& Then
-
If Right(varIn, 1&) = "\" Then
-
TrailingSlash = varIn
-
Else
-
TrailingSlash = varIn & "\"
-
End If
-
End If
-
End Function
Any help or suggestions are appreciated.
14 3798 nico5038 3,080
Recognized Expert Specialist
This code will only allow one filter for the file name extension.
I would advise to call the routine for each extension. The table will "collect" the different extensions for you.
Nic;o)
ADezii 8,834
Recognized Expert Expert
I imagine that you would want to Delete the contents of the Table zzLibScan before populating it with your FileSpec results, if so: - Dim varRetVal As Variant
-
Dim colDirList As New Collection
-
-
DoCmd.Hourglass True
-
-
With DoCmd
-
.SetWarnings False
-
DoCmd.RunSQL "Delete * From zzLibScan"
-
.SetWarnings True
-
End With
-
-
varRetVal = FillDirToTable(colDirList, "C:\Some Folder", "*.FileSpec", True)
-
-
DoCmd.Hourglass False
P.S. - If you ran multiple FileSpecs through this Recursive Procedure, I imagine that you would run into potential problems.
What I am trying to decide is how to feed the multiple file specifications to the function.
On one hand, I can build a list of extensions and parse them out into an array and loop through the array. This benefits users of the program in they would directly choose the file types.
Alternatively, I could ignore the filespec, and use the procedure as written and cappture all files, then discard (which I already have a routine for) the files that the user didn't want. The latter is probably more time consuming.
There has to be a better way of doing this. If there a function, or routine that will do what this routine is doing (just file name to one field and the complete path to another field) being populated in a temporary table with multiple file specifications, I use the two fields for all the other functions, against the individual files, such as getting tags information from MP3s, basic file information, and such in routines afterward.
I suppose the better question is there is better function than this one? Where can I find info, or if there is an open source function, where can I locate?
Thanks for the replies.
CJ
nico5038 3,080
Recognized Expert Specialist
I would probably create a table with file extensions and a YesNo field that can be set by the user.
In a record set processing loop you can activate the function for all extensions having the YesNo field set to True.
(And ofcourse empty the table first with ADezii's DELETE)
Nic;o)
That is not a bad idea, then I can pass the needed extensions through a loop based on the on/off field for the extenion. That would also make it VERY easy to add more extensions as I develop the software.
Nico, AWESOME suggestion, I had not thought of that.
Extension definition table it is, then loop through the valid record for the filldirtotable function.
THANKS!
CJ
ADezii 8,834
Recognized Expert Expert
I actually had my doubts about how effective the code would be with multiple File Specs, so I ran it with 4 different File Specifications, and here are the results following the posted code: - Dim varRetVal As Variant
-
Dim colDirList As New Collection
-
Dim intCounter As Integer
-
-
DoCmd.Hourglass True
-
-
With DoCmd
-
.SetWarnings False
-
DoCmd.RunSQL "Delete * From zzLibScan"
-
.SetWarnings True
-
End With
-
-
For intCounter = 1 To 4
-
Select Case intCounter
-
Case 1
-
varRetVal = FillDirToTable(colDirList, "C:\", "*.exe", True)
-
Case 2
-
varRetVal = FillDirToTable(colDirList, "C:\", "*.dll", True)
-
Case 3
-
varRetVal = FillDirToTable(colDirList, "C:\", "*.bmp", True)
-
Case 4
-
varRetVal = FillDirToTable(colDirList, "C:\", "*.txt", True)
-
Case Else
-
End Select
-
Next
-
-
DoCmd.Hourglass False
OUTPUT:
Files returned matching the 4 Specs: 4,826
Records containing Errors: 60
nico5038 3,080
Recognized Expert Specialist
Glad you see the advantage :-)
The code needed could use a query selecting the true extensions like: -
-
function fncFillFiles()
-
-
dim rs as DAO.Recordset
-
-
set rs = currentdb.openrecordset("select extension from tblExtension where SelectYN = True")
-
-
if rs.eof and rs.bof then
-
msgbox "No selected extensions"
-
exit function
-
endif
-
-
' initialize target table when needed
-
currentdb.execute ("delete * from tblResults")
-
-
while not rs.EOF
-
' change to use the proper colDirList and strpath
-
Call FillDirToTable(colDirList, strpath, rs!FileSpec, bIncludeSubfolders)
-
rs.movenext
-
wend
-
-
end function
-
Nic;o)
ADezii 8,834
Recognized Expert Expert @nico5038
Nice approach, Nico. Any speculation why the 60 Errors (1.24% Error Rate)?
nico5038 3,080
Recognized Expert Specialist
Guess the errors are SQL errors on the INSERT.
In such a case I suspect a field being inserted is empty while defined to be required and/or a unique indexed field that's causing duplicate entries.
Can you check the files causing this trouble? Perhaps they are having a hidden or other property set causing the dir() statement to fail. Another option could be the (sub) folders that are returning . or .. as "filename".
Nic;o)
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: John |
last post by:
Hi everyone !
This is a first time I post a message here. If I post my message in a
wrong group. Please ignore it.
I am trying to build a website which allows users (can be thousands of
users, supposedly) to upload their files to their designaged
directories (max 15 files for each user). A super user (can be more
than one) want to search for a particular file name and also a
particular textual part of a file of all user's files in all...
|
by: Alan Mackenzie |
last post by:
I've recently moved onto a C++ project with a large number of directories
(several hundred) containing an even larger number of C++ source files.
There are vastly more ways in C++ to obfuscate a program than there are
in C, and it seems somebody laid a bet on the original development team
to prove that this is the case. ;-( Unfortunately, I have no contact
with the original programmers, who live and work on a different
continent.
In...
|
by: Jerry |
last post by:
I'm having just a bit of trouble wrapping my brain around the task of
working with folders that are above the site's root folder.
I let users upload photos (.jpg/.gif files) which can subsequently be viewed
on the site's pages. My hosting provider is requiring that any files my Web
app writes get written to a folder that is above the app's root folder (for
security purposes).
When writing the files I understand how to use MapPath to...
|
by: jaysherby |
last post by:
I'm new at Python and I need a little advice. Part of the script I'm
trying to write needs to be aware of all the files of a certain
extension in the script's path and all sub-directories. Can someone
set me on the right path to what modules and calls to use to do that?
You'd think that it would be a fairly simple proposition, but I can't
find examples anywhere. Thanks.
|
by: rn5a |
last post by:
I have a ListBox which should list all the files & directories that
exist in a particular directory. The problem is I can get the ListBox
to list either all the files or all the directories but not the 2 of
them together. This is what I tried:
Sub Page_Load(.....)
Dim dInfo As DirectoryInfo
dInfo = New DirectoryInfo(Server.MapPath(MyDir))
| |
by: neilio2j |
last post by:
hi, can anyone tell me how to search a given directory using C++?
so far i have been successful in searching a file named, for tags"h:\\tags.cpp",
whereas i would like to search for all files in the entire h: directory.
this is the code i have used for searching the file named, "h:\\tags.cpp",
/*char filename;
cout<<"Please enter the filename";
|
by: souravmallik |
last post by:
Hello,
I'm writing a parser program in C language. I need to search all the source file for the parser to parse from a set of directories.
The directory structure have two branch i.e. there will be a root directory and there will be subdirectories, and within the subdirectories the source file are placed.
So I need to scan each sub-directory and find all the file and parse.
I'm using MS VC++ 6.0, so I'm not been able to use the...
|
by: Stephenoja |
last post by:
Hello Guys,
I have a challenge here and would really appreciate some help. I have customer bills that are all done in excel with a template and stored in directories by month order. At the end of the month or periodically, I need to query and print a report giving customer name, account number, date of service and cost for a particular service/item for all customers who received such a service/item (at times up to 300 customer bills in...
|
by: jodleren |
last post by:
Hi!
I wonder, which way to do this fastest.
I have a disk, where I need to search for a file or directory.
I do it recursively, meaning that I start from the top dir, then I add
all directories to an array, and by a counter I work my way through
that array.
And, while doing that I add the directory or file (name) to and result
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |