PC Review


Reply
Thread Tools Rate Thread

How can I list the files in a directory and sub directory

 
 
felixc36@yahoo.com
Guest
Posts: n/a
 
      4th Feb 2005

Hi,

I have this project where i must read all the files havin a specific extention
(*.mdb for example) in a directory and subdirectories.

I was wondering if that is possible.

What ultimately I am looking for is building a procedure that would have a
root directory and an extention as parameters and then would create a
recordset having the path and filenames of all the files having the extention
in the directory and it's sub directories.

Is that a feasable thing in Access 97?

You can answer me here or at my e-mail address (E-Mail Removed).
(please remove the NoSPAM in the address).

Thank you


 
Reply With Quote
 
 
 
 
Alan Z. Scharf
Guest
Posts: n/a
 
      4th Feb 2005
When you say read, do you mean read data from them or get a listing.

The System File Object will handle many file-related operations.

Alan
<(E-Mail Removed)> wrote in message
news:uJCMd.22199$(E-Mail Removed)...
>
> Hi,
>
> I have this project where i must read all the files havin a specific

extention
> (*.mdb for example) in a directory and subdirectories.
>
> I was wondering if that is possible.
>
> What ultimately I am looking for is building a procedure that would have a
> root directory and an extention as parameters and then would create a
> recordset having the path and filenames of all the files having the

extention
> in the directory and it's sub directories.
>
> Is that a feasable thing in Access 97?
>
> You can answer me here or at my e-mail address (E-Mail Removed).
> (please remove the NoSPAM in the address).
>
> Thank you
>
>



 
Reply With Quote
 
felixc36@yahoo.com
Guest
Posts: n/a
 
      4th Feb 2005
Thank you for answering....

What I want to do is first to capture the path and flename and utlimately read
the contents of the files for processing.

For example I have the following file structure:
C:\--|
MyDir------------Agency1 ---- 2002--- File1.dbf, file2.dbf
| | --------- 2003---File1.dbf
| |----------- 2004---File1.dbf
|
|--------------------Agency2 ---- 2002---File1.dbf, file2.dbf
| |-------- 2003---File1.dbf
|
|---------------Agency3 ---- 2000--- File1.dbf, file2.dbf
|----------- 2001---File1.dbf, file2.dbf
|------------ 2002--- File1.dbf, file2.dbf

I want to pass as a parameter MyDIR and The DBFextension to a procedure.

What I would want is for the procedure to create a recordset capturing the
path of each files having a dbf extension in a variable.

"C:\Mydir\Agency1\2002\File1.dbf"
"C:\Mydir\Agency1\2002\File2.dbf!"
"C:\Mydir\Agency1\2003\File1.dbf!"
"C:\Mydir\Agency1\2004\File1.dbf!"
"C:\Mydir\Agency2\2002\File1.dbf!"
...

... and so on.





In article <(E-Mail Removed)>, "Alan Z. Scharf"
<(E-Mail Removed)> wrote:
>When you say read, do you mean read data from them or get a listing.
>
>The System File Object will handle many file-related operations.
>
>Alan
><(E-Mail Removed)> wrote in message
>news:uJCMd.22199$(E-Mail Removed)...
>>
>> Hi,
>>
>> I have this project where i must read all the files havin a specific

>extention
>> (*.mdb for example) in a directory and subdirectories.
>>
>> I was wondering if that is possible.
>>
>> What ultimately I am looking for is building a procedure that would have a
>> root directory and an extention as parameters and then would create a
>> recordset having the path and filenames of all the files having the

>extention
>> in the directory and it's sub directories.
>>
>> Is that a feasable thing in Access 97?
>>
>> You can answer me here or at my e-mail address (E-Mail Removed).
>> (please remove the NoSPAM in the address).
>>
>> Thank you
>>
>>

>
>

 
Reply With Quote
 
=?Utf-8?B?TWlhcGxhY2lkdXM=?=
Guest
Posts: n/a
 
      4th Feb 2005
I have a similar problem, I can use filesearch to get the listing of files
and subdirectories. What Ai want to do first is read the other file
attributes into a table and later, based on file attributes, opent the files
and search for keywords or other information. The end result will be to
create an index of files on the drive with contacts etc.

"(E-Mail Removed)" wrote:

> Thank you for answering....
>
> What I want to do is first to capture the path and flename and utlimately read
> the contents of the files for processing.
>
> For example I have the following file structure:
> C:\--|
> MyDir------------Agency1 ---- 2002--- File1.dbf, file2.dbf
> | | --------- 2003---File1.dbf
> | |----------- 2004---File1.dbf
> |
> |--------------------Agency2 ---- 2002---File1.dbf, file2.dbf
> | |-------- 2003---File1.dbf
> |
> |---------------Agency3 ---- 2000--- File1.dbf, file2.dbf
> |----------- 2001---File1.dbf, file2.dbf
> |------------ 2002--- File1.dbf, file2.dbf
>
> I want to pass as a parameter MyDIR and The DBFextension to a procedure.
>
> What I would want is for the procedure to create a recordset capturing the
> path of each files having a dbf extension in a variable.
>
> "C:\Mydir\Agency1\2002\File1.dbf"
> "C:\Mydir\Agency1\2002\File2.dbf!"
> "C:\Mydir\Agency1\2003\File1.dbf!"
> "C:\Mydir\Agency1\2004\File1.dbf!"
> "C:\Mydir\Agency2\2002\File1.dbf!"
> ...
>
> ... and so on.
>
>
>
>
>
> In article <(E-Mail Removed)>, "Alan Z. Scharf"
> <(E-Mail Removed)> wrote:
> >When you say read, do you mean read data from them or get a listing.
> >
> >The System File Object will handle many file-related operations.
> >
> >Alan
> ><(E-Mail Removed)> wrote in message
> >news:uJCMd.22199$(E-Mail Removed)...
> >>
> >> Hi,
> >>
> >> I have this project where i must read all the files havin a specific

> >extention
> >> (*.mdb for example) in a directory and subdirectories.
> >>
> >> I was wondering if that is possible.
> >>
> >> What ultimately I am looking for is building a procedure that would have a
> >> root directory and an extention as parameters and then would create a
> >> recordset having the path and filenames of all the files having the

> >extention
> >> in the directory and it's sub directories.
> >>
> >> Is that a feasable thing in Access 97?
> >>
> >> You can answer me here or at my e-mail address (E-Mail Removed).
> >> (please remove the NoSPAM in the address).
> >>
> >> Thank you
> >>
> >>

> >
> >

>

 
Reply With Quote
 
Albert D. Kallal
Guest
Posts: n/a
 
      5th Feb 2005
Sure, you can use the following code of mine....

Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub


Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

You can of course change the first dir command to only return *.dbf fields.

And, if you need to put the data into a reocrdset, you could go somthing
like:

dim rst as dao.recordset
.....
....
set rst = currentdb.OpenReocrdSet("tblDir")

For i = 1 To dlist.Count
rst.Add
rst!MyFileName = dlist(i)
rst.Update
Next i

Anyway, the above code shell should get you something to work with....

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(E-Mail Removed)
http://www.members.shaw.ca/AlbertKallal


 
Reply With Quote
 
=?Utf-8?B?TWlhcGxhY2lkdXM=?=
Guest
Posts: n/a
 
      15th Apr 2005
Thanks, that worked, but I would have never glommed it alone. I used that to
create a list of files in a DB. Then I went back and read the list and opened
each file to create a summary of what is in it and also to pick up all the
other file properties. I used Auto summary in word to create a short summary,
and that works OK. I'm still working on a method for other file types. I'd
like to, for example open a PPT file and step through the text boxes looking
for words that are used frequently (other than prepositions). I need a
similar method for other file types, like excel.

Anybody got suggestions, I'm listening.

"Albert D. Kallal" wrote:

> Sure, you can use the following code of mine....
>
> Sub dirTest()
>
> Dim dlist As New Collection
> Dim startDir As String
> Dim i As Integer
>
> startDir = "C:\access\"
> Call FillDir(startDir, dlist)
>
> MsgBox "there are " & dlist.Count & " in the dir"
>
> ' lets printout the stuff into debug window for a test
>
> For i = 1 To dlist.Count
> Debug.Print dlist(i)
> Next i
>
> End Sub
>
>
> Sub FillDir(startDir As String, dlist As Collection)
>
> ' build up a list of files, and then
> ' add add to this list, any additinal
> ' folders
>
> Dim strTemp As String
> Dim colFolders As New Collection
> Dim vFolderName As Variant
>
> strTemp = Dir(startDir)
>
> Do While strTemp <> ""
> dlist.Add startDir & strTemp
> strTemp = Dir
> Loop
>
> ' now build a list of additional folders
> strTemp = Dir(startDir & "*.", vbDirectory)
>
> Do While strTemp <> ""
> If (strTemp <> ".") And (strTemp <> "..") Then
> colFolders.Add strTemp
> End If
> strTemp = Dir
> Loop
>
> ' now process each folder (recursion)
> For Each vFolderName In colFolders
> Call FillDir(startDir & vFolderName & "\", dlist)
> Next vFolderName
>
> End Sub
>
> You can of course change the first dir command to only return *.dbf fields.
>
> And, if you need to put the data into a reocrdset, you could go somthing
> like:
>
> dim rst as dao.recordset
> .....
> ....
> set rst = currentdb.OpenReocrdSet("tblDir")
>
> For i = 1 To dlist.Count
> rst.Add
> rst!MyFileName = dlist(i)
> rst.Update
> Next i
>
> Anyway, the above code shell should get you something to work with....
>
> --
> Albert D. Kallal (Access MVP)
> Edmonton, Alberta Canada
> (E-Mail Removed)
> http://www.members.shaw.ca/AlbertKallal
>
>
>

 
Reply With Quote
 
=?Utf-8?B?Smlt?=
Guest
Posts: n/a
 
      16th Jun 2005
This code is awesome. It worked with no modification and solved my problem
with just a few add ons.

Thanks,

Jim Arnold
St Michaels MD
=======================
"Albert D. Kallal" wrote:

> Sure, you can use the following code of mine....
>
> Sub dirTest()
>
> Dim dlist As New Collection
> Dim startDir As String
> Dim i As Integer
>
> startDir = "C:\access\"
> Call FillDir(startDir, dlist)
>
> MsgBox "there are " & dlist.Count & " in the dir"
>
> ' lets printout the stuff into debug window for a test
>
> For i = 1 To dlist.Count
> Debug.Print dlist(i)
> Next i
>
> End Sub
>
>
> Sub FillDir(startDir As String, dlist As Collection)
>
> ' build up a list of files, and then
> ' add add to this list, any additinal
> ' folders
>
> Dim strTemp As String
> Dim colFolders As New Collection
> Dim vFolderName As Variant
>
> strTemp = Dir(startDir)
>
> Do While strTemp <> ""
> dlist.Add startDir & strTemp
> strTemp = Dir
> Loop
>
> ' now build a list of additional folders
> strTemp = Dir(startDir & "*.", vbDirectory)
>
> Do While strTemp <> ""
> If (strTemp <> ".") And (strTemp <> "..") Then
> colFolders.Add strTemp
> End If
> strTemp = Dir
> Loop
>
> ' now process each folder (recursion)
> For Each vFolderName In colFolders
> Call FillDir(startDir & vFolderName & "\", dlist)
> Next vFolderName
>
> End Sub
>
> You can of course change the first dir command to only return *.dbf fields.
>
> And, if you need to put the data into a reocrdset, you could go somthing
> like:
>
> dim rst as dao.recordset
> .....
> ....
> set rst = currentdb.OpenReocrdSet("tblDir")
>
> For i = 1 To dlist.Count
> rst.Add
> rst!MyFileName = dlist(i)
> rst.Update
> Next i
>
> Anyway, the above code shell should get you something to work with....
>
> --
> Albert D. Kallal (Access MVP)
> Edmonton, Alberta Canada
> (E-Mail Removed)
> http://www.members.shaw.ca/AlbertKallal
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help to copy files names in a column from one directory to another directory VBA Paul B Microsoft Excel Programming 4 10th Nov 2008 01:54 AM
Would like to write batch file to copy all TXT files in a given directory and all subdirectories to a single target directory. Rob Windows XP General 5 20th Aug 2007 02:42 PM
list files in a directory and save list to text file? Mike Henley Freeware 7 22nd Nov 2004 06:32 PM
list all css files in a directory and sub directory TJS Microsoft ASP .NET 1 23rd Jun 2004 11:49 AM
copying files, files either end up in target directory or root directory of disk Popcorn Microsoft Windows 2000 File System 0 16th Dec 2003 06:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:00 PM.