hwo to create a list of files name

S

Silvio

Is there a way in access to dynamically create a list of files names located
in a specific directory?

Thank you,
Silvio
 
K

KARL DEWEY

This is neither dynamic nor in access but it will create you the list as a
text file --

You can use a DOS command (I guess most folks have forgoten DOS) to create a
..txt file.

Click on START, Run... enter CMD and click OK. This gets you to a DOS
window. The drive and folder names will be displayed on the prompt line.

You can either go to the folder or use the drive and path in the DOS command.

To go to folder enter drive letter followed by colon and press ENTER. The
prompt line will change to reflect the drive like this -- H:\> -- for 'H'
drive. Then use CD followed by next folder name in the path. Prompt line
will reflect like this -- H:\My Documents> -- and continue to desired
folder.
NOTE - CD.. backs up one folder level.
- CD\ takes you to root drive.
- HELP DIR list the switches used with the Directory command.
Switches include controlling how much information is included in the file
list and contains contents of subdirectories.

To create file use this command line --
DIR>MyFileList.txt
OR
DIR>c:\My Documents\MyFileList.txt
The first creates the file on same drive, the second includes path.
 
F

fredg

Is there a way in access to dynamically create a list of files names located
in a specific directory?

Thank you,
Silvio

The following will fill a List Box row source with the names of all
files in a specific folder. Place it in an event on a form to fill a
list box on that form. Change MyFolderName and ListBoxName to whatever
the actual names are.

Public Sub FillListBox()
On Error GoTo Err_Handler
Dim Db As DAO.Database
Set Db = CurrentDb
Dim intX As Integer
Dim MyPath As String, MyName As String
MyPath = "C:\MyFolderName\"
MyName = Dir(MyPath, vbNormal)
Do While MyName <> ""
intX = 1
If InStr(MyName, ".") > 0 Then
Me!ListBoxName.RowSource = Me!ListBoxName.RowSource _
& MyName & ","
End If
MyName = Dir
Loop

If intX = 0 And MyName = "" Then
MsgBox "Nothing found"
Exit Sub
End If

ListBoxName.RowSource = Left(ListBoxName.RowSource, _
Len(ListBoxName.RowSource) - 1)

Exit_Sub:
Exit Sub
Err_Handler:
MsgBox "error # " & Err.Number & " " & Err.Description
Resume Exit_Sub

End Sub
 
S

Silvio

Folks I got it. Thank you very much!

To take this one step further, I have my list up and running showing each
file path. I created a simple event (on click) that will show me a preview
of the picture on that same form for the file selected .Of course, not all
the files are picture, so here are 2 questions:

1. How can I evaluate if the file selected is a jpg
I have tried this but it does not work:

Private Sub lstFileList_Click()
If Me.lstFileList = "*.jpg" Then
Me.ImagePrev.Picture = Me.lstFileList
End If
End Sub

2. For each files I would like the user to be able to double click on the
list and open that file with the appropriate software (e.g. *.doc open with
ms word and so on)

I have tried this but it does not work:

Private Sub lstFileList_DblClick(Cancel As Integer)
Dim oApp As Object
oApp.Open FileName:=Me.lstFileList
End Sub

Once again thank you for help.
 

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

Top