View Full Version : Viewing contents of a single folder


Anthony George
12-10-2006, 05:10 AM
Hi Everyone

Wonder if anyone can help with this one:-

All I am trying to do is bring up one folder in access, so that I can view it's contents.

The folder is called old_Files

I just want to click on a text box event, and have the folders contents appear in the box.

That,s it (I dont need to click on the files or anything like that, just view the contents)

Thank's for any help offered.

Kindest regards and a merry Christmas.

Tony

lagbolt
12-10-2006, 01:57 PM
In a VBA code window goto Menu->Tools->References and set a reference to either "Microsoft Scripting Runtime" or "Windows Script Host Object Model". Check out the variety of methods available if you create a FileSystemObject. Use the GetFolder method to return a folder object, and enumerate its Files collection.

Kenln
12-11-2006, 08:01 AM
This is in the MS Knowledge Base.

It show how to look for a specific file or list a directory.



Sub Dir_View_Test_1()

Dim MyFile, MyPath, MyName
' Returns "WIN.INI" (on Microsoft Windows) if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")

' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")

' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir

' Return first *.TXT file with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)

' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop

End Sub

Anthony George
12-11-2006, 11:17 AM
Thanks

Lagbolt and Kenin for your help.

I will give these ideas a try.

Kindest Regards

Tony

Anthony George
12-15-2006, 02:01 PM
I've had a play with this and I can't make it work.

Does anyone know how I can get it to output to a text box on a form.

What i am trying to do is to update files in various folders on my hard drive.

I can do the updates ok that's not my problem.

What I'm trying to do is have a look at the contents of 16 folders after i've done the updates to make sure they are all ok.

What I would love to do is have 16 small text boxes on a form showing a snapshot of 16 folders on my hard drive after ive updated the files.

please help

Your's Fairly desperate

Tony

lagbolt
12-16-2006, 02:58 PM
By "folder contents", or "snapshot of 16 folders" do you mean a list of the filenames in that folder? Is this enough info for you to know your update has succeeded?

Private Function GetFileNames(folderSpec As String) As String
' Returns a list of filenames and filesizes that are present in folderSpec
' Requires that "Microsoft Scripting Runtime" be referenced by the application
Dim fso As New Scripting.FileSystemObject
Dim fd As Scripting.Folder
Dim f As Scripting.File
Dim fns As String

'get a folder object
Set fd = fso.GetFolder(folderSpec)
'traverse the files collection of the folder
For Each f In fd.files
'return information about the file and assign to string
fns = fns & f.Name & " " & Format(f.Size / 1024, "#,##0 KB") & vbCrLf
Next f
'assign to function
GetFileNames = fns

End Function


Assign the result of this function to a text box using something like...
Me.tbFiles = GetFileNames("C:\")

Anthony George
12-17-2006, 12:26 AM
Thank's Lagbolt

I really appreciate that information.

It works really well.

I am a teacher of general Information Technology subjects and every week I have the task of setting up 16 folders on the server with the appropriate files for each individual students exam.

I had already worked out how to archive the old folders, delete the used files, and move fresh fies into the folders, but I just wanted to have a look at the new folder contents just to be sure that everything went according to plan.

Have a great Christmas

Kindest regards

Tony

Bat17
12-17-2006, 04:40 AM
stick the names of the files in a table and you could code it to check they are all correct!

Peter