PC Review


Reply
Thread Tools Rate Thread

Import filenames with Shell DIR command

 
 
Alan Z. Scharf
Guest
Posts: n/a
 
      8th Nov 2003
I need to import filenames from a directory into an Access table.

How can I do this with the Shell command using DIR?

I've been using File System Object, but that is too slow getting 4,000 file
names over my netowrk.

Thanks.

Alan

___________________________
Alan Z. Scharf
GrapeVine Systems
New York City


 
Reply With Quote
 
 
 
 
Joe Fallon
Guest
Posts: n/a
 
      8th Nov 2003
How to Add Directory File Names to an Access Table:

Create a table named tblDirectory with 2 fields:
FileName (Text 250)
FileDate (Date/Time)

Call the code below by pressing Ctrl-G to open the debug window and type:
GetFiles("c:\windows\")

Paste this code into a regular module:

Sub GetFiles(strPath As String)
Dim rs As Recordset
Dim strFile As String, strDate As Date

'clear out existing data
CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError

'open a recordset
Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)

'get the first filename
strFile = Dir(strPath, vbNormal)
'Loop through the balance of files
Do
'check to see if you have a filename
If strFile = "" Then
GoTo ExitHere
End If
strDate = FileDateTime(strPath & strFile)
rs.AddNew
'to save the full path using strPath & strFile
'save only the filename
rs!FileName = strFile
rs!FileDate = strDate
rs.Update

'try for next filename
strFile = Dir()
Loop

ExitHere:
Set rs = Nothing
MsgBox ("Directory list is complete.")
End Sub

--
Joe Fallon
Access MVP



"Alan Z. Scharf" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I need to import filenames from a directory into an Access table.
>
> How can I do this with the Shell command using DIR?
>
> I've been using File System Object, but that is too slow getting 4,000

file
> names over my netowrk.
>
> Thanks.
>
> Alan
>
> ___________________________
> Alan Z. Scharf
> GrapeVine Systems
> New York City
>
>



 
Reply With Quote
 
TC
Guest
Posts: n/a
 
      9th Nov 2003
Those CurrentDB references should really be cached :-)

TC


"Joe Fallon" <(E-Mail Removed)> wrote in message
news:#Idfn#(E-Mail Removed)...
> How to Add Directory File Names to an Access Table:
>
> Create a table named tblDirectory with 2 fields:
> FileName (Text 250)
> FileDate (Date/Time)
>
> Call the code below by pressing Ctrl-G to open the debug window and type:
> GetFiles("c:\windows\")
>
> Paste this code into a regular module:
>
> Sub GetFiles(strPath As String)
> Dim rs As Recordset
> Dim strFile As String, strDate As Date
>
> 'clear out existing data
> CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError
>
> 'open a recordset
> Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)
>
> 'get the first filename
> strFile = Dir(strPath, vbNormal)
> 'Loop through the balance of files
> Do
> 'check to see if you have a filename
> If strFile = "" Then
> GoTo ExitHere
> End If
> strDate = FileDateTime(strPath & strFile)
> rs.AddNew
> 'to save the full path using strPath & strFile
> 'save only the filename
> rs!FileName = strFile
> rs!FileDate = strDate
> rs.Update
>
> 'try for next filename
> strFile = Dir()
> Loop
>
> ExitHere:
> Set rs = Nothing
> MsgBox ("Directory list is complete.")
> End Sub
>
> --
> Joe Fallon
> Access MVP
>
>
>
> "Alan Z. Scharf" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > I need to import filenames from a directory into an Access table.
> >
> > How can I do this with the Shell command using DIR?
> >
> > I've been using File System Object, but that is too slow getting 4,000

> file
> > names over my netowrk.
> >
> > Thanks.
> >
> > Alan
> >
> > ___________________________
> > Alan Z. Scharf
> > GrapeVine Systems
> > New York City
> >
> >

>
>



 
Reply With Quote
 
Alan Z. Scharf
Guest
Posts: n/a
 
      9th Nov 2003
Joe,

Thanks very much.

It works beutifully. Now I will test it pulling filenames over my network.

Regards,

Alan

"Joe Fallon" <(E-Mail Removed)> wrote in message
news:#Idfn#(E-Mail Removed)...
> How to Add Directory File Names to an Access Table:
>
> Create a table named tblDirectory with 2 fields:
> FileName (Text 250)
> FileDate (Date/Time)
>
> Call the code below by pressing Ctrl-G to open the debug window and type:
> GetFiles("c:\windows\")
>
> Paste this code into a regular module:
>
> Sub GetFiles(strPath As String)
> Dim rs As Recordset
> Dim strFile As String, strDate As Date
>
> 'clear out existing data
> CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError
>
> 'open a recordset
> Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)
>
> 'get the first filename
> strFile = Dir(strPath, vbNormal)
> 'Loop through the balance of files
> Do
> 'check to see if you have a filename
> If strFile = "" Then
> GoTo ExitHere
> End If
> strDate = FileDateTime(strPath & strFile)
> rs.AddNew
> 'to save the full path using strPath & strFile
> 'save only the filename
> rs!FileName = strFile
> rs!FileDate = strDate
> rs.Update
>
> 'try for next filename
> strFile = Dir()
> Loop
>
> ExitHere:
> Set rs = Nothing
> MsgBox ("Directory list is complete.")
> End Sub
>
> --
> Joe Fallon
> Access MVP
>
>
>
> "Alan Z. Scharf" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > I need to import filenames from a directory into an Access table.
> >
> > How can I do this with the Shell command using DIR?
> >
> > I've been using File System Object, but that is too slow getting 4,000

> file
> > names over my netowrk.
> >
> > Thanks.
> >
> > Alan
> >
> > ___________________________
> > Alan Z. Scharf
> > GrapeVine Systems
> > New York City
> >
> >

>
>



 
Reply With Quote
 
Alan Z. Scharf
Guest
Posts: n/a
 
      11th Nov 2003
Joe,

The looping method of getteing 4,000 filenames over my client's network is
still too slow, takes about ten minutes.

Do you know a way using shell and DIR to get the long filenames into an
Access table? That way I only have to get the test result of the DIR over
the network.

I can handle the parsing of the resultant DIR format into usable data. I
just need at least to get the results into an Access table.

Thanks.

Alan

> ___________________________
> Alan Z. Scharf
> GrapeVine Systems
> New York City
>
>



 
Reply With Quote
 
Alan Z. Scharf
Guest
Posts: n/a
 
      11th Nov 2003
Joe,

Please forget my request about shelling to DIR.

I finally figured it out, making a text file from DIR /b to get just
filenames and then importing to table.

Thanks again for your help!

Regards,

Alan.


 
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
shell(3).dll <, and similar filenames da_test Windows XP General 1 27th Jan 2005 12:40 PM
Shortened filenames in shell\...\command subkey Michael A. Covington Microsoft Windows 2000 Registry 2 29th Jan 2004 09:22 AM
Shortened filenames in shell\...\command subkey Michael A. Covington Microsoft Windows 2000 Registry Archive 4 29th Jan 2004 09:22 AM
Shortened filenames in shell\...\command subkey Michael A. Covington Microsoft Windows 2000 Registry Archive 0 27th Jan 2004 11:26 PM
Import Filenames with Shell DIR command Alan Z. Scharf Microsoft Access External Data 1 8th Nov 2003 10:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:15 PM.