DOS Function in a Macro?

  • Thread starter Thread starter Joe Schmo
  • Start date Start date
J

Joe Schmo

Can I create an Access macro that runs a DOS command. The command is "DIR
/B >filelist.txt"

Or better yet is there a way to bring up a dialog box and select the
directory I want to run that DOS command on?


Thanks in advance
 
Perhaps there is a better solution to my dilema. I'd like to have a
function that queries the contents of a selected folder and writes that data
to a table. For example:
c:\files\file1.txt
c:\files\file2.txt
c:\files\file3.txt
c:\files\file4.tif
c:\files\file5.jpg

This gives me the ability to inventory data that I receive. This way I can
compare actual files received against files they think I've received. I've
been doing this with the DIR command by writing that data to a file and
importing it into Access. I'd like to more automate the process.

Thanks again,
 
If you've got a table named Files, with a single text field FileName, you
can do something like:

Dim strFolder As String
Dim strFile As String
Dim strSQL As String

strFolder = "C:\Some Folder\Some Other Folder\"
strFile = Dir(strFolder & "*.*")
Do Until Len(strFile) = 0
strSQL = "INSERT INTO Files (FileName) " & _
"VALUES('" & strFolder & strFile & "')"
CurrentDb.Execute strSQL, dbFailOnError
strFile = Dir()
Loop

For more complex situations (such as where you have subfolders that you need
to inspect), see http://my.advisor.com/articles.nsf/aid/16279
 
Dim strFileName As String
Const conPath As String = "C:\files\"

strFileName = Dir(conPath)
Do While Len(strFileName) > 0
"Here is where you add the file name to your table"
"strFileName will contain only the file name"
"To include path and file name use conPath & strFileName"
Dir()
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top